Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.

Commit

Permalink
Fix parse error when destructuring set with default value (#317)
Browse files Browse the repository at this point in the history
  • Loading branch information
existentialism authored and danez committed Jan 20, 2017
1 parent 55df663 commit 461ed45
Show file tree
Hide file tree
Showing 3 changed files with 198 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/parser/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,13 @@ pp.parseObjPropValue = function (prop, startPos, startLoc, isGenerator, isAsync,
return this.finishNode(prop, "ObjectProperty");
}

if (!isPattern && !prop.computed && prop.key.type === "Identifier" && (prop.key.name === "get" || prop.key.name === "set") && (!this.match(tt.comma) && !this.match(tt.braceR))) {
if (
!isPattern &&
!prop.computed &&
prop.key.type === "Identifier" &&
(prop.key.name === "get" || prop.key.name === "set") &&
(!this.match(tt.comma) && !this.match(tt.braceR) && !this.match(tt.eq))
) {
if (isGenerator || isAsync) this.unexpected();
prop.kind = prop.key.name;
this.parsePropertyName(prop);
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/es2015/uncategorised/393/actual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
({set = {}}) => set;
190 changes: 190 additions & 0 deletions test/fixtures/es2015/uncategorised/393/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
{
"type": "File",
"start": 0,
"end": 20,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 20
}
},
"program": {
"type": "Program",
"start": 0,
"end": 20,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 20
}
},
"sourceType": "script",
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 20,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 20
}
},
"expression": {
"type": "ArrowFunctionExpression",
"start": 0,
"end": 19,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 19
}
},
"id": null,
"generator": false,
"expression": true,
"async": false,
"params": [
{
"type": "ObjectPattern",
"start": 1,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 11
}
},
"properties": [
{
"type": "ObjectProperty",
"start": 2,
"end": 10,
"loc": {
"start": {
"line": 1,
"column": 2
},
"end": {
"line": 1,
"column": 10
}
},
"method": false,
"shorthand": true,
"computed": false,
"key": {
"type": "Identifier",
"start": 2,
"end": 5,
"loc": {
"start": {
"line": 1,
"column": 2
},
"end": {
"line": 1,
"column": 5
},
"identifierName": "set"
},
"name": "set"
},
"value": {
"type": "AssignmentPattern",
"start": 2,
"end": 10,
"loc": {
"start": {
"line": 1,
"column": 2
},
"end": {
"line": 1,
"column": 10
}
},
"left": {
"type": "Identifier",
"start": 2,
"end": 5,
"loc": {
"start": {
"line": 1,
"column": 2
},
"end": {
"line": 1,
"column": 5
},
"identifierName": "set"
},
"name": "set"
},
"right": {
"type": "ObjectExpression",
"start": 8,
"end": 10,
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 1,
"column": 10
}
},
"properties": []
}
},
"extra": {
"shorthand": true
}
}
]
}
],
"body": {
"type": "Identifier",
"start": 16,
"end": 19,
"loc": {
"start": {
"line": 1,
"column": 16
},
"end": {
"line": 1,
"column": 19
},
"identifierName": "set"
},
"name": "set"
}
}
}
],
"directives": []
}
}

0 comments on commit 461ed45

Please sign in to comment.