From 2663fe71d74e104eee1b408457a3254c18bddf0e Mon Sep 17 00:00:00 2001 From: TypeScript Bot Date: Fri, 1 Aug 2025 23:21:34 +0000 Subject: [PATCH] Update Baselines, Applied Lint Fixes, and/or Formatted --- src/compiler/transformers/esnext.ts | 250 ++++++++++++++-------------- 1 file changed, 125 insertions(+), 125 deletions(-) diff --git a/src/compiler/transformers/esnext.ts b/src/compiler/transformers/esnext.ts index 82f2e28afa3..48647b491f5 100644 --- a/src/compiler/transformers/esnext.ts +++ b/src/compiler/transformers/esnext.ts @@ -1,67 +1,67 @@ -import { - addEmitHelpers, - addRange, - append, - arrayFrom, - BindingElement, - Block, - Bundle, - CaseOrDefaultClause, - chainBundle, - ClassDeclaration, - Debug, - EmitFlags, - ExportAssignment, - ExportSpecifier, - Expression, - firstOrUndefined, - ForOfStatement, - ForStatement, - GeneratedIdentifierFlags, - getEmitFlags, - hasSyntacticModifier, - Identifier, - IdentifierNameMap, - isArray, - isBindingPattern, - isBlock, - isCaseClause, - isCustomPrologue, - isExpression, - isGeneratedIdentifier, - isIdentifier, - isLocalName, - isNamedEvaluation, - isOmittedExpression, - isPrologueDirective, - isSourceFile, - isStatement, - isVariableDeclarationList, - isVariableStatement, - ModifierFlags, - Node, - NodeFlags, - setCommentRange, - setEmitFlags, - setOriginalNode, - setSourceMapRange, - setTextRange, - skipOuterExpressions, - SourceFile, - Statement, - SwitchStatement, - SyntaxKind, - TransformationContext, - TransformFlags, - transformNamedEvaluation, - VariableDeclaration, - VariableDeclarationList, - VariableStatement, - visitArray, - visitEachChild, - visitNode, - visitNodes, - VisitResult, +import { + addEmitHelpers, + addRange, + append, + arrayFrom, + BindingElement, + Block, + Bundle, + CaseOrDefaultClause, + chainBundle, + ClassDeclaration, + Debug, + EmitFlags, + ExportAssignment, + ExportSpecifier, + Expression, + firstOrUndefined, + ForOfStatement, + ForStatement, + GeneratedIdentifierFlags, + getEmitFlags, + hasSyntacticModifier, + Identifier, + IdentifierNameMap, + isArray, + isBindingPattern, + isBlock, + isCaseClause, + isCustomPrologue, + isExpression, + isGeneratedIdentifier, + isIdentifier, + isLocalName, + isNamedEvaluation, + isOmittedExpression, + isPrologueDirective, + isSourceFile, + isStatement, + isVariableDeclarationList, + isVariableStatement, + ModifierFlags, + Node, + NodeFlags, + setCommentRange, + setEmitFlags, + setOriginalNode, + setSourceMapRange, + setTextRange, + skipOuterExpressions, + SourceFile, + Statement, + SwitchStatement, + SyntaxKind, + TransformationContext, + TransformFlags, + transformNamedEvaluation, + VariableDeclaration, + VariableDeclarationList, + VariableStatement, + visitArray, + visitEachChild, + visitNode, + visitNodes, + VisitResult, } from "../_namespaces/ts.js"; const enum UsingKind { @@ -289,67 +289,67 @@ export function transformESNext(context: TransformationContext): (x: SourceFile ); } - return visitEachChild(node, visitor, context); - } - - function visitForOfStatement(node: ForOfStatement) { - if (isUsingVariableDeclarationList(node.initializer)) { - // given: - // - // for (using x of y) { ... } - // - // produces a shallow transformation to: - // - // for (const x_1 of y) { - // using x = x_1; - // { ... } - // } - // - // where the original loop body is wrapped in an additional block scope - // to handle shadowing variables naturally through block scoping. - const forInitializer = node.initializer; - const forDecl = firstOrUndefined(forInitializer.declarations) || factory.createVariableDeclaration(factory.createTempVariable(/*recordTempVariable*/ undefined)); - - const isAwaitUsing = getUsingKindOfVariableDeclarationList(forInitializer) === UsingKind.Async; - const temp = factory.getGeneratedNameForNode(forDecl.name); - const usingVar = factory.updateVariableDeclaration(forDecl, forDecl.name, /*exclamationToken*/ undefined, /*type*/ undefined, temp); - const usingVarList = factory.createVariableDeclarationList([usingVar], isAwaitUsing ? NodeFlags.AwaitUsing : NodeFlags.Using); - const usingVarStatement = factory.createVariableStatement(/*modifiers*/ undefined, usingVarList); - - // Wrap the original loop body in an additional block scope to handle shadowing - // Don't create an extra block if the original statement is empty or contains only empty statements - const isEmptyBlock = isBlock(node.statement) && ( - node.statement.statements.length === 0 || - node.statement.statements.every(stmt => stmt.kind === SyntaxKind.EmptyStatement) - ); - const shouldWrapInBlock = !isEmptyBlock; - - const statements: Statement[] = [usingVarStatement]; - if (shouldWrapInBlock) { - const wrappedStatement = isBlock(node.statement) ? - node.statement : - factory.createBlock([node.statement], /*multiLine*/ true); - statements.push(wrappedStatement); - } - else { - statements.push(...(isBlock(node.statement) ? node.statement.statements : [node.statement])) - } - - return visitNode( - factory.updateForOfStatement( - node, - node.awaitModifier, - factory.createVariableDeclarationList([ - factory.createVariableDeclaration(temp), - ], NodeFlags.Const), - node.expression, - factory.createBlock(statements, /*multiLine*/ true), - ), - visitor, - isStatement, - ); - } - return visitEachChild(node, visitor, context); + return visitEachChild(node, visitor, context); + } + + function visitForOfStatement(node: ForOfStatement) { + if (isUsingVariableDeclarationList(node.initializer)) { + // given: + // + // for (using x of y) { ... } + // + // produces a shallow transformation to: + // + // for (const x_1 of y) { + // using x = x_1; + // { ... } + // } + // + // where the original loop body is wrapped in an additional block scope + // to handle shadowing variables naturally through block scoping. + const forInitializer = node.initializer; + const forDecl = firstOrUndefined(forInitializer.declarations) || factory.createVariableDeclaration(factory.createTempVariable(/*recordTempVariable*/ undefined)); + + const isAwaitUsing = getUsingKindOfVariableDeclarationList(forInitializer) === UsingKind.Async; + const temp = factory.getGeneratedNameForNode(forDecl.name); + const usingVar = factory.updateVariableDeclaration(forDecl, forDecl.name, /*exclamationToken*/ undefined, /*type*/ undefined, temp); + const usingVarList = factory.createVariableDeclarationList([usingVar], isAwaitUsing ? NodeFlags.AwaitUsing : NodeFlags.Using); + const usingVarStatement = factory.createVariableStatement(/*modifiers*/ undefined, usingVarList); + + // Wrap the original loop body in an additional block scope to handle shadowing + // Don't create an extra block if the original statement is empty or contains only empty statements + const isEmptyBlock = isBlock(node.statement) && ( + node.statement.statements.length === 0 || + node.statement.statements.every(stmt => stmt.kind === SyntaxKind.EmptyStatement) + ); + const shouldWrapInBlock = !isEmptyBlock; + + const statements: Statement[] = [usingVarStatement]; + if (shouldWrapInBlock) { + const wrappedStatement = isBlock(node.statement) ? + node.statement : + factory.createBlock([node.statement], /*multiLine*/ true); + statements.push(wrappedStatement); + } + else { + statements.push(...(isBlock(node.statement) ? node.statement.statements : [node.statement])); + } + + return visitNode( + factory.updateForOfStatement( + node, + node.awaitModifier, + factory.createVariableDeclarationList([ + factory.createVariableDeclaration(temp), + ], NodeFlags.Const), + node.expression, + factory.createBlock(statements, /*multiLine*/ true), + ), + visitor, + isStatement, + ); + } + return visitEachChild(node, visitor, context); } function visitCaseOrDefaultClause(node: CaseOrDefaultClause, envBinding: Identifier) {