Skip to content

Commit eec9b37

Browse files
committed
Fix parsing of ambiguous object pattern with a 'set' property with a default value
Closes #957
1 parent f66c4e7 commit eec9b37

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

acorn/src/expression.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ pp.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startPos
739739
} else if (!isPattern && !containsEsc &&
740740
this.options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" &&
741741
(prop.key.name === "get" || prop.key.name === "set") &&
742-
(this.type !== tt.comma && this.type !== tt.braceR)) {
742+
(this.type !== tt.comma && this.type !== tt.braceR && this.type !== tt.eq)) {
743743
if (isGenerator || isAsync) this.unexpected()
744744
prop.kind = prop.key.name
745745
this.parsePropertyName(prop)

test/tests-harmony.js

+52
Original file line numberDiff line numberDiff line change
@@ -16520,3 +16520,55 @@ test("({ __proto__: x, __proto__: y, __proto__: z }) => {}", {}, {ecmaVersion: 6
1652016520
// Don't parse first token after a class or strict function as strict
1652116521
test("class x {}\n05", {}, {ecmaVersion: 6})
1652216522
test("function x() { 'use strict' }\n05", {}, {ecmaVersion: 6})
16523+
16524+
test("const myFn = ({ set = '' }) => {};", {
16525+
"type": "Program",
16526+
"body": [
16527+
{
16528+
"type": "VariableDeclaration",
16529+
"declarations": [
16530+
{
16531+
"type": "VariableDeclarator",
16532+
"id": {
16533+
"type": "Identifier",
16534+
"name": "myFn"
16535+
},
16536+
"init": {
16537+
"type": "ArrowFunctionExpression",
16538+
"params": [
16539+
{
16540+
"type": "ObjectPattern",
16541+
"properties": [
16542+
{
16543+
"type": "Property",
16544+
"key": {
16545+
"type": "Identifier",
16546+
"name": "set"
16547+
},
16548+
"kind": "init",
16549+
"value": {
16550+
"type": "AssignmentPattern",
16551+
"left": {
16552+
"type": "Identifier",
16553+
"name": "set"
16554+
},
16555+
"right": {
16556+
"type": "Literal",
16557+
"value": ""
16558+
}
16559+
}
16560+
}
16561+
]
16562+
}
16563+
],
16564+
"body": {
16565+
"type": "BlockStatement",
16566+
"body": []
16567+
}
16568+
}
16569+
}
16570+
],
16571+
"kind": "const"
16572+
}
16573+
]
16574+
}, {ecmaVersion: 6})

0 commit comments

Comments
 (0)