Skip to content
Permalink
Browse files
Merge pull request #6452 from webpack/update_acorn
Update parser to support ES 2018
  • Loading branch information
sokra committed Feb 24, 2018
2 parents 9179980 + b0949cb commit c7eb8951ffaaca4ade38efa96efb9d0d5814a4df
@@ -24,7 +24,7 @@ const joinRanges = (startRange, endRange) => {
const defaultParserOptions = {
ranges: true,
locations: true,
ecmaVersion: 2017,
ecmaVersion: 2018,
sourceType: "module",
onComment: null,
plugins: {
@@ -1297,6 +1297,10 @@ class Parser extends Tapable {
walkObjectExpression(expression) {
for(let propIndex = 0, len = expression.properties.length; propIndex < len; propIndex++) {
const prop = expression.properties[propIndex];
if(prop.type === "SpreadElement") {
this.walkExpression(prop.argument);
continue;
}
if(prop.computed)
this.walkExpression(prop.key);
if(prop.shorthand)
@@ -1856,7 +1860,7 @@ class Parser extends Tapable {
}

static parse(code, options) {
const type = options.sourceType;
const type = options ? options.sourceType : "module";
const parserOptions = Object.assign(Object.create(null), defaultParserOptions, options);

if(type === "auto") {
@@ -468,7 +468,8 @@ describe("Parser", () => {
const cases = {
"async function": "async function x() {}",
"async arrow function": "async () => {}",
"await expression": "async function x(y) { await y }"
"await expression": "async function x(y) { await y }",
"await iteration": "async function f() { for await (x of xs); }"
};
const parser = new Parser();
Object.keys(cases).forEach((name) => {
@@ -511,4 +512,20 @@ describe("Parser", () => {
});
});
});

describe("object rest/spread support", () => {
describe("should accept", () => {
const cases = {
"object spread": "({...obj})",
"object rest": "({...obj} = foo)"
};
Object.keys(cases).forEach((name) => {
const expr = cases[name];
it(name, () => {
const actual = Parser.parse(expr);
should.strictEqual(typeof actual, "object");
});
});
});
});
});
@@ -0,0 +1 @@
module.exports = "ok";
@@ -0,0 +1,11 @@
import X, { A, B } from "./module";
import * as M from "./module";

it("should support spread operator", function() {
var o1 = { ...X };
o1.should.be.eql({ A: "A", B: "B" });
var o2 = { ...({ X }) };
o2.should.be.eql({ X: { A: "A", B: "B" } });
var o3 = { ...M };
o3.should.be.eql({ default: { A: "A", B: "B" }, A: "A", B: "B" });
});
@@ -0,0 +1,6 @@
const A = "A";
const B = "B";

export default { A, B };

export { A, B };
@@ -0,0 +1,5 @@
var supportsSpread = require("../../../helpers/supportsSpread");

module.exports = function(config) {
return supportsSpread();
};
@@ -0,0 +1,9 @@
module.exports = function supportsSpread() {
try {
var x = { a: true }, y; // eslint-disable-line no-unused-vars
eval("y = { ...x }");
return y !== x && y.a;
} catch(e) {
return false;
}
};
@@ -47,7 +47,11 @@ acorn@^3.0.4:
version "3.3.0"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-3.3.0.tgz#45e37fb39e8da3f25baee3ff5369e2bb5f22017a"

acorn@^5.0.0, acorn@^5.2.1:
acorn@^5.0.0:
version "5.4.1"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.4.1.tgz#fdc58d9d17f4a4e98d102ded826a9b9759125102"

acorn@^5.2.1:
version "5.3.0"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.3.0.tgz#7446d39459c54fb49a80e6ee6478149b940ec822"

0 comments on commit c7eb895

Please sign in to comment.