mirror of
https://github.com/bluetech/ng-annotate-patched.git
synced 2026-07-02 00:17:42 +08:00
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:
@@ -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`.
|
||||
|
||||
|
||||
Generated
+6
-11
@@ -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
@@ -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"
|
||||
|
||||
@@ -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
@@ -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];
|
||||
|
||||
@@ -1057,3 +1057,5 @@ export var exportVariableFunctionVar3 = function($scope) {
|
||||
};
|
||||
};
|
||||
})();
|
||||
|
||||
import('dynamic-import-is-allowed.js').then(module => {});
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -1106,3 +1106,5 @@ exportVariableFunctionVar3.$inject = ["$scope"];
|
||||
};
|
||||
};
|
||||
})();
|
||||
|
||||
import('dynamic-import-is-allowed.js').then(module => {});
|
||||
|
||||
Reference in New Issue
Block a user