This plugin has option to whitelist helpers, but what if it could detect which helpers are automatically injected and create whitelist from that?
I’ve made PoC based on Webpack 3 version of the plugin.
module.exports = function (compiler, pluginOptions) {
compiler.plugin('compilation', function (compilation, params) {
const injectedBabelHelpers = [];
params.normalModuleFactory.plugin('parser', (parser) => {
parser.plugin('call babelHelpers.*', ( expr ) => {
injectedBabelHelpers.push(expr.callee.property.name);
});
});
inject(compilation, pluginOptions, injectedBabelHelpers);
});
};
function inject(compilation, pluginOptions, injectedBabelHelpers) {
compilation.dependencyFactories.set(SingleEntryDependencyWrapper, new NullFactory());
compilation.plugin('seal', function () {
// Babel helpers whitelist is available here
getChunks(this, pluginOptions.entries).forEach(chunk => injectHelpers(this, chunk.module, pluginOptions.whitelist));
});
}
// …
It uses Webpack parser to get all babelHelpers expressions from AST and stores methods used in array. That array is then passed down to inject method, at first it’s empty, but in seal phase it’s filled with all the helpers inside compiled module. It may seem like a hack, but as I said, this is PoC and it could possibliy be made better. Final array can then be filtered for duplicates and used instead of pluginOptions.whitelist.
This should of course be another plugin option and it should be opt-in.
What do you think? Am I missing something here?
This plugin has option to whitelist helpers, but what if it could detect which helpers are automatically injected and create whitelist from that?
I’ve made PoC based on Webpack 3 version of the plugin.
It uses Webpack parser to get all
babelHelpersexpressions from AST and stores methods used in array. That array is then passed down toinjectmethod, at first it’s empty, but insealphase it’s filled with all the helpers inside compiled module. It may seem like a hack, but as I said, this is PoC and it could possibliy be made better. Final array can then be filtered for duplicates and used instead ofpluginOptions.whitelist.This should of course be another plugin option and it should be opt-in.
What do you think? Am I missing something here?