@@ -277,15 +277,13 @@ namespace ts {
277
277
this.flags = 0;
278
278
}
279
279
280
- const idCache = new Map<Node, number>();
281
280
export function getNodeId(node: Node): number {
282
- let result = idCache.get(node);
283
- if (!result) {
284
- result = nextNodeId;
285
- idCache.set(node, result);
281
+ let id = node.id;
282
+ if (!id) {
283
+ node.id = id = nextNodeId;
286
284
nextNodeId++;
287
285
}
288
- return result ;
286
+ return id ;
289
287
}
290
288
291
289
export function getSymbolId(symbol: Symbol): SymbolId {
@@ -963,7 +961,7 @@ namespace ts {
963
961
let flowInvocationCount = 0;
964
962
let lastFlowNode: FlowNode | undefined;
965
963
let lastFlowNodeReachable: boolean;
966
- let flowTypeCache: ESMap<Node, Type> | undefined;
964
+ let flowTypeCache: Type[] | undefined;
967
965
968
966
const emptyStringType = getStringLiteralType("");
969
967
const zeroType = getNumberLiteralType(0);
@@ -977,7 +975,7 @@ namespace ts {
977
975
const maximumSuggestionCount = 10;
978
976
const mergedSymbols: Symbol[] = [];
979
977
const symbolLinks: SymbolLinks[] = [];
980
- const nodeLinks = new Map<Node, NodeLinks>() ;
978
+ const nodeLinks: NodeLinks[] = [] ;
981
979
const flowLoopCaches: ESMap<string, Type>[] = [];
982
980
const flowLoopNodes: FlowNode[] = [];
983
981
const flowLoopKeys: string[] = [];
@@ -1466,11 +1464,8 @@ namespace ts {
1466
1464
}
1467
1465
1468
1466
function getNodeLinks(node: Node): NodeLinks {
1469
- let result = nodeLinks.get(node);
1470
- if (!result) {
1471
- nodeLinks.set(node, result = new (NodeLinks as any)() as NodeLinks);
1472
- }
1473
- return result;
1467
+ const nodeId = getNodeId(node);
1468
+ return nodeLinks[nodeId] || (nodeLinks[nodeId] = new (NodeLinks as any)());
1474
1469
}
1475
1470
1476
1471
function isGlobalSourceFile(node: Node) {
@@ -33790,7 +33785,7 @@ namespace ts {
33790
33785
}
33791
33786
// If a type has been cached for the node, return it.
33792
33787
if (node.flags & NodeFlags.TypeCached && flowTypeCache) {
33793
- const cachedType = flowTypeCache.get (node);
33788
+ const cachedType = flowTypeCache[getNodeId (node)] ;
33794
33789
if (cachedType) {
33795
33790
return cachedType;
33796
33791
}
@@ -33799,8 +33794,8 @@ namespace ts {
33799
33794
const type = checkExpression(node);
33800
33795
// If control flow analysis was required to determine the type, it is worth caching.
33801
33796
if (flowInvocationCount !== startInvocationCount) {
33802
- const cache = (flowTypeCache ||= new Map<Node, Type>() );
33803
- cache.set (node, type) ;
33797
+ const cache = (flowTypeCache ||= [] );
33798
+ cache[getNodeId (node)] = type;
33804
33799
setNodeFlags(node, node.flags | NodeFlags.TypeCached);
33805
33800
}
33806
33801
return type;
@@ -41603,7 +41598,9 @@ namespace ts {
41603
41598
}
41604
41599
41605
41600
function getNodeCheckFlags(node: Node): NodeCheckFlags {
41606
- return nodeLinks.get(node)?.flags || 0;
41601
+ const nodeId = node.id || 0;
41602
+ if (nodeId < 0 || nodeId >= nodeLinks.length) return 0;
41603
+ return nodeLinks[nodeId]?.flags || 0;
41607
41604
}
41608
41605
41609
41606
function getEnumMemberValue(node: EnumMember): string | number | undefined {
0 commit comments