Skip to content

Commit

Permalink
Merge pull request #8598 from kiliancs/acorn6
Browse files Browse the repository at this point in the history
Upgrade acorn to v6
  • Loading branch information
sokra committed Jan 14, 2019
2 parents fdb6b13 + ef67132 commit 2b2c17f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 21 deletions.
18 changes: 11 additions & 7 deletions lib/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@

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

const acorn = require("acorn-dynamic-import").default;
const acorn = require("acorn");
const acornDynamicImport = require("acorn-dynamic-import").default;
const { Tapable, SyncBailHook, HookMap } = require("tapable");
const util = require("util");
const vm = require("vm");
const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
const StackedSetMap = require("./util/StackedSetMap");
const TrackingSet = require("./util/TrackingSet");

const acornParser = acorn.Parser.extend(acornDynamicImport);

const joinRanges = (startRange, endRange) => {
if (!endRange) return startRange;
if (!startRange) return endRange;
Expand All @@ -25,10 +28,7 @@ const defaultParserOptions = {
locations: true,
ecmaVersion: 2019,
sourceType: "module",
onComment: null,
plugins: {
dynamicImport: true
}
onComment: null
};

// regexp to match at lease one "magic comment"
Expand Down Expand Up @@ -2133,9 +2133,13 @@ class Parser extends Tapable {
sourceType: this.sourceType,
locations: false
});
// TODO(https://github.com/acornjs/acorn/issues/741)
// @ts-ignore
if (ast.body.length !== 1 || ast.body[0].type !== "ExpressionStatement") {
throw new Error("evaluate: Source is not a expression");
}
// TODO(https://github.com/acornjs/acorn/issues/741)
// @ts-ignore
return this.evaluateExpression(ast.body[0].expression);
}

Expand Down Expand Up @@ -2226,7 +2230,7 @@ class Parser extends Tapable {
let error;
let threw = false;
try {
ast = acorn.parse(code, parserOptions);
ast = acornParser.parse(code, parserOptions);
} catch (e) {
error = e;
threw = true;
Expand All @@ -2238,7 +2242,7 @@ class Parser extends Tapable {
parserOptions.onComment.length = 0;
}
try {
ast = acorn.parse(code, parserOptions);
ast = acornParser.parse(code, parserOptions);
threw = false;
} catch (e) {
threw = true;
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"@webassemblyjs/helper-module-context": "1.7.11",
"@webassemblyjs/wasm-edit": "1.7.11",
"@webassemblyjs/wasm-parser": "1.7.11",
"acorn": "^5.6.2",
"acorn-dynamic-import": "^3.0.0",
"acorn": "^6.0.5",
"acorn-dynamic-import": "^4.0.0",
"ajv": "^6.1.0",
"ajv-keywords": "^3.1.0",
"chrome-trace-event": "^1.0.0",
Expand Down
8 changes: 3 additions & 5 deletions test/cases/parsing/precreated-ast/ast-loader.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
"use strict";

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

module.exports = function(source) {
const comments = [];
const ast = acorn.parse(source, {
const ast = acornParser.parse(source, {
ranges: true,
locations: true,
ecmaVersion: 2017,
sourceType: "module",
plugins: {
dynamicImport: true
},
onComment: comments
});

Expand Down
17 changes: 10 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,10 @@ accepts@~1.2.12:
mime-types "~2.1.6"
negotiator "0.5.3"

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

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

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

acorn@^6.0.5:
version "6.0.5"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-6.0.5.tgz#81730c0815f3f3b34d8efa95cb7430965f4d887a"
integrity sha512-i33Zgp3XWtmZBMNvCr4azvOFeWVw1Rk6p3hfi3LUDvIFraOMywb1kAtrbi+med14m4Xfpqm3zRZMT+c0FNE7kg==

ajv-errors@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/ajv-errors/-/ajv-errors-1.0.0.tgz#ecf021fa108fd17dfb5e6b383f2dd233e31ffc59"
Expand Down

0 comments on commit 2b2c17f

Please sign in to comment.