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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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

View File

@ -3176,14 +3176,27 @@ declare namespace ts {
createStringLiteralFromNode(sourceNode: PropertyNameLiteral, isSingleQuote?: boolean): StringLiteral;
createRegularExpressionLiteral(text: string): RegularExpressionLiteral;
createIdentifier(text: string): Identifier;
/** Create a unique temporary variable. */
createTempVariable(recordTempVariable: ((node: Identifier) => void) | undefined): Identifier;
/** Create a unique temporary variable for use in a loop. */
createLoopVariable(): Identifier;
/**
* 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.
* @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;
getGeneratedNameForNode(node: Node | undefined, flags?: GeneratedIdentifierFlags): Identifier;
createPrivateIdentifier(text: string): PrivateIdentifier;
createToken(token: SyntaxKind.SuperKeyword): SuperExpression;
createToken(token: SyntaxKind.ThisKeyword): ThisExpression;
@ -10256,7 +10269,7 @@ declare namespace ts {
/** @deprecated Use `factory.createRegularExpressionLiteral` or the factory supplied by your transformation context instead. */
const createRegularExpressionLiteral: (text: string) => RegularExpressionLiteral;
/** @deprecated Use `factory.createLoopVariable` or the factory supplied by your transformation context instead. */
const createLoopVariable: () => Identifier;
const createLoopVariable: (reservedInNestedScopes?: boolean | undefined) => Identifier;
/** @deprecated Use `factory.createUniqueName` or the factory supplied by your transformation context instead. */
const createUniqueName: (text: string, flags?: GeneratedIdentifierFlags | undefined) => Identifier;
/** @deprecated Use `factory.createPrivateIdentifier` or the factory supplied by your transformation context instead. */

View File

@ -3176,14 +3176,27 @@ declare namespace ts {
createStringLiteralFromNode(sourceNode: PropertyNameLiteral, isSingleQuote?: boolean): StringLiteral;
createRegularExpressionLiteral(text: string): RegularExpressionLiteral;
createIdentifier(text: string): Identifier;
/** Create a unique temporary variable. */
createTempVariable(recordTempVariable: ((node: Identifier) => void) | undefined): Identifier;
/** Create a unique temporary variable for use in a loop. */
createLoopVariable(): Identifier;
/**
* 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.
* @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;
getGeneratedNameForNode(node: Node | undefined, flags?: GeneratedIdentifierFlags): Identifier;
createPrivateIdentifier(text: string): PrivateIdentifier;
createToken(token: SyntaxKind.SuperKeyword): SuperExpression;
createToken(token: SyntaxKind.ThisKeyword): ThisExpression;
@ -6513,7 +6526,7 @@ declare namespace ts {
/** @deprecated Use `factory.createRegularExpressionLiteral` or the factory supplied by your transformation context instead. */
const createRegularExpressionLiteral: (text: string) => RegularExpressionLiteral;
/** @deprecated Use `factory.createLoopVariable` or the factory supplied by your transformation context instead. */
const createLoopVariable: () => Identifier;
const createLoopVariable: (reservedInNestedScopes?: boolean | undefined) => Identifier;
/** @deprecated Use `factory.createUniqueName` or the factory supplied by your transformation context instead. */
const createUniqueName: (text: string, flags?: GeneratedIdentifierFlags | undefined) => Identifier;
/** @deprecated Use `factory.createPrivateIdentifier` or the factory supplied by your transformation context instead. */