Skip to content

Commit 107d090

Browse files
committed
Revert autoGenerate change
1 parent 85e5453 commit 107d090

File tree

10 files changed

+25
-34
lines changed

10 files changed

+25
-34
lines changed

src/compiler/emitter.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5681,7 +5681,7 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
56815681
* Generate the text for a generated identifier.
56825682
*/
56835683
function generateName(name: GeneratedIdentifier | GeneratedPrivateIdentifier) {
5684-
const autoGenerate = name.emitNode.autoGenerate;
5684+
const autoGenerate = name.autoGenerate;
56855685
if ((autoGenerate.flags & GeneratedIdentifierFlags.KindMask) === GeneratedIdentifierFlags.Node) {
56865686
// Node names generate unique names based on their original node
56875687
// and are cached based on that node's id.
@@ -5962,7 +5962,7 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
59625962
* Generates a unique identifier for a node.
59635963
*/
59645964
function makeName(name: GeneratedIdentifier | GeneratedPrivateIdentifier) {
5965-
const autoGenerate = name.emitNode.autoGenerate;
5965+
const autoGenerate = name.autoGenerate;
59665966
const prefix = formatGeneratedNamePart(autoGenerate.prefix, generateName);
59675967
const suffix = formatGeneratedNamePart(autoGenerate.suffix);
59685968
switch (autoGenerate.flags & GeneratedIdentifierFlags.KindMask) {

src/compiler/factory/emitNode.ts

-12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {
22
AccessExpression,
33
append,
44
appendIfUnique,
5-
AutoGenerateInfo,
65
Debug,
76
EmitFlags,
87
EmitHelper,
@@ -336,17 +335,6 @@ export function getIdentifierTypeArguments(node: Identifier): NodeArray<TypeNode
336335
return node.emitNode?.identifierTypeArguments;
337336
}
338337

339-
/** @internal */
340-
export function setIdentifierAutoGenerate<T extends Identifier | PrivateIdentifier>(node: T, autoGenerate: AutoGenerateInfo | undefined) {
341-
getOrCreateEmitNode(node).autoGenerate = autoGenerate;
342-
return node;
343-
}
344-
345-
/** @internal */
346-
export function getIdentifierAutoGenerate(node: Identifier | PrivateIdentifier): AutoGenerateInfo | undefined {
347-
return node.emitNode?.autoGenerate;
348-
}
349-
350338
/** @internal */
351339
export function setIdentifierGeneratedImportReference<T extends Identifier | PrivateIdentifier>(node: T, value: ImportSpecifier | undefined) {
352340
getOrCreateEmitNode(node).generatedImportReference = value;

src/compiler/factory/nodeFactory.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,6 @@ import {
391391
SetAccessorDeclaration,
392392
setEachParent,
393393
setEmitFlags,
394-
setIdentifierAutoGenerate,
395394
setIdentifierTypeArguments,
396395
setParent,
397396
setTextRange,
@@ -1155,6 +1154,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
11551154
function createBaseIdentifier(escapedText: __String) {
11561155
const node = baseFactory.createBaseIdentifierNode(SyntaxKind.Identifier) as Mutable<Identifier>;
11571156
node.escapedText = escapedText;
1157+
node.autoGenerate = undefined;
11581158
node.jsDoc = undefined; // initialized by parser (JsDocContainer)
11591159
node.flowNode = undefined; // initialized by binder (FlowContainer)
11601160
node.symbol = undefined!; // initialized by checker
@@ -1163,12 +1163,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
11631163

11641164
function createBaseGeneratedIdentifier(text: string, autoGenerateFlags: GeneratedIdentifierFlags, prefix: string | GeneratedNamePart | undefined, suffix: string | undefined) {
11651165
const node = createBaseIdentifier(escapeLeadingUnderscores(text)) as Mutable<GeneratedIdentifier>;
1166-
setIdentifierAutoGenerate(node, {
1166+
node.autoGenerate = {
11671167
flags: autoGenerateFlags,
11681168
id: nextAutoGenerateId,
11691169
prefix,
11701170
suffix
1171-
});
1171+
};
11721172
nextAutoGenerateId++;
11731173
return node;
11741174
}
@@ -1239,6 +1239,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
12391239
function createBasePrivateIdentifier(escapedText: __String) {
12401240
const node = baseFactory.createBasePrivateIdentifierNode(SyntaxKind.PrivateIdentifier) as Mutable<PrivateIdentifier>;
12411241
node.escapedText = escapedText;
1242+
node.autoGenerate = undefined;
12421243
node.transformFlags |= TransformFlags.ContainsClassFields;
12431244
return node;
12441245
}
@@ -1251,12 +1252,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
12511252

12521253
function createBaseGeneratedPrivateIdentifier(text: string, autoGenerateFlags: GeneratedIdentifierFlags, prefix: string | GeneratedNamePart | undefined, suffix: string | undefined) {
12531254
const node = createBasePrivateIdentifier(escapeLeadingUnderscores(text));
1254-
setIdentifierAutoGenerate(node, {
1255+
node.autoGenerate = {
12551256
flags: autoGenerateFlags,
12561257
id: nextAutoGenerateId,
12571258
prefix,
12581259
suffix,
1259-
});
1260+
};
12601261
nextAutoGenerateId++;
12611262
return node;
12621263
}
@@ -6303,9 +6304,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
63036304
function cloneGeneratedIdentifier(node: GeneratedIdentifier): GeneratedIdentifier {
63046305
const clone = createBaseIdentifier(node.escapedText) as Mutable<GeneratedIdentifier>;
63056306
clone.flags |= node.flags & ~NodeFlags.Synthesized;
6307+
clone.autoGenerate = { ...node.autoGenerate };
63066308
clone.transformFlags = node.transformFlags;
63076309
setOriginalNode(clone, node);
6308-
setIdentifierAutoGenerate(clone, { ...node.emitNode.autoGenerate });
63096310
return clone;
63106311
}
63116312

@@ -6327,9 +6328,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
63276328
function cloneGeneratedPrivateIdentifier(node: GeneratedPrivateIdentifier): GeneratedPrivateIdentifier {
63286329
const clone = createBasePrivateIdentifier(node.escapedText) as Mutable<GeneratedPrivateIdentifier>;
63296330
clone.flags |= node.flags & ~NodeFlags.Synthesized;
6331+
clone.autoGenerate = { ...node.autoGenerate };
63306332
clone.transformFlags = node.transformFlags;
63316333
setOriginalNode(clone, node);
6332-
setIdentifierAutoGenerate(clone, { ...node.emitNode.autoGenerate });
63336334
return clone;
63346335
}
63356336

src/compiler/factory/utilities.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -1489,19 +1489,18 @@ export function elideNodes<T extends Node>(factory: NodeFactory, nodes: NodeArra
14891489
* @internal
14901490
*/
14911491
export function getNodeForGeneratedName(name: GeneratedIdentifier | GeneratedPrivateIdentifier) {
1492-
const autoGenerate = name.emitNode.autoGenerate;
1492+
const autoGenerate = name.autoGenerate;
14931493
if (autoGenerate.flags & GeneratedIdentifierFlags.Node) {
14941494
const autoGenerateId = autoGenerate.id;
14951495
let node = name as Node;
14961496
let original = node.original;
14971497
while (original) {
14981498
node = original;
1499-
const autoGenerate = node.emitNode?.autoGenerate;
15001499
// if "node" is a different generated name (having a different "autoGenerateId"), use it and stop traversing.
15011500
if (isMemberName(node) && (
1502-
autoGenerate === undefined ||
1503-
!!(autoGenerate.flags & GeneratedIdentifierFlags.Node) &&
1504-
autoGenerate.id !== autoGenerateId)) {
1501+
node.autoGenerate === undefined ||
1502+
!!(node.autoGenerate.flags & GeneratedIdentifierFlags.Node) &&
1503+
node.autoGenerate.id !== autoGenerateId)) {
15051504
break;
15061505
}
15071506

src/compiler/transformers/classFields.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1553,7 +1553,7 @@ export function transformClassFields(context: TransformationContext): (x: Source
15531553
// record an alias as the class name is not in scope for statics.
15541554
enableSubstitutionForClassAliases();
15551555
const alias = factory.cloneNode(temp) as GeneratedIdentifier;
1556-
alias.emitNode.autoGenerate.flags &= ~GeneratedIdentifierFlags.ReservedInNestedScopes;
1556+
alias.autoGenerate.flags &= ~GeneratedIdentifierFlags.ReservedInNestedScopes;
15571557
classAliases[getOriginalNodeId(node)] = alias;
15581558
}
15591559

src/compiler/transformers/module/module.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2064,7 +2064,7 @@ export function transformModule(context: TransformationContext): (x: SourceFile
20642064
}
20652065
return node;
20662066
}
2067-
else if (!(isGeneratedIdentifier(node) && !(node.emitNode.autoGenerate.flags & GeneratedIdentifierFlags.AllowNameSubstitution)) && !isLocalName(node)) {
2067+
else if (!(isGeneratedIdentifier(node) && !(node.autoGenerate.flags & GeneratedIdentifierFlags.AllowNameSubstitution)) && !isLocalName(node)) {
20682068
const exportContainer = resolver.getReferencedExportContainer(node, isExportName(node));
20692069
if (exportContainer && exportContainer.kind === SyntaxKind.SourceFile) {
20702070
return setTextRange(

src/compiler/types.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1680,6 +1680,7 @@ export interface Identifier extends PrimaryExpression, Declaration, JSDocContain
16801680
* Text of identifier, but if the identifier begins with two underscores, this will begin with three.
16811681
*/
16821682
readonly escapedText: __String;
1683+
/** @internal */ readonly autoGenerate: AutoGenerateInfo | undefined; // Used for auto-generated identifiers and private identifiers.
16831684
}
16841685

16851686
// Transient identifier node (marked by id === -1)
@@ -1697,7 +1698,7 @@ export interface AutoGenerateInfo {
16971698

16981699
/** @internal */
16991700
export interface GeneratedIdentifier extends Identifier {
1700-
readonly emitNode: EmitNode & { autoGenerate: AutoGenerateInfo; };
1701+
readonly autoGenerate: AutoGenerateInfo;
17011702
}
17021703

17031704
export interface QualifiedName extends Node, FlowContainer {
@@ -1774,11 +1775,12 @@ export interface PrivateIdentifier extends PrimaryExpression {
17741775
// escaping not strictly necessary
17751776
// avoids gotchas in transforms and utils
17761777
readonly escapedText: __String;
1778+
/** @internal */ readonly autoGenerate: AutoGenerateInfo | undefined; // Used for auto-generated identifiers and private identifiers.
17771779
}
17781780

17791781
/** @internal */
17801782
export interface GeneratedPrivateIdentifier extends PrivateIdentifier {
1781-
readonly emitNode: EmitNode & { autoGenerate: AutoGenerateInfo };
1783+
readonly autoGenerate: AutoGenerateInfo;
17821784
}
17831785

17841786
/** @internal */
@@ -7822,7 +7824,6 @@ export interface EmitNode {
78227824
snippetElement?: SnippetElement; // Snippet element of the node
78237825
typeNode?: TypeNode; // VariableDeclaration type
78247826
identifierTypeArguments?: NodeArray<TypeNode | TypeParameterDeclaration>; // Only defined on synthesized identifiers. Though not syntactically valid, used in emitting diagnostics, quickinfo, and signature help.
7825-
autoGenerate: AutoGenerateInfo | undefined; // Used for auto-generated identifiers and private identifiers.
78267827
generatedImportReference?: ImportSpecifier; // Reference to the generated import specifier this identifier refers to
78277828
}
78287829

src/compiler/utilities.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1650,7 +1650,7 @@ export function tryGetTextOfPropertyName(name: PropertyName | NoSubstitutionTemp
16501650
switch (name.kind) {
16511651
case SyntaxKind.Identifier:
16521652
case SyntaxKind.PrivateIdentifier:
1653-
return name.emitNode?.autoGenerate ? undefined : name.escapedText;
1653+
return name.autoGenerate ? undefined : name.escapedText;
16541654
case SyntaxKind.StringLiteral:
16551655
case SyntaxKind.NumericLiteral:
16561656
case SyntaxKind.NoSubstitutionTemplateLiteral:

src/compiler/utilitiesPublic.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1490,12 +1490,12 @@ export function isStringTextContainingNode(node: Node): node is StringLiteral |
14901490

14911491
/** @internal */
14921492
export function isGeneratedIdentifier(node: Node): node is GeneratedIdentifier {
1493-
return isIdentifier(node) && node.emitNode?.autoGenerate !== undefined;
1493+
return isIdentifier(node) && node.autoGenerate !== undefined;
14941494
}
14951495

14961496
/** @internal */
14971497
export function isGeneratedPrivateIdentifier(node: Node): node is GeneratedPrivateIdentifier {
1498-
return isPrivateIdentifier(node) && node.emitNode?.autoGenerate !== undefined;
1498+
return isPrivateIdentifier(node) && node.autoGenerate !== undefined;
14991499
}
15001500

15011501
// Private Identifiers

src/services/services.ts

+2
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,7 @@ class TokenObject<TKind extends SyntaxKind> extends TokenOrIdentifierObject impl
733733
class IdentifierObject extends TokenOrIdentifierObject implements Identifier {
734734
public kind: SyntaxKind.Identifier = SyntaxKind.Identifier;
735735
public escapedText!: __String;
736+
declare autoGenerate: ts.AutoGenerateInfo | undefined;
736737
declare _primaryExpressionBrand: any;
737738
declare _memberExpressionBrand: any;
738739
declare _leftHandSideExpressionBrand: any;
@@ -755,6 +756,7 @@ IdentifierObject.prototype.kind = SyntaxKind.Identifier;
755756
class PrivateIdentifierObject extends TokenOrIdentifierObject implements PrivateIdentifier {
756757
public kind: SyntaxKind.PrivateIdentifier = SyntaxKind.PrivateIdentifier;
757758
public escapedText!: __String;
759+
declare autoGenerate: ts.AutoGenerateInfo | undefined;
758760
declare _primaryExpressionBrand: any;
759761
declare _memberExpressionBrand: any;
760762
declare _leftHandSideExpressionBrand: any;

0 commit comments

Comments
 (0)