diff --git a/CHANGELOG.md b/CHANGELOG.md index bf8d42c37b..7a099a9b89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ _Note: Gaps between patch versions are faulty/broken releases._ ## 3.0.0 * **Breaking Change** - * `allowImportExportEverywhere` acorn option has been disabled for spec compliancy so imports and exports can **only** be present at the top level. + * Imports and exports are now illegal anywhere except the root level by default. Set `modules` to [loose mode](http://6to5.org/docs/usage/loose) to allow them everywhere. * Caching is now always enabled for the require hook. It also now no longer caches require resolutions. * `ignoreRegex` fallback has now been dropped from the require hook. `register(/foo/);`, `register({ ignoreRegex: /foo/ })` -> `register({ ignore: /foo/ })`. * Optional fast transformer backwards compatibility support has been removed. Use [loose mode](https://6to5.org/docs/usage/loose). diff --git a/lib/6to5/file.js b/lib/6to5/file.js index 5d561ac1a0..2bc26ee611 100644 --- a/lib/6to5/file.js +++ b/lib/6to5/file.js @@ -244,7 +244,10 @@ File.prototype.parse = function (code) { code = this.addCode(code); - return util.parse(this.opts, code, function (tree) { + var opts = this.opts; + opts.looseModules = this.isLoose("modules"); + + return util.parse(opts, code, function (tree) { self.transform(tree); return self.generate(); }); diff --git a/lib/6to5/util.js b/lib/6to5/util.js index 11301f16b4..27a790141c 100644 --- a/lib/6to5/util.js +++ b/lib/6to5/util.js @@ -218,14 +218,15 @@ exports.parse = function (opts, code, callback) { var tokens = []; var ast = acorn.parse(code, { - allowReturnOutsideFunction: true, - ecmaVersion: opts.experimental ? 7 : 6, - playground: opts.playground, - strictMode: true, - onComment: comments, - locations: true, - onToken: tokens, - ranges: true + allowImportExportEverywhere: opts.looseModules, + allowReturnOutsideFunction: true, + ecmaVersion: opts.experimental ? 7 : 6, + playground: opts.playground, + strictMode: true, + onComment: comments, + locations: true, + onToken: tokens, + ranges: true }); estraverse.attachComments(ast, comments, tokens);