Skip to content

fix(typescript-estree): disallow using as the variable keyword for for..in loops #7649

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 12, 2024
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
for(using foo in {});

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions packages/typescript-estree/src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,7 @@ export class Converter {
});

case SyntaxKind.ForInStatement:
this.#checkForStatementDeclaration(node.initializer);
return this.createNode<TSESTree.ForInStatement>(node, {
type: AST_NODE_TYPES.ForInStatement,
left: this.convertPattern(node.initializer),
Expand Down Expand Up @@ -3510,4 +3511,14 @@ export class Converter {

throw createError(message, this.ast, start, end);
}
#checkForStatementDeclaration(initializer: ts.ForInitializer): void {
if (ts.isVariableDeclarationList(initializer)) {
if ((initializer.flags & ts.NodeFlags.Using) !== 0) {
this.#throwError(
initializer,
"The left-hand side of a 'for...in' statement cannot be a 'using' declaration.",
);
}
}
}
}
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy