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>
This commit is contained in:
3
packages/babel-parser/test/fixtures/es2015/for-of/invalid-let-as-identifier/input.js
vendored
Normal file
3
packages/babel-parser/test/fixtures/es2015/for-of/invalid-let-as-identifier/input.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
for (let.foo of []);
|
||||
for (let().bar of []);
|
||||
for (let``.bar of []);
|
||||
130
packages/babel-parser/test/fixtures/es2015/for-of/invalid-let-as-identifier/output.json
vendored
Normal file
130
packages/babel-parser/test/fixtures/es2015/for-of/invalid-let-as-identifier/output.json
vendored
Normal file
@@ -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": []
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user