allow imports and exports everywhere in loose mode

This commit is contained in:
Sebastian McKenzie 2015-01-14 15:21:45 +11:00
parent f33cd7184f
commit 0cbcbc60de
3 changed files with 14 additions and 10 deletions

View File

@ -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).

View File

@ -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();
});

View File

@ -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);