esprima
esprima copied to clipboard
Duplicate PropertyName of `__proto__` should be accepted in destructuring
Annex B defines an early error for duplicate PropertyName of __proto__, in object initializers, but this does not apply to Object Assignment patterns
Steps to reproduce
esprima.parse('result = { __proto__: x, __proto__: y } = value;')
// Parenthesized
esprima.parse('result = ({ __proto__: x, __proto__: y } = value);')
Expected output
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "AssignmentExpression",
"left": {
"type": "Identifier",
"name": "result"
},
"operator": "=",
"right": {
"type": "AssignmentExpression",
"left": {
"type": "ObjectPattern",
"properties": [
{
"type": "Property",
"key": {
"type": "Identifier",
"name": "__proto__"
},
"value": {
"type": "Identifier",
"name": "x"
},
"kind": "init",
"computed": false,
"method": false,
"shorthand": false
},
{
"type": "Property",
"key": {
"type": "Identifier",
"name": "__proto__"
},
"value": {
"type": "Identifier",
"name": "y"
},
"kind": "init",
"computed": false,
"method": false,
"shorthand": false
}
]
},
"operator": "=",
"right": {
"type": "Identifier",
"name": "value"
}
}
}
}
],
"sourceType": "script"
}
Actual output
Throws Error: Line 1: Duplicate __proto__ fields are not allowed in object literals
Relevant references
There exist an Test262 test for this