Skip to content

Commit 8b888fe

Browse files
authored
Merge pull request webpack#6254 from ooflorent/acorn5
Use acorn v5
2 parents 41edb20 + 5a1ffb5 commit 8b888fe

File tree

3 files changed

+28
-27
lines changed

3 files changed

+28
-27
lines changed

lib/Parser.js

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -988,20 +988,16 @@ class Parser extends Tapable {
988988
this.hooks.export.call(statement);
989989
}
990990
if(statement.declaration) {
991-
if(/Expression$/.test(statement.declaration.type)) {
992-
throw new Error("Doesn't occur?");
993-
} else {
994-
if(!this.hooks.exportDeclaration.call(statement, statement.declaration)) {
995-
const originalDefinitions = this.scope.definitions;
996-
const tracker = new TrackingSet(this.scope.definitions);
997-
this.scope.definitions = tracker;
998-
this.prewalkStatement(statement.declaration);
999-
const newDefs = Array.from(tracker.getAddedItems());
1000-
this.scope.definitions = originalDefinitions;
1001-
for(let index = newDefs.length - 1; index >= 0; index--) {
1002-
const def = newDefs[index];
1003-
this.hooks.exportSpecifier.call(statement, def, def, index);
1004-
}
991+
if(!this.hooks.exportDeclaration.call(statement, statement.declaration)) {
992+
const originalDefinitions = this.scope.definitions;
993+
const tracker = new TrackingSet(this.scope.definitions);
994+
this.scope.definitions = tracker;
995+
this.prewalkStatement(statement.declaration);
996+
const newDefs = Array.from(tracker.getAddedItems());
997+
this.scope.definitions = originalDefinitions;
998+
for(let index = newDefs.length - 1; index >= 0; index--) {
999+
const def = newDefs[index];
1000+
this.hooks.exportSpecifier.call(statement, def, def, index);
10051001
}
10061002
}
10071003
}
@@ -1030,7 +1026,7 @@ class Parser extends Tapable {
10301026
}
10311027

10321028
prewalkExportDefaultDeclaration(statement) {
1033-
if(/Declaration$/.test(statement.declaration.type)) {
1029+
if(statement.declaration.id) {
10341030
const originalDefinitions = this.scope.definitions;
10351031
const tracker = new TrackingSet(this.scope.definitions);
10361032
this.scope.definitions = tracker;
@@ -1046,12 +1042,21 @@ class Parser extends Tapable {
10461042

10471043
walkExportDefaultDeclaration(statement) {
10481044
this.hooks.export.call(statement);
1049-
if(/Declaration$/.test(statement.declaration.type)) {
1045+
if(statement.declaration.id) {
10501046
if(!this.hooks.exportDeclaration.call(statement, statement.declaration)) {
10511047
this.walkStatement(statement.declaration);
10521048
}
10531049
} else {
1054-
this.walkExpression(statement.declaration);
1050+
// Acorn parses `export default function() {}` as `FunctionDeclaration` and
1051+
// `export default class {}` as `ClassDeclaration`, both with `id = null`.
1052+
// These nodes must be treated as expressions.
1053+
if(statement.declaration.type === "FunctionDeclaration") {
1054+
this.walkFunctionDeclaration(statement.declaration);
1055+
} else if(statement.declaration.type === "ClassDeclaration") {
1056+
this.walkClassDeclaration(statement.declaration);
1057+
} else {
1058+
this.walkExpression(statement.declaration);
1059+
}
10551060
if(!this.hooks.exportExpression.call(statement, statement.declaration)) {
10561061
this.hooks.exportSpecifier.call(statement, statement.declaration, "default");
10571062
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
"version": "4.0.0-alpha.4",
44
"author": "Tobias Koppers @sokra",
55
"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.",
6+
"license": "MIT",
67
"dependencies": {
78
"acorn": "^5.0.0",
8-
"acorn-dynamic-import": "^2.0.0",
9+
"acorn-dynamic-import": "^3.0.0",
910
"ajv": "^5.1.5",
1011
"ajv-keywords": "^2.0.0",
1112
"async": "^2.1.2",
@@ -22,7 +23,6 @@
2223
"watchpack": "^1.4.0",
2324
"webpack-sources": "^1.0.1"
2425
},
25-
"license": "MIT",
2626
"devDependencies": {
2727
"beautify-lint": "^1.0.3",
2828
"benchmark": "^2.1.1",

yarn.lock

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ accepts@~1.2.12:
1717
mime-types "~2.1.6"
1818
negotiator "0.5.3"
1919

20-
acorn-dynamic-import@^2.0.0:
21-
version "2.0.2"
22-
resolved "https://registry.yarnpkg.com/acorn-dynamic-import/-/acorn-dynamic-import-2.0.2.tgz#c752bd210bef679501b6c6cb7fc84f8f47158cc4"
20+
acorn-dynamic-import@^3.0.0:
21+
version "3.0.0"
22+
resolved "https://registry.yarnpkg.com/acorn-dynamic-import/-/acorn-dynamic-import-3.0.0.tgz#901ceee4c7faaef7e07ad2a47e890675da50a278"
2323
dependencies:
24-
acorn "^4.0.3"
24+
acorn "^5.0.0"
2525

2626
acorn-globals@^1.0.3:
2727
version "1.0.9"
@@ -47,10 +47,6 @@ acorn@^3.0.4:
4747
version "3.3.0"
4848
resolved "https://registry.yarnpkg.com/acorn/-/acorn-3.3.0.tgz#45e37fb39e8da3f25baee3ff5369e2bb5f22017a"
4949

50-
acorn@^4.0.3:
51-
version "4.0.13"
52-
resolved "https://registry.yarnpkg.com/acorn/-/acorn-4.0.13.tgz#105495ae5361d697bd195c825192e1ad7f253787"
53-
5450
acorn@^5.0.0, acorn@^5.2.1:
5551
version "5.3.0"
5652
resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.3.0.tgz#7446d39459c54fb49a80e6ee6478149b940ec822"

0 commit comments

Comments
 (0)