Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
helpers.list.forEach(function (name) {
if (whitelist && whitelist.indexOf(name) < 0) return;
const key = t.identifier(name);
// AST tree for: objectMember.helperName = function () { ... }
body.push(t.expressionStatement(t.assignmentExpression("=", t.memberExpression(t.identifier('babelHelpers'), key), helpers.get(name))));
});
}
if (declar) return declar;
const generator = this.get("helperGenerator");
const runtime = this.get("helpersNamespace");
if (generator) {
const res = generator(name);
if (res) return res;
} else if (runtime) {
return t.memberExpression(runtime, t.identifier(name));
}
const uid = (this.declarations[name] = this.scope.generateUidIdentifier(
name,
));
const { nodes, globals } = getHelper(
name,
name => this.addHelper(name),
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;
});
function buildHelpers(body, whitelist) {
helpers.list.forEach(function (name) {
if (whitelist && whitelist.indexOf(name) < 0) return;
const key = t.identifier(name);
// AST tree for: objectMember.helperName = function () { ... }
body.push(t.expressionStatement(t.assignmentExpression("=", t.memberExpression(t.identifier('babelHelpers'), key), helpers.get(name))));
});
}
// Regenerator is a special dependency that we want to include
var fs = require('fs');
var babel = require('babel');
var helpers = require('babel-helpers');
var t = babel.types;
// ES Module helpers based on https://github.com/babel/babel/blob/master/packages/babel-runtime/scripts/build-dist.js
helpers.list.forEach(function(helperName) {
var tree = t.program([
t.exportDefaultDeclaration(helpers.get(helperName))
]);
fs.writeFileSync('../babel-helpers/' + helperName + '.js', babel.transformFromAst(tree).code);
});
}),
babel({
babelrc: false,
presets: [
[
'es2015',
{
modules: false,
},
],
],
plugins: [
'external-helpers',
],
// fixing temporary rollup's regression, remove when rollup/rollup#1595 gets solved
externalHelpersWhitelist: babelHelpersList.filter(helperName => helperName !== 'asyncGenerator'),
}),
visualizer(),
],
external: [
'combine-arrays',
'eventemitter3',
'hash-brown-router',
'iso-next-tick',
'page-path-builder',
'path-to-regexp-with-reversible-keys',
'then-denodeify',
],
}
getUsedMethods({exclude}={}){
if (!Array.isArray(exclude)) {
exclude = [];
}
let ret = [];
for (let name of this.usedHelpers) {
if (exclude.indexOf(name) == -1) {
let METHOD = this._definedHelpers[name] || babelHelpers.get(name);
ret.push(helperDefineTemplate({
METHOD_NAME: Identifier(name),
METHOD
}))
}
}
return ret;
}
helpers.list.forEach(function(helperName) {
var tree = t.program([
t.exportDefaultDeclaration(helpers.get(helperName))
]);
fs.writeFileSync('../babel-helpers/' + helperName + '.js', babel.transformFromAst(tree).code);
});
each(helpers.list, function (name) {
if (whitelist && whitelist.indexOf(name) < 0) return;
let key = t.identifier(name);
body.push(t.expressionStatement(
t.assignmentExpression("=", t.memberExpression(namespace, key), helpers.get(name))
));
});
}
list.forEach( function(fn){
if (whitelist && whitelist.indexOf(fn) < 0) return;
callback(fn, bh.get(fn));
});
}
function buildGlobal(namespace, builder) {
let body = [];
let container = t.functionExpression(null, [t.identifier("global")], t.blockStatement(body));
let tree = t.program([t.expressionStatement(t.callExpression(container, [helpers.get("selfGlobal")]))]);
body.push(t.variableDeclaration("var", [
t.variableDeclarator(
namespace,
t.assignmentExpression("=", t.memberExpression(t.identifier("global"), namespace), t.objectExpression([]))
)
]));
builder(body);
return tree;
}