Skip to content

Commit 652990a

Browse files
not-an-aardvarkilyavolodin
authored andcommitted
Fix: raise error for trailing commas after rest properties (fixes #310) (#323)
1 parent 9d86ba5 commit 652990a

File tree

5 files changed

+462
-0
lines changed

5 files changed

+462
-0
lines changed

espree.js

+5
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ acorn.plugins.espree = function(instance) {
353353
instance.parseObj = function(isPattern, refShorthandDefaultPos) {
354354
var node = this.startNode(),
355355
first = true,
356+
hasRestProperty = false,
356357
propHash = {};
357358
node.properties = [];
358359
this.next();
@@ -362,6 +363,9 @@ acorn.plugins.espree = function(instance) {
362363
this.expect(tt.comma);
363364

364365
if (this.afterTrailingComma(tt.braceR)) {
366+
if (hasRestProperty) {
367+
this.raise(node.properties[node.properties.length - 1].end, "Unexpected trailing comma after rest property");
368+
}
365369
break;
366370
}
367371

@@ -378,6 +382,7 @@ acorn.plugins.espree = function(instance) {
378382
if (extra.ecmaFeatures.experimentalObjectRestSpread && this.type === tt.ellipsis) {
379383
if (isPattern) {
380384
prop = this.parseObjectRest();
385+
hasRestProperty = true;
381386
} else {
382387
prop = this.parseSpread();
383388
prop.type = "ExperimentalSpreadProperty";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
index: 16,
3+
lineNumber: 1,
4+
column: 17,
5+
message: "Unexpected trailing comma after rest property"
6+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var { x, y, ...z, } = foo;

0 commit comments

Comments
 (0)