Duplicate PropertyName of `__proto__` should be accepted in destructuring
Open
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 7.1k
- Forks
- 773
- PR merge metrics
- No merged PRs in 30d
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the parser path for object assignment patterns and the duplicate proto validation, using the esprima.parse reproducer in this issue. Compare its behavior with the linked Test262 case and verify that both examples parse into the shown nested AssignmentExpression and ObjectPattern AST without an error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100