Skip to content

Commit

Permalink
Update: Upgrade Acorn to support ES2017 (fixes #287)
Browse files Browse the repository at this point in the history
  • Loading branch information
nzakas authored and xjamundx committed Sep 14, 2016
1 parent 8d9767d commit bb15253
Show file tree
Hide file tree
Showing 424 changed files with 35,162 additions and 13 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var ast = espree.parse(code, {
// create a top-level tokens array containing all tokens
tokens: true,

// specify the language version (3, 5, 6, or 7, default is 5)
// specify the language version (3, 5, 6, 7, or 8, default is 5)
ecmaVersion: 5,

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

All of them.

### What ECMAScript 7 features do you support?
### What ECMAScript 7/2016 features do you support?

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

### What ECMAScript 2017 features do you support?

Because ECMAScript 2017 is still under development, we are implementing features as they are finalized. Currently, Espree supports:

* `async` functions
* Trailing commas in function declarations and calls (including arrow functions and concise methods)

### How do you determine which experimental features to support?

In general, we do not support experimental JavaScript features. We may make exceptions from time to time depending on the maturity of the features.
25 changes: 21 additions & 4 deletions espree.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ acorn.plugins.espree = function(instance) {

var prop = this.startNode(),
isGenerator,
isAsync,
startPos,
startLoc;

Expand Down Expand Up @@ -369,8 +370,22 @@ acorn.plugins.espree = function(instance) {
}
}

this.parsePropertyName(prop);
this.parsePropertyValue(prop, isPattern, isGenerator, startPos, startLoc, refShorthandDefaultPos);
// grab the property name or "async"
this.parsePropertyName(prop/* , refDestructuringErrors */);
if (this.options.ecmaVersion >= 8 &&
!isPattern &&
!isGenerator &&
!prop.computed &&
prop.key.type === "Identifier" &&
prop.key.name === "async" &&
this.type !== tt.parenL &&
!this.canInsertSemicolon()
) {
this.parsePropertyName(prop/* , refDestructuringErrors */);
isAsync = true;
}

this.parsePropertyValue(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refShorthandDefaultPos);
this.checkPropClash(prop, propHash);
node.properties.push(this.finishNode(prop, "Property"));
}
Expand Down Expand Up @@ -506,12 +521,13 @@ function tokenize(code, options) {
case 5:
case 6:
case 7:
case 8:
acornOptions.ecmaVersion = options.ecmaVersion;
extra.ecmaVersion = options.ecmaVersion;
break;

default:
throw new Error("ecmaVersion must be 3, 5, 6, or 7.");
throw new Error("ecmaVersion must be 3, 5, 6, 7, or 8.");
}
}

Expand Down Expand Up @@ -643,12 +659,13 @@ function parse(code, options) {
case 5:
case 6:
case 7:
case 8:
acornOptions.ecmaVersion = options.ecmaVersion;
extra.ecmaVersion = options.ecmaVersion;
break;

default:
throw new Error("ecmaVersion must be 3, 5, 6, or 7.");
throw new Error("ecmaVersion must be 3, 5, 6, 7, or 8.");
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"license": "BSD-2-Clause",
"dependencies": {
"acorn": "^3.3.0",
"acorn": "^4.0.1",
"acorn-jsx": "^3.0.0"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
"index": 4,
"index": 5,
"lineNumber": 1,
"column": 5,
"column": 6,
"message": "Comma is not permitted after the rest element"
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
"index": 4,
"index": 5,
"lineNumber": 1,
"column": 5,
"column": 6,
"message": "Comma is not permitted after the rest element"
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
"index": 4,
"index": 5,
"lineNumber": 1,
"column": 5,
"column": 6,
"message": "Comma is not permitted after the rest element"
};

0 comments on commit bb15253

Please sign in to comment.