diff --git a/src/babel/transformation/file.js b/src/babel/transformation/file.js index e4d0de2391..d7528b052a 100644 --- a/src/babel/transformation/file.js +++ b/src/babel/transformation/file.js @@ -339,7 +339,11 @@ export default class File { this.dynamicImported.push(declar); if (noDefault) this.dynamicImportedNoDefault.push(declar); - this.moduleFormatter.importSpecifier(specifiers[0], declar, this.dynamicImports); + if (this.transformers["es6.modules"].canRun()) { + this.moduleFormatter.importSpecifier(specifiers[0], declar, this.dynamicImports); + } else { + this.dynamicImports.push(declar); + } } return id; diff --git a/src/babel/transformation/transformers/internal/module-formatter.js b/src/babel/transformation/transformers/internal/module-formatter.js index a601ff4230..5d17476725 100644 --- a/src/babel/transformation/transformers/internal/module-formatter.js +++ b/src/babel/transformation/transformers/internal/module-formatter.js @@ -1,12 +1,12 @@ import * as strict from "../../helpers/strict"; export function Program(program, parent, scope, file) { - if (!file.transformers["es6.modules"].canRun()) return; - strict.wrap(program, function () { program.body = file.dynamicImports.concat(program.body); }); + if (!file.transformers["es6.modules"].canRun()) return; + if (file.moduleFormatter.transform) { file.moduleFormatter.transform(program); }