Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: the LHS in for-of loop should not start with let (#13049)
* fix: the LHS in for-of loop should not start with let * Update packages/babel-parser/src/parser/statement.js Co-authored-by: Nicol貌 Ribaudo <nicolo.ribaudo@gmail.com> Co-authored-by: Nicol貌 Ribaudo <nicolo.ribaudo@gmail.com>
- Loading branch information
1 parent
5c0d2f6
commit 8efbac4
Showing
4 changed files
with
155 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
packages/babel-parser/test/fixtures/es2015/for-of/invalid-let-as-identifier/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
for (let.foo of []); | ||
for (let().bar of []); | ||
for (let``.bar of []); |
130 changes: 130 additions & 0 deletions
130
packages/babel-parser/test/fixtures/es2015/for-of/invalid-let-as-identifier/output.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":66,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":22}}, | ||
"errors": [ | ||
"SyntaxError: The left-hand side of a for-of loop may not start with 'let'. (1:5)", | ||
"SyntaxError: The left-hand side of a for-of loop may not start with 'let'. (2:5)", | ||
"SyntaxError: The left-hand side of a for-of loop may not start with 'let'. (3:5)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":66,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":22}}, | ||
"sourceType": "script", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ForOfStatement", | ||
"start":0,"end":20,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":20}}, | ||
"await": false, | ||
"left": { | ||
"type": "MemberExpression", | ||
"start":5,"end":12,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":12}}, | ||
"object": { | ||
"type": "Identifier", | ||
"start":5,"end":8,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":8},"identifierName":"let"}, | ||
"name": "let" | ||
}, | ||
"computed": false, | ||
"property": { | ||
"type": "Identifier", | ||
"start":9,"end":12,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":12},"identifierName":"foo"}, | ||
"name": "foo" | ||
} | ||
}, | ||
"right": { | ||
"type": "ArrayExpression", | ||
"start":16,"end":18,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":18}}, | ||
"elements": [] | ||
}, | ||
"body": { | ||
"type": "EmptyStatement", | ||
"start":19,"end":20,"loc":{"start":{"line":1,"column":19},"end":{"line":1,"column":20}} | ||
} | ||
}, | ||
{ | ||
"type": "ForOfStatement", | ||
"start":21,"end":43,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":22}}, | ||
"await": false, | ||
"left": { | ||
"type": "MemberExpression", | ||
"start":26,"end":35,"loc":{"start":{"line":2,"column":5},"end":{"line":2,"column":14}}, | ||
"object": { | ||
"type": "CallExpression", | ||
"start":26,"end":31,"loc":{"start":{"line":2,"column":5},"end":{"line":2,"column":10}}, | ||
"callee": { | ||
"type": "Identifier", | ||
"start":26,"end":29,"loc":{"start":{"line":2,"column":5},"end":{"line":2,"column":8},"identifierName":"let"}, | ||
"name": "let" | ||
}, | ||
"arguments": [] | ||
}, | ||
"computed": false, | ||
"property": { | ||
"type": "Identifier", | ||
"start":32,"end":35,"loc":{"start":{"line":2,"column":11},"end":{"line":2,"column":14},"identifierName":"bar"}, | ||
"name": "bar" | ||
} | ||
}, | ||
"right": { | ||
"type": "ArrayExpression", | ||
"start":39,"end":41,"loc":{"start":{"line":2,"column":18},"end":{"line":2,"column":20}}, | ||
"elements": [] | ||
}, | ||
"body": { | ||
"type": "EmptyStatement", | ||
"start":42,"end":43,"loc":{"start":{"line":2,"column":21},"end":{"line":2,"column":22}} | ||
} | ||
}, | ||
{ | ||
"type": "ForOfStatement", | ||
"start":44,"end":66,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":22}}, | ||
"await": false, | ||
"left": { | ||
"type": "MemberExpression", | ||
"start":49,"end":58,"loc":{"start":{"line":3,"column":5},"end":{"line":3,"column":14}}, | ||
"object": { | ||
"type": "TaggedTemplateExpression", | ||
"start":49,"end":54,"loc":{"start":{"line":3,"column":5},"end":{"line":3,"column":10}}, | ||
"tag": { | ||
"type": "Identifier", | ||
"start":49,"end":52,"loc":{"start":{"line":3,"column":5},"end":{"line":3,"column":8},"identifierName":"let"}, | ||
"name": "let" | ||
}, | ||
"quasi": { | ||
"type": "TemplateLiteral", | ||
"start":52,"end":54,"loc":{"start":{"line":3,"column":8},"end":{"line":3,"column":10}}, | ||
"expressions": [], | ||
"quasis": [ | ||
{ | ||
"type": "TemplateElement", | ||
"start":53,"end":53,"loc":{"start":{"line":3,"column":9},"end":{"line":3,"column":9}}, | ||
"value": { | ||
"raw": "", | ||
"cooked": "" | ||
}, | ||
"tail": true | ||
} | ||
] | ||
} | ||
}, | ||
"computed": false, | ||
"property": { | ||
"type": "Identifier", | ||
"start":55,"end":58,"loc":{"start":{"line":3,"column":11},"end":{"line":3,"column":14},"identifierName":"bar"}, | ||
"name": "bar" | ||
} | ||
}, | ||
"right": { | ||
"type": "ArrayExpression", | ||
"start":62,"end":64,"loc":{"start":{"line":3,"column":18},"end":{"line":3,"column":20}}, | ||
"elements": [] | ||
}, | ||
"body": { | ||
"type": "EmptyStatement", | ||
"start":65,"end":66,"loc":{"start":{"line":3,"column":21},"end":{"line":3,"column":22}} | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |