Skip to content

Commit

Permalink
disallow of as a for-using-of binding
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Sep 27, 2022
1 parent 860a51f commit 6cd106e
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 115 deletions.
29 changes: 2 additions & 27 deletions packages/babel-parser/src/parser/statement.ts
Expand Up @@ -317,33 +317,8 @@ export default abstract class StatementParser extends ExpressionParser {
startsUsingForOf(): boolean {
const lookahead = this.lookahead();
if (lookahead.type === tt._of && lookahead.end - lookahead.start === 2) {
// using of ...
const originalState = this.state;
// @ts-expect-error: Second lookahead
this.state = lookahead;
const lookaheadAhead = this.lookahead();
this.state = originalState;
if (
lookaheadAhead.type === tt._of &&
lookaheadAhead.end - lookaheadAhead.start === 2
) {
// using of of ...
const nextNextNextTokenStart = this.nextTokenStartSince(
lookaheadAhead.end,
);
if (
this.input.charCodeAt(nextNextNextTokenStart) ===
charCodes.rightParenthesis
) {
// using of of)
return false;
} else {
this.expectPlugin("explicitResourceManagement");
return true;
}
} else {
return false;
}
// `using of` must start a for-lhs-of statement
return false;
} else {
this.expectPlugin("explicitResourceManagement");
return true;
Expand Down
@@ -0,0 +1,4 @@
{
"sourceType": "module",
"throws": "Unexpected token, expected \")\" (1:23)"
}
@@ -0,0 +1,3 @@
{
"throws": "Unexpected token, expected \")\" (1:17)"
}
@@ -0,0 +1 @@
for await (using \u006ff of of);
@@ -0,0 +1,44 @@
{
"type": "File",
"start":0,"end":32,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":32,"index":32}},
"program": {
"type": "Program",
"start":0,"end":32,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":32,"index":32}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ForOfStatement",
"start":0,"end":32,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":32,"index":32}},
"await": true,
"left": {
"type": "VariableDeclaration",
"start":11,"end":24,"loc":{"start":{"line":1,"column":11,"index":11},"end":{"line":1,"column":24,"index":24}},
"declarations": [
{
"type": "VariableDeclarator",
"start":17,"end":24,"loc":{"start":{"line":1,"column":17,"index":17},"end":{"line":1,"column":24,"index":24}},
"id": {
"type": "Identifier",
"start":17,"end":24,"loc":{"start":{"line":1,"column":17,"index":17},"end":{"line":1,"column":24,"index":24},"identifierName":"of"},
"name": "of"
},
"init": null
}
],
"kind": "using"
},
"right": {
"type": "Identifier",
"start":28,"end":30,"loc":{"start":{"line":1,"column":28,"index":28},"end":{"line":1,"column":30,"index":30},"identifierName":"of"},
"name": "of"
},
"body": {
"type": "EmptyStatement",
"start":31,"end":32,"loc":{"start":{"line":1,"column":31,"index":31},"end":{"line":1,"column":32,"index":32}}
}
}
],
"directives": []
}
}

This file was deleted.

@@ -0,0 +1 @@
for (using o\u0066 of of);
@@ -0,0 +1,44 @@
{
"type": "File",
"start":0,"end":26,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":26,"index":26}},
"program": {
"type": "Program",
"start":0,"end":26,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":26,"index":26}},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ForOfStatement",
"start":0,"end":26,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":26,"index":26}},
"await": false,
"left": {
"type": "VariableDeclaration",
"start":5,"end":18,"loc":{"start":{"line":1,"column":5,"index":5},"end":{"line":1,"column":18,"index":18}},
"declarations": [
{
"type": "VariableDeclarator",
"start":11,"end":18,"loc":{"start":{"line":1,"column":11,"index":11},"end":{"line":1,"column":18,"index":18}},
"id": {
"type": "Identifier",
"start":11,"end":18,"loc":{"start":{"line":1,"column":11,"index":11},"end":{"line":1,"column":18,"index":18},"identifierName":"of"},
"name": "of"
},
"init": null
}
],
"kind": "using"
},
"right": {
"type": "Identifier",
"start":22,"end":24,"loc":{"start":{"line":1,"column":22,"index":22},"end":{"line":1,"column":24,"index":24},"identifierName":"of"},
"name": "of"
},
"body": {
"type": "EmptyStatement",
"start":25,"end":26,"loc":{"start":{"line":1,"column":25,"index":25},"end":{"line":1,"column":26,"index":26}}
}
}
],
"directives": []
}
}

This file was deleted.

0 comments on commit 6cd106e

Please sign in to comment.