Use acorn@5

This commit is contained in:
Florent Cailhol 2018-01-06 17:44:20 +01:00
parent 114abeeb4d
commit 5a1ffb53dc
3 changed files with 28 additions and 27 deletions

View File

@ -988,20 +988,16 @@ class Parser extends Tapable {
this.hooks.export.call(statement); this.hooks.export.call(statement);
} }
if(statement.declaration) { if(statement.declaration) {
if(/Expression$/.test(statement.declaration.type)) { if(!this.hooks.exportDeclaration.call(statement, statement.declaration)) {
throw new Error("Doesn't occur?"); const originalDefinitions = this.scope.definitions;
} else { const tracker = new TrackingSet(this.scope.definitions);
if(!this.hooks.exportDeclaration.call(statement, statement.declaration)) { this.scope.definitions = tracker;
const originalDefinitions = this.scope.definitions; this.prewalkStatement(statement.declaration);
const tracker = new TrackingSet(this.scope.definitions); const newDefs = Array.from(tracker.getAddedItems());
this.scope.definitions = tracker; this.scope.definitions = originalDefinitions;
this.prewalkStatement(statement.declaration); for(let index = newDefs.length - 1; index >= 0; index--) {
const newDefs = Array.from(tracker.getAddedItems()); const def = newDefs[index];
this.scope.definitions = originalDefinitions; this.hooks.exportSpecifier.call(statement, def, def, index);
for(let index = newDefs.length - 1; index >= 0; index--) {
const def = newDefs[index];
this.hooks.exportSpecifier.call(statement, def, def, index);
}
} }
} }
} }
@ -1030,7 +1026,7 @@ class Parser extends Tapable {
} }
prewalkExportDefaultDeclaration(statement) { prewalkExportDefaultDeclaration(statement) {
if(/Declaration$/.test(statement.declaration.type)) { if(statement.declaration.id) {
const originalDefinitions = this.scope.definitions; const originalDefinitions = this.scope.definitions;
const tracker = new TrackingSet(this.scope.definitions); const tracker = new TrackingSet(this.scope.definitions);
this.scope.definitions = tracker; this.scope.definitions = tracker;
@ -1046,12 +1042,21 @@ class Parser extends Tapable {
walkExportDefaultDeclaration(statement) { walkExportDefaultDeclaration(statement) {
this.hooks.export.call(statement); this.hooks.export.call(statement);
if(/Declaration$/.test(statement.declaration.type)) { if(statement.declaration.id) {
if(!this.hooks.exportDeclaration.call(statement, statement.declaration)) { if(!this.hooks.exportDeclaration.call(statement, statement.declaration)) {
this.walkStatement(statement.declaration); this.walkStatement(statement.declaration);
} }
} else { } else {
this.walkExpression(statement.declaration); // Acorn parses `export default function() {}` as `FunctionDeclaration` and
// `export default class {}` as `ClassDeclaration`, both with `id = null`.
// These nodes must be treated as expressions.
if(statement.declaration.type === "FunctionDeclaration") {
this.walkFunctionDeclaration(statement.declaration);
} else if(statement.declaration.type === "ClassDeclaration") {
this.walkClassDeclaration(statement.declaration);
} else {
this.walkExpression(statement.declaration);
}
if(!this.hooks.exportExpression.call(statement, statement.declaration)) { if(!this.hooks.exportExpression.call(statement, statement.declaration)) {
this.hooks.exportSpecifier.call(statement, statement.declaration, "default"); this.hooks.exportSpecifier.call(statement, statement.declaration, "default");
} }

View File

@ -3,9 +3,10 @@
"version": "4.0.0-alpha.4", "version": "4.0.0-alpha.4",
"author": "Tobias Koppers @sokra", "author": "Tobias Koppers @sokra",
"description": "Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.", "description": "Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.",
"license": "MIT",
"dependencies": { "dependencies": {
"acorn": "^5.0.0", "acorn": "^5.0.0",
"acorn-dynamic-import": "^2.0.0", "acorn-dynamic-import": "^3.0.0",
"ajv": "^5.1.5", "ajv": "^5.1.5",
"ajv-keywords": "^2.0.0", "ajv-keywords": "^2.0.0",
"async": "^2.1.2", "async": "^2.1.2",
@ -22,7 +23,6 @@
"watchpack": "^1.4.0", "watchpack": "^1.4.0",
"webpack-sources": "^1.0.1" "webpack-sources": "^1.0.1"
}, },
"license": "MIT",
"devDependencies": { "devDependencies": {
"beautify-lint": "^1.0.3", "beautify-lint": "^1.0.3",
"benchmark": "^2.1.1", "benchmark": "^2.1.1",

View File

@ -17,11 +17,11 @@ accepts@~1.2.12:
mime-types "~2.1.6" mime-types "~2.1.6"
negotiator "0.5.3" negotiator "0.5.3"
acorn-dynamic-import@^2.0.0: acorn-dynamic-import@^3.0.0:
version "2.0.2" version "3.0.0"
resolved "https://registry.yarnpkg.com/acorn-dynamic-import/-/acorn-dynamic-import-2.0.2.tgz#c752bd210bef679501b6c6cb7fc84f8f47158cc4" resolved "https://registry.yarnpkg.com/acorn-dynamic-import/-/acorn-dynamic-import-3.0.0.tgz#901ceee4c7faaef7e07ad2a47e890675da50a278"
dependencies: dependencies:
acorn "^4.0.3" acorn "^5.0.0"
acorn-globals@^1.0.3: acorn-globals@^1.0.3:
version "1.0.9" version "1.0.9"
@ -47,10 +47,6 @@ acorn@^3.0.4:
version "3.3.0" version "3.3.0"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-3.3.0.tgz#45e37fb39e8da3f25baee3ff5369e2bb5f22017a" resolved "https://registry.yarnpkg.com/acorn/-/acorn-3.3.0.tgz#45e37fb39e8da3f25baee3ff5369e2bb5f22017a"
acorn@^4.0.3:
version "4.0.13"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-4.0.13.tgz#105495ae5361d697bd195c825192e1ad7f253787"
acorn@^5.0.0, acorn@^5.2.1: acorn@^5.0.0, acorn@^5.2.1:
version "5.3.0" version "5.3.0"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.3.0.tgz#7446d39459c54fb49a80e6ee6478149b940ec822" resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.3.0.tgz#7446d39459c54fb49a80e6ee6478149b940ec822"