Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
}
});
nodes.forEach(node => {
node._compact = true;
});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);
return babel.transformFromAst(tree, null, {
filename: helperFilename,
presets: [
[
"@babel/preset-env",
{ modules: false, exclude: ["@babel/plugin-transform-typeof-symbol"] },
],
],
plugins: [helpers.list.forEach(function(name) {
if (whitelist && whitelist.indexOf(name) < 0) return;
const ref = (refs[name] = getHelperReference(name));
const { nodes } = helpers.get(name, getHelperReference, ref);
body.push(...nodes);
});
return refs;