Skip to content

Commit 9bbcad8

Browse files
xjamundxnzakas
authored andcommitted
Update: Upgrade Acorn to support ES2017 (fixes #287) (#290)
1 parent 8d9767d commit 9bbcad8

File tree

424 files changed

+35162
-13
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

424 files changed

+35162
-13
lines changed

README.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ var ast = espree.parse(code, {
4141
// create a top-level tokens array containing all tokens
4242
tokens: true,
4343

44-
// specify the language version (3, 5, 6, or 7, default is 5)
44+
// specify the language version (3, 5, 6, 7, or 8, default is 5)
4545
ecmaVersion: 5,
4646

4747
// specify which type of script you're parsing (script or module, default is script)
@@ -130,10 +130,17 @@ We are building on top of Acorn, however, so that we can contribute back and hel
130130

131131
All of them.
132132

133-
### What ECMAScript 7 features do you support?
133+
### What ECMAScript 7/2016 features do you support?
134134

135135
There is only one ECMAScript 7 syntax change: the exponentiation operator. Espree supports this.
136136

137+
### What ECMAScript 2017 features do you support?
138+
139+
Because ECMAScript 2017 is still under development, we are implementing features as they are finalized. Currently, Espree supports:
140+
141+
* `async` functions
142+
* Trailing commas in function declarations and calls (including arrow functions and concise methods)
143+
137144
### How do you determine which experimental features to support?
138145

139146
In general, we do not support experimental JavaScript features. We may make exceptions from time to time depending on the maturity of the features.

espree.js

+21-4
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ acorn.plugins.espree = function(instance) {
340340

341341
var prop = this.startNode(),
342342
isGenerator,
343+
isAsync,
343344
startPos,
344345
startLoc;
345346

@@ -369,8 +370,22 @@ acorn.plugins.espree = function(instance) {
369370
}
370371
}
371372

372-
this.parsePropertyName(prop);
373-
this.parsePropertyValue(prop, isPattern, isGenerator, startPos, startLoc, refShorthandDefaultPos);
373+
// grab the property name or "async"
374+
this.parsePropertyName(prop/* , refDestructuringErrors */);
375+
if (this.options.ecmaVersion >= 8 &&
376+
!isPattern &&
377+
!isGenerator &&
378+
!prop.computed &&
379+
prop.key.type === "Identifier" &&
380+
prop.key.name === "async" &&
381+
this.type !== tt.parenL &&
382+
!this.canInsertSemicolon()
383+
) {
384+
this.parsePropertyName(prop/* , refDestructuringErrors */);
385+
isAsync = true;
386+
}
387+
388+
this.parsePropertyValue(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refShorthandDefaultPos);
374389
this.checkPropClash(prop, propHash);
375390
node.properties.push(this.finishNode(prop, "Property"));
376391
}
@@ -506,12 +521,13 @@ function tokenize(code, options) {
506521
case 5:
507522
case 6:
508523
case 7:
524+
case 8:
509525
acornOptions.ecmaVersion = options.ecmaVersion;
510526
extra.ecmaVersion = options.ecmaVersion;
511527
break;
512528

513529
default:
514-
throw new Error("ecmaVersion must be 3, 5, 6, or 7.");
530+
throw new Error("ecmaVersion must be 3, 5, 6, 7, or 8.");
515531
}
516532
}
517533

@@ -643,12 +659,13 @@ function parse(code, options) {
643659
case 5:
644660
case 6:
645661
case 7:
662+
case 8:
646663
acornOptions.ecmaVersion = options.ecmaVersion;
647664
extra.ecmaVersion = options.ecmaVersion;
648665
break;
649666

650667
default:
651-
throw new Error("ecmaVersion must be 3, 5, 6, or 7.");
668+
throw new Error("ecmaVersion must be 3, 5, 6, 7, or 8.");
652669
}
653670
}
654671

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
},
1919
"license": "BSD-2-Clause",
2020
"dependencies": {
21-
"acorn": "^3.3.0",
21+
"acorn": "^4.0.1",
2222
"acorn-jsx": "^3.0.0"
2323
},
2424
"devDependencies": {
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
2-
"index": 4,
2+
"index": 5,
33
"lineNumber": 1,
4-
"column": 5,
4+
"column": 6,
55
"message": "Comma is not permitted after the rest element"
66
};
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
2-
"index": 4,
2+
"index": 5,
33
"lineNumber": 1,
4-
"column": 5,
4+
"column": 6,
55
"message": "Comma is not permitted after the rest element"
66
};
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
2-
"index": 4,
2+
"index": 5,
33
"lineNumber": 1,
4-
"column": 5,
4+
"column": 6,
55
"message": "Comma is not permitted after the rest element"
66
};

0 commit comments

Comments
 (0)