Skip to content

Commit

Permalink
fix: triple __proto__ in object patterns should be allowed (#11009)
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Jan 16, 2020
1 parent 6363b59 commit a1063d2
Show file tree
Hide file tree
Showing 3 changed files with 267 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/babel-parser/src/parser/expression.js
Expand Up @@ -88,10 +88,13 @@ export default class ExpressionParser extends LValParser {
const name = key.type === "Identifier" ? key.name : String(key.value);

if (name === "__proto__") {
// Store the first redefinition's position
if (protoRef.used) {
if (refExpressionErrors && refExpressionErrors.doubleProto === -1) {
refExpressionErrors.doubleProto = key.start;
if (refExpressionErrors) {
// Store the first redefinition's position, otherwise ignore because
// we are parsing ambiguous pattern
if (refExpressionErrors.doubleProto === -1) {
refExpressionErrors.doubleProto = key.start;
}
} else {
this.raise(key.start, "Redefinition of __proto__ property");
}
Expand Down
@@ -0,0 +1 @@
({ __proto__: x, __proto__: y, __proto__: z }) => {};
@@ -0,0 +1,260 @@
{
"type": "File",
"start": 0,
"end": 53,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 53
}
},
"program": {
"type": "Program",
"start": 0,
"end": 53,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 53
}
},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 53,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 53
}
},
"expression": {
"type": "ArrowFunctionExpression",
"start": 0,
"end": 52,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 52
}
},
"id": null,
"generator": false,
"async": false,
"params": [
{
"type": "ObjectPattern",
"start": 1,
"end": 45,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 45
}
},
"properties": [
{
"type": "ObjectProperty",
"start": 3,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 3
},
"end": {
"line": 1,
"column": 15
}
},
"method": false,
"key": {
"type": "Identifier",
"start": 3,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 3
},
"end": {
"line": 1,
"column": 12
},
"identifierName": "__proto__"
},
"name": "__proto__"
},
"computed": false,
"shorthand": false,
"value": {
"type": "Identifier",
"start": 14,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 14
},
"end": {
"line": 1,
"column": 15
},
"identifierName": "x"
},
"name": "x"
}
},
{
"type": "ObjectProperty",
"start": 17,
"end": 29,
"loc": {
"start": {
"line": 1,
"column": 17
},
"end": {
"line": 1,
"column": 29
}
},
"method": false,
"key": {
"type": "Identifier",
"start": 17,
"end": 26,
"loc": {
"start": {
"line": 1,
"column": 17
},
"end": {
"line": 1,
"column": 26
},
"identifierName": "__proto__"
},
"name": "__proto__"
},
"computed": false,
"shorthand": false,
"value": {
"type": "Identifier",
"start": 28,
"end": 29,
"loc": {
"start": {
"line": 1,
"column": 28
},
"end": {
"line": 1,
"column": 29
},
"identifierName": "y"
},
"name": "y"
}
},
{
"type": "ObjectProperty",
"start": 31,
"end": 43,
"loc": {
"start": {
"line": 1,
"column": 31
},
"end": {
"line": 1,
"column": 43
}
},
"method": false,
"key": {
"type": "Identifier",
"start": 31,
"end": 40,
"loc": {
"start": {
"line": 1,
"column": 31
},
"end": {
"line": 1,
"column": 40
},
"identifierName": "__proto__"
},
"name": "__proto__"
},
"computed": false,
"shorthand": false,
"value": {
"type": "Identifier",
"start": 42,
"end": 43,
"loc": {
"start": {
"line": 1,
"column": 42
},
"end": {
"line": 1,
"column": 43
},
"identifierName": "z"
},
"name": "z"
}
}
]
}
],
"body": {
"type": "BlockStatement",
"start": 50,
"end": 52,
"loc": {
"start": {
"line": 1,
"column": 50
},
"end": {
"line": 1,
"column": 52
}
},
"body": [],
"directives": []
}
}
}
],
"directives": []
}
}

0 comments on commit a1063d2

Please sign in to comment.