Skip to content

Commit

Permalink
Fix parsing of ambiguous object pattern with a 'set' property with a …
Browse files Browse the repository at this point in the history
…default value

Closes #957
  • Loading branch information
marijnh committed Jun 1, 2020
1 parent f66c4e7 commit eec9b37
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion acorn/src/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ pp.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startPos
} else if (!isPattern && !containsEsc &&
this.options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" &&
(prop.key.name === "get" || prop.key.name === "set") &&
(this.type !== tt.comma && this.type !== tt.braceR)) {
(this.type !== tt.comma && this.type !== tt.braceR && this.type !== tt.eq)) {
if (isGenerator || isAsync) this.unexpected()
prop.kind = prop.key.name
this.parsePropertyName(prop)
Expand Down
52 changes: 52 additions & 0 deletions test/tests-harmony.js
Original file line number Diff line number Diff line change
Expand Up @@ -16520,3 +16520,55 @@ test("({ __proto__: x, __proto__: y, __proto__: z }) => {}", {}, {ecmaVersion: 6
// Don't parse first token after a class or strict function as strict
test("class x {}\n05", {}, {ecmaVersion: 6})
test("function x() { 'use strict' }\n05", {}, {ecmaVersion: 6})

test("const myFn = ({ set = '' }) => {};", {
"type": "Program",
"body": [
{
"type": "VariableDeclaration",
"declarations": [
{
"type": "VariableDeclarator",
"id": {
"type": "Identifier",
"name": "myFn"
},
"init": {
"type": "ArrowFunctionExpression",
"params": [
{
"type": "ObjectPattern",
"properties": [
{
"type": "Property",
"key": {
"type": "Identifier",
"name": "set"
},
"kind": "init",
"value": {
"type": "AssignmentPattern",
"left": {
"type": "Identifier",
"name": "set"
},
"right": {
"type": "Literal",
"value": ""
}
}
}
]
}
],
"body": {
"type": "BlockStatement",
"body": []
}
}
}
],
"kind": "const"
}
]
}, {ecmaVersion: 6})

0 comments on commit eec9b37

Please sign in to comment.