babel/lib/6to5/transformation/transformers/optional-external-runtime.js
Aluísio Augusto Silva Gonçalves e8237910e8 Add a transformer to import the runtime from a file
The `externalRuntime` optional transformer can be used in conjunction
with the `runtime` option to import and use the runtime from a module
instead of polluting the global environment.
2015-01-18 17:31:52 -02:00

12 lines
413 B
JavaScript

exports.optional = true;
// In theory, it would be more appropriate to do this in `manipulateOptions`,
// but we need an identifier for the import and we can't get that before the
// AST is built.
exports.ast = {
enter: function (ast, file) {
file.opts.runtime = file.addImport(file.opts.runtime, "to5Runtime").name;
file.dynamicImports[file.dynamicImports.length - 1]._noInteropRequire = true;
}
};