New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate PropertyName of `__proto__` should be accepted in destructuring #1907

Open
KFlash opened this Issue Dec 25, 2017 · 0 comments

Comments

Projects
None yet
1 participant
@KFlash

KFlash commented Dec 25, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment