Update to acorn 7, bump ecmaVersion to 11, deprecate the dynamicImport option

acorn, with ecmaVersion set to 11, now support dynamic imports, so we
can drop the acorn-dynamic-import dependency, and just enable parsing
import()s unconditionally.
This commit is contained in:
Ran Benita
2019-09-03 22:35:05 +03:00
parent 9f109d92fc
commit 554ffce7b7
8 changed files with 18 additions and 28 deletions
+2 -3
View File
@@ -10,6 +10,7 @@ This fork contains the following changes:
- Renamed package and binary from `ng-annotate` to `ng-annotate-patched`.
- Updated the [acorn](https://github.com/ternjs/acorn) JavaScript parser.
ECMAScript 2020 mode is used by default.
- Enabled some acorn options that allow it to parse a wider range of
JavaScript.
@@ -30,9 +31,7 @@ This fork contains the following changes:
- Added support for parsing dynamic `import()` syntax. If you use Webpack
or a similar module loader you would probably like to compile to
`esnext` modules for dynamic import support. To do that you will need to
pass the `dynamicImport` flag which will switch from the default acorn
package, to the upgraded `acorn-dynamic-import`.
`esnext` modules for dynamic import support.
- Published to npm under the name `ng-annotate-patched`.
+6 -11
View File
@@ -5,19 +5,14 @@
"requires": true,
"dependencies": {
"acorn": {
"version": "6.0.5",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-6.0.5.tgz",
"integrity": "sha512-i33Zgp3XWtmZBMNvCr4azvOFeWVw1Rk6p3hfi3LUDvIFraOMywb1kAtrbi+med14m4Xfpqm3zRZMT+c0FNE7kg=="
},
"acorn-dynamic-import": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/acorn-dynamic-import/-/acorn-dynamic-import-4.0.0.tgz",
"integrity": "sha512-d3OEjQV4ROpoflsnUA8HozoIR504TFxNivYEUi6uwz0IYhBkTDXGuWlNdMtybRt3nqVx/L6XqMt0FxkXuWKZhw=="
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-7.0.0.tgz",
"integrity": "sha512-PaF/MduxijYYt7unVGRuds1vBC9bFxbNf+VWqhOClfdgy7RlVkQqt610ig1/yxTgsDIfW1cWDel5EBbOy3jdtQ=="
},
"acorn-walk": {
"version": "6.1.1",
"resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-6.1.1.tgz",
"integrity": "sha512-OtUw6JUTgxA2QoqqmrmQ7F2NYqiBPi/L2jqHyFtllhOUvXYQXf0Z1CYUinIfyT4bTCGmrA7gX9FvHA81uzCoVw=="
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-7.0.0.tgz",
"integrity": "sha512-7Bv1We7ZGuU79zZbb6rRqcpxo3OY+zrdtloZWoyD8fmGX+FeXRjE+iuGkZjSXLVovLzrsvMGMy0EkwA0E0umxg=="
},
"coffee-script": {
"version": "1.12.7",
+2 -3
View File
@@ -8,9 +8,8 @@
"url": "https://github.com/bluetech/ng-annotate-patched.git"
},
"dependencies": {
"acorn": "^6.0.5",
"acorn-dynamic-import": "^4.0.0",
"acorn-walk": "^6.1.1",
"acorn": "^7.0.0",
"acorn-walk": "^7.0.0",
"convert-source-map": "^1.1.2",
"optimist": "^0.6.1",
"source-map": "^0.6.1"
+3 -4
View File
@@ -1196,19 +1196,18 @@ module.exports = function ngAnnotate(src, options) {
try {
const acorn = require("acorn");
const parser = options.dynamicImport ? acorn.Parser.extend(require("acorn-dynamic-import").default) : acorn.Parser;
stats.parser_require_t0 = require_acorn_t0;
stats.parser_require_t1 = require_acorn_t1;
stats.parser_parse_t0 = Date.now();
// acorn
ast = parser.parse(src, Object.assign({
ecmaVersion: 8,
ast = acorn.Parser.parse(src, Object.assign({
ecmaVersion: 11,
allowImportExportEverywhere: true,
allowReturnOutsideFunction: true,
locations: true,
ranges: true,
onComment: comments,
plugins: options.dynamicImport ? { dynamicImport: true } : {}, // just having the key triggers plugin regardless of value
plugins: {}, // just having the key triggers plugin regardless of value
}, options.acornOptions));
stats.parser_parse_t1 = Date.now();
} catch(e) {
+1 -3
View File
@@ -1,11 +1,9 @@
// traverse.js
// MIT licensed, see LICENSE file
const defaultWalk = require("acorn-walk");
const dynamicImportWalk = require("acorn-dynamic-import/lib/walk").default(defaultWalk);
const walk = require("acorn-walk");
module.exports = function traverse(rootNode, options, pluginOptions = {}) {
const walk = pluginOptions.dynamicImport ? dynamicImportWalk : defaultWalk;
const ancestors = [];
(function c(node, st, override) {
const parent = ancestors[ancestors.length - 1];
+2
View File
@@ -1057,3 +1057,5 @@ export var exportVariableFunctionVar3 = function($scope) {
};
};
})();
import('dynamic-import-is-allowed.js').then(module => {});
-4
View File
@@ -128,10 +128,6 @@ function run(ngAnnotate) {
const arrowFunctionsAnnotated = ngAnnotate(arrowFunctions, {add: true}).src;
test(slurp("tests/arrow-functions.annotated.js"), arrowFunctionsAnnotated, "arrow-functions.annotated.js");
console.log("testing adding annotations with dynamicImport enabled");
const annotatedWithDynamicImportEnabled = ngAnnotate(original, {add: true, dynamicImport: true}).src;
test(slurp("tests/with_annotations.js"), annotatedWithDynamicImportEnabled, "with_annotations.js");
const rename = slurp("tests/rename.js");
console.log("testing adding annotations and renaming");
+2
View File
@@ -1106,3 +1106,5 @@ exportVariableFunctionVar3.$inject = ["$scope"];
};
};
})();
import('dynamic-import-is-allowed.js').then(module => {});