Skip to content

Commit 6d41964

Browse files
authored
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
1 parent 7267fca commit 6d41964

File tree

62 files changed

+2727
-1619
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+2727
-1619
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,4 @@ tests/cases/user/puppeteer/puppeteer
8484
tests/cases/user/axios-src/axios-src
8585
tests/cases/user/prettier/prettier
8686
.eslintcache
87+
*v8.log

src/compiler/binder.ts

Lines changed: 138 additions & 120 deletions
Large diffs are not rendered by default.

src/compiler/checker.ts

Lines changed: 489 additions & 363 deletions
Large diffs are not rendered by default.

src/compiler/emitter.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
BundleFileTextLikeKind,
2929
CallExpression,
3030
CallSignatureDeclaration,
31+
canHaveLocals,
3132
CaseBlock,
3233
CaseClause,
3334
CaseOrDefaultClause,
@@ -181,6 +182,7 @@ import {
181182
getTransformers,
182183
getTypeNode,
183184
guessIndentation,
185+
HasLocals,
184186
hasRecordedExternalHelpers,
185187
HeritageClause,
186188
Identifier,
@@ -412,6 +414,7 @@ import {
412414
tracing,
413415
TransformationResult,
414416
transformNodes,
417+
tryCast,
415418
tryParseRawSourceMap,
416419
TryStatement,
417420
TupleTypeNode,
@@ -2475,8 +2478,7 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
24752478
//
24762479

24772480
function emitPrivateIdentifier(node: PrivateIdentifier) {
2478-
const writeText = node.symbol ? writeSymbol : write;
2479-
writeText(getTextOfNode(node, /*includeTrivia*/ false), node.symbol);
2481+
write(getTextOfNode(node, /*includeTrivia*/ false));
24802482
}
24812483

24822484

@@ -5656,9 +5658,9 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
56565658
/**
56575659
* Returns a value indicating whether a name is unique within a container.
56585660
*/
5659-
function isUniqueLocalName(name: string, container: Node): boolean {
5660-
for (let node = container; isNodeDescendantOf(node, container); node = node.nextContainer!) {
5661-
if (node.locals) {
5661+
function isUniqueLocalName(name: string, container: HasLocals | undefined): boolean {
5662+
for (let node = container; node && isNodeDescendantOf(node, container); node = node.nextContainer) {
5663+
if (canHaveLocals(node) && node.locals) {
56625664
const local = node.locals.get(escapeLeadingUnderscores(name));
56635665
// We conservatively include alias symbols to cover cases where they're emitted as locals
56645666
if (local && local.flags & (SymbolFlags.Value | SymbolFlags.ExportValue | SymbolFlags.Alias)) {
@@ -5798,7 +5800,7 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
57985800
function generateNameForModuleOrEnum(node: ModuleDeclaration | EnumDeclaration) {
57995801
const name = getTextOfNode(node.name);
58005802
// Use module/enum name itself if it is unique, otherwise make a unique variation
5801-
return isUniqueLocalName(name, node) ? name : makeUniqueName(name, isUniqueName, /*optimistic*/ false, /*scoped*/ false, /*privateName*/ false, /*prefix*/ "", /*suffix*/ "");
5803+
return isUniqueLocalName(name, tryCast(node, canHaveLocals)) ? name : makeUniqueName(name, isUniqueName, /*optimistic*/ false, /*scoped*/ false, /*privateName*/ false, /*prefix*/ "", /*suffix*/ "");
58025804
}
58035805

58045806
/**

0 commit comments

Comments
 (0)