Skip to content

Remove calls of getNodeId in compiler outside of the checker #46595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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!;
}
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -4946,7 +4946,7 @@ namespace ts {
lateSymbol?: Symbol; // Late-bound symbol for a computed property
specifierCache?: ESMap<string, string>; // 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<NodeId, Symbol[]>; // Containers (other than the parent) which this symbol is aliased in
extendedContainersByFile?: ESMap<Node, Symbol[]>; // 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
Expand Down Expand Up @@ -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<NodeId, Node>; // 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
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions src/services/refactors/extractSymbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1597,7 +1597,7 @@ namespace ts.refactor.extractSymbol {
const functionErrorsPerScope: Diagnostic[][] = [];
const constantErrorsPerScope: Diagnostic[][] = [];
const visibleDeclarationsInExtractedRange: NamedDeclaration[] = [];
const exposedVariableSymbolSet = new Map<string, true>(); // Key is symbol ID
const exposedVariableSymbolSet = new Set<Symbol>(); // Key is symbol ID
const exposedVariableDeclarations: VariableDeclaration[] = [];
let firstExposedNonVariableDeclaration: NamedDeclaration | undefined;

Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ namespace ts {

class SymbolObject implements Symbol {
flags: SymbolFlags;
id = 0;
escapedName: __String;
declarations!: Declaration[];
valueDeclaration!: Declaration;
Expand Down