diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 67e3eb1f9a261..305852103def4 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -278,20 +278,22 @@ namespace ts { } export function getNodeId(node: Node): number { - if (!node.id) { - node.id = nextNodeId; + let id = node.id; + if (!id) { + node.id = id = nextNodeId; nextNodeId++; } - return node.id; + return id; } export function getSymbolId(symbol: Symbol): SymbolId { - if (!symbol.id) { - symbol.id = nextSymbolId; + let id = symbol.id; + if (!id) { + symbol.id = id = nextSymbolId; nextSymbolId++; } - return symbol.id; + return id; } export function isInstantiatedModule(node: ModuleDeclaration, preserveConstEnums: boolean) { @@ -3885,10 +3887,9 @@ namespace ts { function getAlternativeContainingModules(symbol: Symbol, enclosingDeclaration: Node): Symbol[] { const containingFile = getSourceFileOfNode(enclosingDeclaration); - const id = getNodeId(containingFile); const links = getSymbolLinks(symbol); let results: Symbol[] | undefined; - if (links.extendedContainersByFile && (results = links.extendedContainersByFile.get(id))) { + if (links.extendedContainersByFile && (results = links.extendedContainersByFile.get(containingFile))) { return results; } if (containingFile && containingFile.imports) { @@ -3902,7 +3903,7 @@ namespace ts { results = append(results, resolvedModule); } if (length(results)) { - (links.extendedContainersByFile || (links.extendedContainersByFile = new Map())).set(id, results!); + (links.extendedContainersByFile ||= new Map()).set(containingFile, results!); return results!; } } @@ -33794,7 +33795,7 @@ namespace ts { const type = checkExpression(node); // If control flow analysis was required to determine the type, it is worth caching. if (flowInvocationCount !== startInvocationCount) { - const cache = flowTypeCache || (flowTypeCache = []); + const cache = (flowTypeCache ||= []); cache[getNodeId(node)] = type; setNodeFlags(node, node.flags | NodeFlags.TypeCached); } @@ -40316,9 +40317,8 @@ namespace ts { const enclosingFile = getSourceFileOfNode(node); const links = getNodeLinks(enclosingFile); if (!(links.flags & NodeCheckFlags.TypeChecked)) { - links.deferredNodes = links.deferredNodes || new Map(); - const id = getNodeId(node); - links.deferredNodes.set(id, node); + links.deferredNodes ||= []; + links.deferredNodes[getNodeId(node)] = node; } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 9a32a79f37f78..6660f9849a92f 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -4900,7 +4900,7 @@ namespace ts { members?: SymbolTable; // Class, interface or object literal instance members exports?: SymbolTable; // Module exports globalExports?: SymbolTable; // Conditional global UMD exports - /* @internal */ id?: SymbolId; // Unique id (used to look up SymbolLinks) + /* @internal */ id: SymbolId; // Unique id (used to look up SymbolLinks) /* @internal */ mergeId?: number; // Merge id (used to look up merged symbol) /* @internal */ parent?: Symbol; // Parent symbol /* @internal */ exportSymbol?: Symbol; // Exported symbol associated with this symbol @@ -4946,7 +4946,7 @@ namespace ts { lateSymbol?: Symbol; // Late-bound symbol for a computed property specifierCache?: ESMap; // For symbols corresponding to external modules, a cache of incoming path -> module specifier name mappings extendedContainers?: Symbol[]; // Containers (other than the parent) which this symbol is aliased in - extendedContainersByFile?: ESMap; // Containers (other than the parent) which this symbol is aliased in + extendedContainersByFile?: ESMap; // Containers (other than the parent) which this symbol is aliased in variances?: VarianceFlags[]; // Alias symbol type argument variance cache deferralConstituents?: Type[]; // Calculated list of constituents for a deferred type deferralParent?: Type; // Source union/intersection of a deferred type @@ -5106,7 +5106,7 @@ namespace ts { jsxNamespace?: Symbol | false; // Resolved jsx namespace symbol for this node jsxImplicitImportContainer?: Symbol | false; // Resolved module symbol the implicit jsx import of this file should refer to contextFreeType?: Type; // Cached context-free type used by the first pass of inference; used when a function's return is partially contextually sensitive - deferredNodes?: ESMap; // Set of nodes whose checking has been deferred + deferredNodes?: Node[]; // Sparse array of nodes whose checking has been deferred capturedBlockScopeBindings?: Symbol[]; // Block-scoped bindings captured beneath this part of an IterationStatement outerTypeParameters?: TypeParameter[]; // Outer type parameters of anonymous object type isExhaustive?: boolean; // Is node an exhaustive switch statement diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 8caba5b205af8..1eb07d3328852 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -5798,7 +5798,7 @@ namespace ts { this.escapedName = name; this.declarations = undefined; this.valueDeclaration = undefined; - this.id = undefined; + this.id = 0; this.mergeId = undefined; this.parent = undefined; } diff --git a/src/services/refactors/extractSymbol.ts b/src/services/refactors/extractSymbol.ts index 6490fde538708..6b9d722157910 100644 --- a/src/services/refactors/extractSymbol.ts +++ b/src/services/refactors/extractSymbol.ts @@ -1597,7 +1597,7 @@ namespace ts.refactor.extractSymbol { const functionErrorsPerScope: Diagnostic[][] = []; const constantErrorsPerScope: Diagnostic[][] = []; const visibleDeclarationsInExtractedRange: NamedDeclaration[] = []; - const exposedVariableSymbolSet = new Map(); // Key is symbol ID + const exposedVariableSymbolSet = new Set(); // Key is symbol ID const exposedVariableDeclarations: VariableDeclaration[] = []; let firstExposedNonVariableDeclaration: NamedDeclaration | undefined; @@ -1903,10 +1903,10 @@ namespace ts.refactor.extractSymbol { const decl = find(visibleDeclarationsInExtractedRange, d => d.symbol === sym); if (decl) { if (isVariableDeclaration(decl)) { - const idString = decl.symbol.id!.toString(); - if (!exposedVariableSymbolSet.has(idString)) { + const declSymbol = decl.symbol; + if (!exposedVariableSymbolSet.has(declSymbol)) { exposedVariableDeclarations.push(decl); - exposedVariableSymbolSet.set(idString, true); + exposedVariableSymbolSet.add(declSymbol); } } else { diff --git a/src/services/services.ts b/src/services/services.ts index b04052a29c0b6..1782d3be1872d 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -287,6 +287,7 @@ namespace ts { class SymbolObject implements Symbol { flags: SymbolFlags; + id = 0; escapedName: __String; declarations!: Declaration[]; valueDeclaration!: Declaration;