Skip to content

Commit 135ab83

Browse files
Throw on duplicate __proto__ props followed by assignment (#13951)
1 parent dd63950 commit 135ab83

7 files changed

Lines changed: 176 additions & 79 deletions

File tree

packages/babel-parser/src/parser/expression.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -309,17 +309,18 @@ export default class ExpressionParser extends LValParser {
309309

310310
if (this.match(tt.eq)) {
311311
node.left = this.toAssignable(left, /* isLHS */ true);
312-
refExpressionErrors.doubleProto = -1; // reset because double __proto__ is valid in assignment expression
312+
313+
if (refExpressionErrors.doubleProto >= startPos) {
314+
refExpressionErrors.doubleProto = -1; // reset because double __proto__ is valid in assignment expression
315+
}
316+
if (refExpressionErrors.shorthandAssign >= startPos) {
317+
refExpressionErrors.shorthandAssign = -1; // reset because shorthand default was used correctly
318+
}
313319
} else {
314320
node.left = left;
315321
}
316322

317-
if (refExpressionErrors.shorthandAssign >= node.left.start) {
318-
refExpressionErrors.shorthandAssign = -1; // reset because shorthand default was used correctly
319-
}
320-
321323
this.checkLVal(left, "assignment expression");
322-
323324
this.next();
324325
node.right = this.parseMaybeAssign();
325326
return this.finishNode(node, "AssignmentExpression");
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
({
2+
__proto__: a,
3+
__proto__: a,
4+
a: a = 1
5+
})
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
{
2+
"type": "File",
3+
"start":0,"end":48,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":2}},
4+
"errors": [
5+
"SyntaxError: Redefinition of __proto__ property. (3:2)"
6+
],
7+
"program": {
8+
"type": "Program",
9+
"start":0,"end":48,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":2}},
10+
"sourceType": "script",
11+
"interpreter": null,
12+
"body": [
13+
{
14+
"type": "ExpressionStatement",
15+
"start":0,"end":48,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":2}},
16+
"expression": {
17+
"type": "ObjectExpression",
18+
"start":1,"end":47,"loc":{"start":{"line":1,"column":1},"end":{"line":5,"column":1}},
19+
"properties": [
20+
{
21+
"type": "ObjectProperty",
22+
"start":5,"end":17,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":14}},
23+
"method": false,
24+
"key": {
25+
"type": "Identifier",
26+
"start":5,"end":14,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":11},"identifierName":"__proto__"},
27+
"name": "__proto__"
28+
},
29+
"computed": false,
30+
"shorthand": false,
31+
"value": {
32+
"type": "Identifier",
33+
"start":16,"end":17,"loc":{"start":{"line":2,"column":13},"end":{"line":2,"column":14},"identifierName":"a"},
34+
"name": "a"
35+
}
36+
},
37+
{
38+
"type": "ObjectProperty",
39+
"start":21,"end":33,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":14}},
40+
"method": false,
41+
"key": {
42+
"type": "Identifier",
43+
"start":21,"end":30,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":11},"identifierName":"__proto__"},
44+
"name": "__proto__"
45+
},
46+
"computed": false,
47+
"shorthand": false,
48+
"value": {
49+
"type": "Identifier",
50+
"start":32,"end":33,"loc":{"start":{"line":3,"column":13},"end":{"line":3,"column":14},"identifierName":"a"},
51+
"name": "a"
52+
}
53+
},
54+
{
55+
"type": "ObjectProperty",
56+
"start":37,"end":45,"loc":{"start":{"line":4,"column":2},"end":{"line":4,"column":10}},
57+
"method": false,
58+
"key": {
59+
"type": "Identifier",
60+
"start":37,"end":38,"loc":{"start":{"line":4,"column":2},"end":{"line":4,"column":3},"identifierName":"a"},
61+
"name": "a"
62+
},
63+
"computed": false,
64+
"shorthand": false,
65+
"value": {
66+
"type": "AssignmentExpression",
67+
"start":40,"end":45,"loc":{"start":{"line":4,"column":5},"end":{"line":4,"column":10}},
68+
"operator": "=",
69+
"left": {
70+
"type": "Identifier",
71+
"start":40,"end":41,"loc":{"start":{"line":4,"column":5},"end":{"line":4,"column":6},"identifierName":"a"},
72+
"name": "a"
73+
},
74+
"right": {
75+
"type": "NumericLiteral",
76+
"start":44,"end":45,"loc":{"start":{"line":4,"column":9},"end":{"line":4,"column":10}},
77+
"extra": {
78+
"rawValue": 1,
79+
"raw": "1"
80+
},
81+
"value": 1
82+
}
83+
}
84+
}
85+
],
86+
"extra": {
87+
"parenthesized": true,
88+
"parenStart": 0
89+
}
90+
}
91+
}
92+
],
93+
"directives": []
94+
}
95+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
({
2+
__proto__: a,
3+
__proto__: a,
4+
})
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"type": "File",
3+
"start":0,"end":37,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":2}},
4+
"errors": [
5+
"SyntaxError: Redefinition of __proto__ property. (3:2)"
6+
],
7+
"program": {
8+
"type": "Program",
9+
"start":0,"end":37,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":2}},
10+
"sourceType": "script",
11+
"interpreter": null,
12+
"body": [
13+
{
14+
"type": "ExpressionStatement",
15+
"start":0,"end":37,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":2}},
16+
"expression": {
17+
"type": "ObjectExpression",
18+
"start":1,"end":36,"loc":{"start":{"line":1,"column":1},"end":{"line":4,"column":1}},
19+
"properties": [
20+
{
21+
"type": "ObjectProperty",
22+
"start":5,"end":17,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":14}},
23+
"method": false,
24+
"key": {
25+
"type": "Identifier",
26+
"start":5,"end":14,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":11},"identifierName":"__proto__"},
27+
"name": "__proto__"
28+
},
29+
"computed": false,
30+
"shorthand": false,
31+
"value": {
32+
"type": "Identifier",
33+
"start":16,"end":17,"loc":{"start":{"line":2,"column":13},"end":{"line":2,"column":14},"identifierName":"a"},
34+
"name": "a"
35+
}
36+
},
37+
{
38+
"type": "ObjectProperty",
39+
"start":21,"end":33,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":14}},
40+
"method": false,
41+
"key": {
42+
"type": "Identifier",
43+
"start":21,"end":30,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":11},"identifierName":"__proto__"},
44+
"name": "__proto__"
45+
},
46+
"computed": false,
47+
"shorthand": false,
48+
"value": {
49+
"type": "Identifier",
50+
"start":32,"end":33,"loc":{"start":{"line":3,"column":13},"end":{"line":3,"column":14},"identifierName":"a"},
51+
"name": "a"
52+
}
53+
}
54+
],
55+
"extra": {
56+
"trailingComma": 33,
57+
"parenthesized": true,
58+
"parenStart": 0
59+
}
60+
}
61+
}
62+
],
63+
"directives": []
64+
}
65+
}

packages/babel-parser/test/fixtures/es2015/uncategorised/348/input.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/babel-parser/test/fixtures/es2015/uncategorised/348/output.json

Lines changed: 0 additions & 72 deletions
This file was deleted.

0 commit comments

Comments
 (0)