Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const generator = this.get("helperGenerator");
if (generator) {
const res = generator(name);
if (res) return res;
}
// make sure that the helper exists
helpers.ensure(name);
const uid = (this.declarations[name] = this.scope.generateUidIdentifier(
name,
));
const dependencies = {};
for (const dep of helpers.getDependencies(name)) {
dependencies[dep] = this.addHelper(dep);
}
const { nodes, globals } = helpers.get(
name,
dep => dependencies[dep],
uid,
Object.keys(this.scope.getAllBindings()),
);
globals.forEach(name => {
if (this.path.scope.hasBinding(name, true /* noGlobals */)) {
this.path.scope.rename(name);
}
});
function buildHelper(
runtimeName,
pkgDirname,
helperFilename,
helperName,
{ esm, corejs }
) {
const tree = t.program([], [], esm ? "module" : "script");
const dependencies = {};
let bindings = null;
if (!esm) {
bindings = [];
for (const dep of helpers.getDependencies(helperName)) {
const id = (dependencies[dep] = t.identifier(t.toIdentifier(dep)));
tree.body.push(template.statement.ast`
var ${id} = require("${`./${dep}`}");
`);
bindings.push(id.name);
}
}
const helper = helpers.get(
helperName,
dep => dependencies[dep],
esm ? null : template.expression.ast`module.exports`,
bindings
);
tree.body.push(...helper.nodes);