Skip to content

Commit

Permalink
Fix: raise error for trailing commas after rest properties (fixes #310)…
Browse files Browse the repository at this point in the history
… (#323)
  • Loading branch information
not-an-aardvark authored and ilyavolodin committed Mar 24, 2017
1 parent 9d86ba5 commit 652990a
Show file tree
Hide file tree
Showing 5 changed files with 462 additions and 0 deletions.
5 changes: 5 additions & 0 deletions espree.js
Expand Up @@ -353,6 +353,7 @@ acorn.plugins.espree = function(instance) {
instance.parseObj = function(isPattern, refShorthandDefaultPos) {
var node = this.startNode(),
first = true,
hasRestProperty = false,
propHash = {};
node.properties = [];
this.next();
Expand All @@ -362,6 +363,9 @@ acorn.plugins.espree = function(instance) {
this.expect(tt.comma);

if (this.afterTrailingComma(tt.braceR)) {
if (hasRestProperty) {
this.raise(node.properties[node.properties.length - 1].end, "Unexpected trailing comma after rest property");
}
break;
}

Expand All @@ -378,6 +382,7 @@ acorn.plugins.espree = function(instance) {
if (extra.ecmaFeatures.experimentalObjectRestSpread && this.type === tt.ellipsis) {
if (isPattern) {
prop = this.parseObjectRest();
hasRestProperty = true;
} else {
prop = this.parseSpread();
prop.type = "ExperimentalSpreadProperty";
Expand Down
@@ -0,0 +1,6 @@
module.exports = {
index: 16,
lineNumber: 1,
column: 17,
message: "Unexpected trailing comma after rest property"
};
@@ -0,0 +1 @@
var { x, y, ...z, } = foo;

0 comments on commit 652990a

Please sign in to comment.