Skip to content

Commit d42b2b7

Browse files
Try just the fetching change in checker.
1 parent 083db3a commit d42b2b7

15 files changed

+174
-152
lines changed

src/compiler/binder.ts

+10-9
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace ts {
1515
referenced: boolean;
1616
}
1717

18-
export function getModuleInstanceState(node: ModuleDeclaration, visited?: ESMap<Node, ModuleInstanceState | undefined>): ModuleInstanceState {
18+
export function getModuleInstanceState(node: ModuleDeclaration, visited?: ESMap<number, ModuleInstanceState | undefined>): ModuleInstanceState {
1919
if (node.body && !node.body.parent) {
2020
// getModuleInstanceStateForAliasTarget needs to walk up the parent chain, so parent pointers must be set on this tree already
2121
setParent(node.body, node);
@@ -24,17 +24,18 @@ namespace ts {
2424
return node.body ? getModuleInstanceStateCached(node.body, visited) : ModuleInstanceState.Instantiated;
2525
}
2626

27-
function getModuleInstanceStateCached(node: Node, visited = new Map<Node, ModuleInstanceState | undefined>()) {
28-
if (visited.has(node)) {
29-
return visited.get(node) || ModuleInstanceState.NonInstantiated;
27+
function getModuleInstanceStateCached(node: Node, visited = new Map<number, ModuleInstanceState | undefined>()) {
28+
const nodeId = getNodeId(node);
29+
if (visited.has(nodeId)) {
30+
return visited.get(nodeId) || ModuleInstanceState.NonInstantiated;
3031
}
31-
visited.set(node, undefined);
32+
visited.set(nodeId, undefined);
3233
const result = getModuleInstanceStateWorker(node, visited);
33-
visited.set(node, result);
34+
visited.set(nodeId, result);
3435
return result;
3536
}
3637

37-
function getModuleInstanceStateWorker(node: Node, visited: ESMap<Node, ModuleInstanceState | undefined>): ModuleInstanceState {
38+
function getModuleInstanceStateWorker(node: Node, visited: ESMap<number, ModuleInstanceState | undefined>): ModuleInstanceState {
3839
// A module is uninstantiated if it contains only
3940
switch (node.kind) {
4041
// 1. interface declarations, type alias declarations
@@ -106,7 +107,7 @@ namespace ts {
106107
return ModuleInstanceState.Instantiated;
107108
}
108109

109-
function getModuleInstanceStateForAliasTarget(specifier: ExportSpecifier, visited: ESMap<Node, ModuleInstanceState | undefined>) {
110+
function getModuleInstanceStateForAliasTarget(specifier: ExportSpecifier, visited: ESMap<number, ModuleInstanceState | undefined>) {
110111
const name = specifier.propertyName || specifier.name;
111112
let p: Node | undefined = specifier.parent;
112113
while (p) {
@@ -2983,7 +2984,7 @@ namespace ts {
29832984

29842985
function addLateBoundAssignmentDeclarationToSymbol(node: BinaryExpression | DynamicNamedDeclaration, symbol: Symbol | undefined) {
29852986
if (symbol) {
2986-
(symbol.assignmentDeclarationMembers ||= new Set()).add(node);
2987+
(symbol.assignmentDeclarationMembers || (symbol.assignmentDeclarationMembers = new Map())).set(getNodeId(node), node);
29872988
}
29882989
}
29892990

src/compiler/checker.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -3887,9 +3887,10 @@ namespace ts {
38873887

38883888
function getAlternativeContainingModules(symbol: Symbol, enclosingDeclaration: Node): Symbol[] {
38893889
const containingFile = getSourceFileOfNode(enclosingDeclaration);
3890+
const id = getNodeId(containingFile);
38903891
const links = getSymbolLinks(symbol);
38913892
let results: Symbol[] | undefined;
3892-
if (links.extendedContainersByFile && (results = links.extendedContainersByFile.get(containingFile))) {
3893+
if (links.extendedContainersByFile && (results = links.extendedContainersByFile.get(id))) {
38933894
return results;
38943895
}
38953896
if (containingFile && containingFile.imports) {
@@ -3903,7 +3904,7 @@ namespace ts {
39033904
results = append(results, resolvedModule);
39043905
}
39053906
if (length(results)) {
3906-
(links.extendedContainersByFile ||= new Map()).set(containingFile, results!);
3907+
(links.extendedContainersByFile || (links.extendedContainersByFile = new Map())).set(id, results!);
39073908
return results!;
39083909
}
39093910
}
@@ -33795,7 +33796,7 @@ namespace ts {
3379533796
const type = checkExpression(node);
3379633797
// If control flow analysis was required to determine the type, it is worth caching.
3379733798
if (flowInvocationCount !== startInvocationCount) {
33798-
const cache = (flowTypeCache ||= []);
33799+
const cache = flowTypeCache || (flowTypeCache = []);
3379933800
cache[getNodeId(node)] = type;
3380033801
setNodeFlags(node, node.flags | NodeFlags.TypeCached);
3380133802
}
@@ -40317,8 +40318,9 @@ namespace ts {
4031740318
const enclosingFile = getSourceFileOfNode(node);
4031840319
const links = getNodeLinks(enclosingFile);
4031940320
if (!(links.flags & NodeCheckFlags.TypeChecked)) {
40320-
links.deferredNodes ||= new Set();
40321-
links.deferredNodes.add(node);
40321+
links.deferredNodes = links.deferredNodes || new Map();
40322+
const id = getNodeId(node);
40323+
links.deferredNodes.set(id, node);
4032240324
}
4032340325
}
4032440326

src/compiler/emitter.ts

+4-7
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ namespace ts {
869869
const bundledHelpers = new Map<string, boolean>();
870870

871871
let currentSourceFile: SourceFile | undefined;
872-
let nodeToGeneratedName: ESMap<Node, string>; // Map of generated names for specific nodes.
872+
let nodeIdToGeneratedName: string[]; // Map of generated names for specific nodes.
873873
let autoGeneratedIdToGeneratedName: string[]; // Map of generated names for temp and loop variables.
874874
let generatedNames: Set<string>; // Set of names generated by the NameGenerator.
875875
let tempFlagsStack: TempFlags[]; // Stack of enclosing name generation scopes.
@@ -1154,7 +1154,7 @@ namespace ts {
11541154
}
11551155

11561156
function reset() {
1157-
nodeToGeneratedName = new Map<Node, string>();
1157+
nodeIdToGeneratedName = [];
11581158
autoGeneratedIdToGeneratedName = [];
11591159
generatedNames = new Set();
11601160
tempFlagsStack = [];
@@ -5008,11 +5008,8 @@ namespace ts {
50085008
}
50095009

50105010
function generateNameCached(node: Node, flags?: GeneratedIdentifierFlags) {
5011-
let result = nodeToGeneratedName.get(node);
5012-
if (result === undefined) {
5013-
nodeToGeneratedName.set(node, result = generateNameForNode(node, flags));
5014-
}
5015-
return result;
5011+
const nodeId = getNodeId(node);
5012+
return nodeIdToGeneratedName[nodeId] || (nodeIdToGeneratedName[nodeId] = generateNameForNode(node, flags));
50165013
}
50175014

50185015
/**

src/compiler/factory/nodeFactory.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5339,7 +5339,7 @@ namespace ts {
53395339
}
53405340

53415341
function flattenCommaElements(node: Expression): Expression | readonly Expression[] {
5342-
if (nodeIsSynthesized(node) && !isParseTreeNode(node) && !node.original && !node.emitNode) {
5342+
if (nodeIsSynthesized(node) && !isParseTreeNode(node) && !node.original && !node.emitNode && !node.id) {
53435343
if (isCommaListExpression(node)) {
53445344
return node.elements;
53455345
}

src/compiler/transformers/classFields.ts

+19-17
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ namespace ts {
147147

148148
let enabledSubstitutions: ClassPropertySubstitutionFlags;
149149

150-
let classAliases: ESMap<Node, Identifier>;
150+
let classAliases: Identifier[];
151151

152152
/**
153153
* Tracks what computed name expressions originating from elided names must be inlined
@@ -162,7 +162,7 @@ namespace ts {
162162
let pendingStatements: Statement[] | undefined;
163163

164164
const classLexicalEnvironmentStack: (ClassLexicalEnvironment | undefined)[] = [];
165-
const classLexicalEnvironmentMap = new WeakMap<Node, ClassLexicalEnvironment>();
165+
const classLexicalEnvironmentMap = new Map<number, ClassLexicalEnvironment>();
166166
let currentClassLexicalEnvironment: ClassLexicalEnvironment | undefined;
167167
let currentComputedPropertyNameClassLexicalEnvironment: ClassLexicalEnvironment | undefined;
168168
let currentStaticPropertyDeclarationOrStaticBlock: PropertyDeclaration | ClassStaticBlockDeclaration | undefined;
@@ -738,7 +738,7 @@ namespace ts {
738738
function transformClassStaticBlockDeclaration(node: ClassStaticBlockDeclaration) {
739739
if (shouldTransformPrivateElementsOrClassStaticBlocks) {
740740
if (currentClassLexicalEnvironment) {
741-
classLexicalEnvironmentMap.set(getOriginalNode(node), currentClassLexicalEnvironment);
741+
classLexicalEnvironmentMap.set(getOriginalNodeId(node), currentClassLexicalEnvironment);
742742
}
743743

744744
startLexicalEnvironment();
@@ -1128,7 +1128,7 @@ namespace ts {
11281128
enableSubstitutionForClassAliases();
11291129
const alias = factory.cloneNode(temp) as GeneratedIdentifier;
11301130
alias.autoGenerateFlags &= ~GeneratedIdentifierFlags.ReservedInNestedScopes;
1131-
classAliases.set(getOriginalNode(node), alias);
1131+
classAliases[getOriginalNodeId(node)] = alias;
11321132
}
11331133

11341134
// To preserve the behavior of the old emitter, we explicitly indent
@@ -1375,7 +1375,7 @@ namespace ts {
13751375
// capture the lexical environment for the member
13761376
setOriginalNode(transformed, property);
13771377
addEmitFlags(transformed, EmitFlags.AdviseOnEmitNode);
1378-
classLexicalEnvironmentMap.set(getOriginalNode(transformed), currentClassLexicalEnvironment);
1378+
classLexicalEnvironmentMap.set(getOriginalNodeId(transformed), currentClassLexicalEnvironment);
13791379
}
13801380
currentStaticPropertyDeclarationOrStaticBlock = savedCurrentStaticPropertyDeclarationOrStaticBlock;
13811381
return transformed;
@@ -1453,7 +1453,7 @@ namespace ts {
14531453
context.enableSubstitution(SyntaxKind.Identifier);
14541454

14551455
// Keep track of class aliases.
1456-
classAliases = new Map<Node, Identifier>();
1456+
classAliases = [];
14571457
}
14581458
}
14591459

@@ -1516,16 +1516,18 @@ namespace ts {
15161516

15171517
function onEmitNode(hint: EmitHint, node: Node, emitCallback: (hint: EmitHint, node: Node) => void) {
15181518
const original = getOriginalNode(node);
1519-
const classLexicalEnvironment = classLexicalEnvironmentMap.get(original);
1520-
if (classLexicalEnvironment) {
1521-
const savedClassLexicalEnvironment = currentClassLexicalEnvironment;
1522-
const savedCurrentComputedPropertyNameClassLexicalEnvironment = currentComputedPropertyNameClassLexicalEnvironment;
1523-
currentClassLexicalEnvironment = classLexicalEnvironment;
1524-
currentComputedPropertyNameClassLexicalEnvironment = classLexicalEnvironment;
1525-
previousOnEmitNode(hint, node, emitCallback);
1526-
currentClassLexicalEnvironment = savedClassLexicalEnvironment;
1527-
currentComputedPropertyNameClassLexicalEnvironment = savedCurrentComputedPropertyNameClassLexicalEnvironment;
1528-
return;
1519+
if (original.id) {
1520+
const classLexicalEnvironment = classLexicalEnvironmentMap.get(original.id);
1521+
if (classLexicalEnvironment) {
1522+
const savedClassLexicalEnvironment = currentClassLexicalEnvironment;
1523+
const savedCurrentComputedPropertyNameClassLexicalEnvironment = currentComputedPropertyNameClassLexicalEnvironment;
1524+
currentClassLexicalEnvironment = classLexicalEnvironment;
1525+
currentComputedPropertyNameClassLexicalEnvironment = classLexicalEnvironment;
1526+
previousOnEmitNode(hint, node, emitCallback);
1527+
currentClassLexicalEnvironment = savedClassLexicalEnvironment;
1528+
currentComputedPropertyNameClassLexicalEnvironment = savedCurrentComputedPropertyNameClassLexicalEnvironment;
1529+
return;
1530+
}
15291531
}
15301532

15311533
switch (node.kind) {
@@ -1631,7 +1633,7 @@ namespace ts {
16311633
// constructor references in static property initializers.
16321634
const declaration = resolver.getReferencedValueDeclaration(node);
16331635
if (declaration) {
1634-
const classAlias = classAliases.get(declaration);
1636+
const classAlias = classAliases[declaration.id!]; // TODO: GH#18217
16351637
if (classAlias) {
16361638
const clone = factory.cloneNode(classAlias);
16371639
setSourceMapRange(clone, node);

src/compiler/transformers/declarations.ts

+14-14
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ namespace ts {
6060
let enclosingDeclaration: Node;
6161
let necessaryTypeReferences: Set<string> | undefined;
6262
let lateMarkedStatements: LateVisibilityPaintedStatement[] | undefined;
63-
let lateStatementReplacementMap: ESMap<Node, VisitResult<LateVisibilityPaintedStatement | ExportAssignment>>;
63+
let lateStatementReplacementMap: ESMap<NodeId, VisitResult<LateVisibilityPaintedStatement | ExportAssignment>>;
6464
let suppressNewDiagnosticContexts: boolean;
6565
let exportedModulesFromDeclarationEmit: Symbol[] | undefined;
6666

@@ -84,7 +84,7 @@ namespace ts {
8484
let errorFallbackNode: Declaration | undefined;
8585

8686
let currentSourceFile: SourceFile;
87-
let refs: ESMap<Node, SourceFile>;
87+
let refs: ESMap<NodeId, SourceFile>;
8888
let libs: ESMap<string, boolean>;
8989
let emittedImports: readonly AnyImportSyntax[] | undefined; // must be declared in container so it can be `undefined` while transformer's first pass
9090
const resolver = context.getEmitResolver();
@@ -110,7 +110,7 @@ namespace ts {
110110
}
111111
// Otherwise we should emit a path-based reference
112112
const container = getSourceFileOfNode(node);
113-
refs.set(getOriginalNode(container), container);
113+
refs.set(getOriginalNodeId(container), container);
114114
}
115115

116116
function handleSymbolAccessibilityError(symbolAccessibilityResult: SymbolAccessibilityResult) {
@@ -426,12 +426,12 @@ namespace ts {
426426
}
427427
}
428428

429-
function collectReferences(sourceFile: SourceFile | UnparsedSource, ret: ESMap<Node, SourceFile>) {
429+
function collectReferences(sourceFile: SourceFile | UnparsedSource, ret: ESMap<NodeId, SourceFile>) {
430430
if (noResolve || (!isUnparsedSource(sourceFile) && isSourceFileJS(sourceFile))) return ret;
431431
forEach(sourceFile.referencedFiles, f => {
432432
const elem = host.getSourceFileFromReference(sourceFile, f);
433433
if (elem) {
434-
ret.set(getOriginalNode(elem), elem);
434+
ret.set(getOriginalNodeId(elem), elem);
435435
}
436436
});
437437
return ret;
@@ -812,7 +812,7 @@ namespace ts {
812812
needsDeclare = i.parent && isSourceFile(i.parent) && !(isExternalModule(i.parent) && isBundledEmit);
813813
const result = transformTopLevelDeclaration(i);
814814
needsDeclare = priorNeedsDeclare;
815-
lateStatementReplacementMap.set(getOriginalNode(i), result);
815+
lateStatementReplacementMap.set(getOriginalNodeId(i), result);
816816
}
817817

818818
// And lastly, we need to get the final form of all those indetermine import declarations from before and add them to the output list
@@ -821,10 +821,10 @@ namespace ts {
821821

822822
function visitLateVisibilityMarkedStatements(statement: Statement) {
823823
if (isLateVisibilityPaintedStatement(statement)) {
824-
const originalNode = getOriginalNode(statement);
825-
if (lateStatementReplacementMap.has(originalNode)) {
826-
const result = lateStatementReplacementMap.get(originalNode);
827-
lateStatementReplacementMap.delete(originalNode);
824+
const key = getOriginalNodeId(statement);
825+
if (lateStatementReplacementMap.has(key)) {
826+
const result = lateStatementReplacementMap.get(key);
827+
lateStatementReplacementMap.delete(key);
828828
if (result) {
829829
if (isArray(result) ? some(result, needsScopeMarker) : needsScopeMarker(result)) {
830830
// Top-level declarations in .d.ts files are always considered exported even without a modifier unless there's an export assignment or specifier
@@ -1146,7 +1146,7 @@ namespace ts {
11461146

11471147
const result = transformTopLevelDeclaration(input);
11481148
// Don't actually transform yet; just leave as original node - will be elided/swapped by late pass
1149-
lateStatementReplacementMap.set(getOriginalNode(input), result);
1149+
lateStatementReplacementMap.set(getOriginalNodeId(input), result);
11501150
return input;
11511151
}
11521152

@@ -1348,9 +1348,9 @@ namespace ts {
13481348
needsDeclare = false;
13491349
visitNode(inner, visitDeclarationStatements);
13501350
// eagerly transform nested namespaces (the nesting doesn't need any elision or painting done)
1351-
const originalNode = getOriginalNode(inner!); // TODO: GH#18217
1352-
const body = lateStatementReplacementMap.get(originalNode);
1353-
lateStatementReplacementMap.delete(originalNode);
1351+
const id = getOriginalNodeId(inner!); // TODO: GH#18217
1352+
const body = lateStatementReplacementMap.get(id);
1353+
lateStatementReplacementMap.delete(id);
13541354
return cleanup(factory.updateModuleDeclaration(
13551355
input,
13561356
/*decorators*/ undefined,

src/compiler/transformers/es2017.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ namespace ts {
4646
/** Whether the async function contains an element access on super (`super[x]`). */
4747
let hasSuperElementAccess: boolean;
4848
/** A set of node IDs for generated super accessors (variable statements). */
49-
const substitutedSuperAccessors = new Set<Node>();
49+
const substitutedSuperAccessors: boolean[] = [];
5050

5151
let contextFlags: ContextFlags = 0;
5252

@@ -503,7 +503,7 @@ namespace ts {
503503
enableSubstitutionForAsyncMethodsWithSuper();
504504
if (capturedSuperProperties.size) {
505505
const variableStatement = createSuperAccessVariableStatement(factory, resolver, node, capturedSuperProperties);
506-
substitutedSuperAccessors.add(variableStatement);
506+
substitutedSuperAccessors[getNodeId(variableStatement)] = true;
507507
insertStatementsAfterStandardPrologue(statements, [variableStatement]);
508508
}
509509
}
@@ -613,7 +613,7 @@ namespace ts {
613613
}
614614
}
615615
// Disable substitution in the generated super accessor itself.
616-
else if (enabledSubstitutions && substitutedSuperAccessors.has(node)) {
616+
else if (enabledSubstitutions && substitutedSuperAccessors[getNodeId(node)]) {
617617
const savedEnclosingSuperContainerFlags = enclosingSuperContainerFlags;
618618
enclosingSuperContainerFlags = 0;
619619
previousOnEmitNode(hint, node, emitCallback);

0 commit comments

Comments
 (0)