Expose 'reservedInNestedScopes' option when creating temp and loop variables (#43083)

This commit is contained in:
Ron Buckton
2021-03-04 15:37:45 -08:00
committed by GitHub
parent e234f0c094
commit 38fdce9440
4 changed files with 60 additions and 21 deletions

View File

@@ -883,8 +883,10 @@ namespace ts {
/** Create a unique temporary variable for use in a loop. */
// @api
function createLoopVariable(): Identifier {
return createBaseGeneratedIdentifier("", GeneratedIdentifierFlags.Loop);
function createLoopVariable(reservedInNestedScopes?: boolean): Identifier {
let flags = GeneratedIdentifierFlags.Loop;
if (reservedInNestedScopes) flags |= GeneratedIdentifierFlags.ReservedInNestedScopes;
return createBaseGeneratedIdentifier("", flags);
}
/** Create a unique name based on the supplied text. */

View File

@@ -6785,19 +6785,30 @@ namespace ts {
/* @internal */ createIdentifier(text: string, typeArguments?: readonly (TypeNode | TypeParameterDeclaration)[], originalKeywordKind?: SyntaxKind): Identifier; // eslint-disable-line @typescript-eslint/unified-signatures
/* @internal */ updateIdentifier(node: Identifier, typeArguments: NodeArray<TypeNode | TypeParameterDeclaration> | undefined): Identifier;
/** Create a unique temporary variable. */
createTempVariable(recordTempVariable: ((node: Identifier) => void) | undefined): Identifier;
/* @internal */ createTempVariable(recordTempVariable: ((node: Identifier) => void) | undefined, reservedInNestedScopes?: boolean): Identifier; // eslint-disable-line @typescript-eslint/unified-signatures
/**
* Create a unique temporary variable.
* @param recordTempVariable An optional callback used to record the temporary variable name. This
* should usually be a reference to `hoistVariableDeclaration` from a `TransformationContext`, but
* can be `undefined` if you plan to record the temporary variable manually.
* @param reservedInNestedScopes When `true`, reserves the temporary variable name in all nested scopes
* during emit so that the variable can be referenced in a nested function body. This is an alternative to
* setting `EmitFlags.ReuseTempVariableScope` on the nested function itself.
*/
createTempVariable(recordTempVariable: ((node: Identifier) => void) | undefined, reservedInNestedScopes?: boolean): Identifier;
/** Create a unique temporary variable for use in a loop. */
createLoopVariable(): Identifier;
/**
* Create a unique temporary variable for use in a loop.
* @param reservedInNestedScopes When `true`, reserves the temporary variable name in all nested scopes
* during emit so that the variable can be referenced in a nested function body. This is an alternative to
* setting `EmitFlags.ReuseTempVariableScope` on the nested function itself.
*/
createLoopVariable(reservedInNestedScopes?: boolean): Identifier;
/** Create a unique name based on the supplied text. */
createUniqueName(text: string, flags?: GeneratedIdentifierFlags): Identifier;
/** Create a unique name generated for a node. */
getGeneratedNameForNode(node: Node | undefined): Identifier;
/* @internal */ getGeneratedNameForNode(node: Node | undefined, flags?: GeneratedIdentifierFlags): Identifier; // eslint-disable-line @typescript-eslint/unified-signatures
getGeneratedNameForNode(node: Node | undefined, flags?: GeneratedIdentifierFlags): Identifier;
createPrivateIdentifier(text: string): PrivateIdentifier