Reduce polymorphism resulting from unstable Node shapes (#51682)

* Move .symbol to Declaration

* simplify some factories

* Move localSymbol to Declaration

* Ensure JSDocContainer types are properly initialized

* Move contextualType from Node to NodeLinks

* Move 'locals' and 'nextContainer' out of Node

* Move 'flowNode' out of 'Node'

* Pre-define endFlowNode/returnFlowNode

* Pre-define some SourceFile properties and a more stable cloneNode

* Don't add excess properties to type nodes in typeToTypeNode

* Refactor wrapSymbolTrackerToReportForContext to improve perf
This commit is contained in:
Ron Buckton
2022-12-13 15:11:10 -05:00
committed by GitHub
parent 7267fcaeb9
commit 6d41964fd0
62 changed files with 2730 additions and 1622 deletions
+3 -1
View File
@@ -5,6 +5,7 @@ import {
Block,
BreakOrContinueStatement,
CancellationToken,
canHaveSymbol,
CaseClause,
cast,
concatenate,
@@ -78,6 +79,7 @@ import {
ThrowStatement,
toArray,
toPath,
tryCast,
TryStatement,
} from "./_namespaces/ts";
@@ -184,7 +186,7 @@ export namespace DocumentHighlights {
}
function getFromAllDeclarations<T extends Node>(nodeTest: (node: Node) => node is T, keywords: readonly SyntaxKind[]): HighlightSpan[] | undefined {
return useParent(node.parent, nodeTest, decl => mapDefined(decl.symbol.declarations, d =>
return useParent(node.parent, nodeTest, decl => mapDefined(tryCast(decl, canHaveSymbol)?.symbol.declarations, d =>
nodeTest(d) ? find(d.getChildren(sourceFile), c => contains(keywords, c.kind)) : undefined));
}