Skip to content

Commit 2b2c17f

Browse files
authored
Merge pull request webpack#8598 from kiliancs/acorn6
Upgrade acorn to v6
2 parents fdb6b13 + ef67132 commit 2b2c17f

File tree

4 files changed

+26
-21
lines changed

4 files changed

+26
-21
lines changed

lib/Parser.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@
66

77
// Syntax: https://developer.mozilla.org/en/SpiderMonkey/Parser_API
88

9-
const acorn = require("acorn-dynamic-import").default;
9+
const acorn = require("acorn");
10+
const acornDynamicImport = require("acorn-dynamic-import").default;
1011
const { Tapable, SyncBailHook, HookMap } = require("tapable");
1112
const util = require("util");
1213
const vm = require("vm");
1314
const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
1415
const StackedSetMap = require("./util/StackedSetMap");
1516
const TrackingSet = require("./util/TrackingSet");
1617

18+
const acornParser = acorn.Parser.extend(acornDynamicImport);
19+
1720
const joinRanges = (startRange, endRange) => {
1821
if (!endRange) return startRange;
1922
if (!startRange) return endRange;
@@ -25,10 +28,7 @@ const defaultParserOptions = {
2528
locations: true,
2629
ecmaVersion: 2019,
2730
sourceType: "module",
28-
onComment: null,
29-
plugins: {
30-
dynamicImport: true
31-
}
31+
onComment: null
3232
};
3333

3434
// regexp to match at lease one "magic comment"
@@ -2133,9 +2133,13 @@ class Parser extends Tapable {
21332133
sourceType: this.sourceType,
21342134
locations: false
21352135
});
2136+
// TODO(https://github.com/acornjs/acorn/issues/741)
2137+
// @ts-ignore
21362138
if (ast.body.length !== 1 || ast.body[0].type !== "ExpressionStatement") {
21372139
throw new Error("evaluate: Source is not a expression");
21382140
}
2141+
// TODO(https://github.com/acornjs/acorn/issues/741)
2142+
// @ts-ignore
21392143
return this.evaluateExpression(ast.body[0].expression);
21402144
}
21412145

@@ -2226,7 +2230,7 @@ class Parser extends Tapable {
22262230
let error;
22272231
let threw = false;
22282232
try {
2229-
ast = acorn.parse(code, parserOptions);
2233+
ast = acornParser.parse(code, parserOptions);
22302234
} catch (e) {
22312235
error = e;
22322236
threw = true;
@@ -2238,7 +2242,7 @@ class Parser extends Tapable {
22382242
parserOptions.onComment.length = 0;
22392243
}
22402244
try {
2241-
ast = acorn.parse(code, parserOptions);
2245+
ast = acornParser.parse(code, parserOptions);
22422246
threw = false;
22432247
} catch (e) {
22442248
threw = true;

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"@webassemblyjs/helper-module-context": "1.7.11",
1010
"@webassemblyjs/wasm-edit": "1.7.11",
1111
"@webassemblyjs/wasm-parser": "1.7.11",
12-
"acorn": "^5.6.2",
13-
"acorn-dynamic-import": "^3.0.0",
12+
"acorn": "^6.0.5",
13+
"acorn-dynamic-import": "^4.0.0",
1414
"ajv": "^6.1.0",
1515
"ajv-keywords": "^3.1.0",
1616
"chrome-trace-event": "^1.0.0",

test/cases/parsing/precreated-ast/ast-loader.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
"use strict";
22

3-
const acorn = require("acorn-dynamic-import").default;
3+
const acorn = require("acorn");
4+
const acornParser = acorn.Parser.extend(require("acorn-dynamic-import").default);
45

56
module.exports = function(source) {
67
const comments = [];
7-
const ast = acorn.parse(source, {
8+
const ast = acornParser.parse(source, {
89
ranges: true,
910
locations: true,
1011
ecmaVersion: 2017,
1112
sourceType: "module",
12-
plugins: {
13-
dynamicImport: true
14-
},
1513
onComment: comments
1614
});
1715

yarn.lock

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,10 @@ accepts@~1.2.12:
279279
mime-types "~2.1.6"
280280
negotiator "0.5.3"
281281

282-
acorn-dynamic-import@^3.0.0:
283-
version "3.0.0"
284-
resolved "https://registry.yarnpkg.com/acorn-dynamic-import/-/acorn-dynamic-import-3.0.0.tgz#901ceee4c7faaef7e07ad2a47e890675da50a278"
285-
integrity sha512-zVWV8Z8lislJoOKKqdNMOB+s6+XV5WERty8MnKBeFgwA+19XJjJHs2RP5dzM57FftIs+jQnRToLiWazKr6sSWg==
286-
dependencies:
287-
acorn "^5.0.0"
282+
acorn-dynamic-import@^4.0.0:
283+
version "4.0.0"
284+
resolved "https://registry.yarnpkg.com/acorn-dynamic-import/-/acorn-dynamic-import-4.0.0.tgz#482210140582a36b83c3e342e1cfebcaa9240948"
285+
integrity sha512-d3OEjQV4ROpoflsnUA8HozoIR504TFxNivYEUi6uwz0IYhBkTDXGuWlNdMtybRt3nqVx/L6XqMt0FxkXuWKZhw==
288286

289287
acorn-globals@^1.0.3:
290288
version "1.0.9"
@@ -339,11 +337,16 @@ acorn@^5.0.0, acorn@^5.3.0:
339337
resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.7.1.tgz#f095829297706a7c9776958c0afc8930a9b9d9d8"
340338
integrity sha512-d+nbxBUGKg7Arpsvbnlq61mc12ek3EY8EQldM3GPAhWJ1UVxC6TDGbIvUMNU6obBX3i1+ptCIzV4vq0gFPEGVQ==
341339

342-
acorn@^5.0.3, acorn@^5.6.0, acorn@^5.6.2:
340+
acorn@^5.0.3, acorn@^5.6.0:
343341
version "5.7.2"
344342
resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.7.2.tgz#91fa871883485d06708800318404e72bfb26dcc5"
345343
integrity sha512-cJrKCNcr2kv8dlDnbw+JPUGjHZzo4myaxOLmpOX8a+rgX94YeTcTMv/LFJUSByRpc+i4GgVnnhLxvMu/2Y+rqw==
346344

345+
acorn@^6.0.5:
346+
version "6.0.5"
347+
resolved "https://registry.yarnpkg.com/acorn/-/acorn-6.0.5.tgz#81730c0815f3f3b34d8efa95cb7430965f4d887a"
348+
integrity sha512-i33Zgp3XWtmZBMNvCr4azvOFeWVw1Rk6p3hfi3LUDvIFraOMywb1kAtrbi+med14m4Xfpqm3zRZMT+c0FNE7kg==
349+
347350
ajv-errors@^1.0.0:
348351
version "1.0.0"
349352
resolved "https://registry.yarnpkg.com/ajv-errors/-/ajv-errors-1.0.0.tgz#ecf021fa108fd17dfb5e6b383f2dd233e31ffc59"

0 commit comments

Comments
 (0)