The following code:
When run through esprima returns:
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "ArrowFunctionExpression",
"id": null,
"params": [
{
"type": "ObjectPattern",
"properties": [
{
"type": "Property",
"key": {
"type": "Identifier",
"name": "a"
},
"computed": false,
"value": {
"type": "AssignmentPattern",
"left": {
"type": "Identifier",
"name": "a"
},
"right": {
"type": "Literal",
"value": "b",
"raw": "'b'"
}
},
"kind": "init",
"method": false,
"shorthand": true
}
]
}
],
"defaults": [],
"body": {
"type": "BlockStatement",
"body": []
},
"generator": false,
"expression": false
}
}
],
"sourceType": "script"
}
And when run back through escodegen, returns:
i.e., the value of a is not recognized and the AssignmentExpression is lost
..
I was playing around with this, and I found that adding expr.value as a third parameter to generatePropertyKey and modifying like so makes it work
- result.push(this.generateExpression(expr, Precedence.Sequence, E_TTT));
+ if (value.type === 'AssignmentPattern') {
+ result.push(this.AssignmentPattern(value, Precedence.Sequence, E_TTT));
+ }
+ else {
+ result.push(this.generateExpression(expr, Precedence.Sequence, E_TTT));
+ }
Thing is, I'm unsure if this could have other unintended consequences...the tests still pass, fwiw.
I can send along a PR with this change, and a simple object destructuring test... thoughts?
The following code:
When run through esprima returns:
{ "type": "Program", "body": [ { "type": "ExpressionStatement", "expression": { "type": "ArrowFunctionExpression", "id": null, "params": [ { "type": "ObjectPattern", "properties": [ { "type": "Property", "key": { "type": "Identifier", "name": "a" }, "computed": false, "value": { "type": "AssignmentPattern", "left": { "type": "Identifier", "name": "a" }, "right": { "type": "Literal", "value": "b", "raw": "'b'" } }, "kind": "init", "method": false, "shorthand": true } ] } ], "defaults": [], "body": { "type": "BlockStatement", "body": [] }, "generator": false, "expression": false } } ], "sourceType": "script" }And when run back through escodegen, returns:
i.e., the
valueofais not recognized and the AssignmentExpression is lost..
I was playing around with this, and I found that adding
expr.valueas a third parameter togeneratePropertyKeyand modifying like so makes it workThing is, I'm unsure if this could have other unintended consequences...the tests still pass, fwiw.
I can send along a PR with this change, and a simple object destructuring test... thoughts?