Fix parse error when destructuring set with default value (#317)

This commit is contained in:
Brian Ng 2017-01-20 15:21:40 -06:00 committed by Daniel Tschinder
parent 55df6631fa
commit 461ed45942
3 changed files with 198 additions and 1 deletions

View File

@ -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);

View File

@ -0,0 +1 @@
({set = {}}) => set;

View File

@ -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": []
}
}