Skip to content

Commit

Permalink
Reduce polymorphism resulting from unstable Node shapes (#51682)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
rbuckton authored Dec 13, 2022
1 parent 7267fca commit 6d41964
Show file tree
Hide file tree
Showing 62 changed files with 2,727 additions and 1,619 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,4 @@ tests/cases/user/puppeteer/puppeteer
tests/cases/user/axios-src/axios-src
tests/cases/user/prettier/prettier
.eslintcache
*v8.log
258 changes: 138 additions & 120 deletions src/compiler/binder.ts

Large diffs are not rendered by default.

852 changes: 489 additions & 363 deletions src/compiler/checker.ts

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
BundleFileTextLikeKind,
CallExpression,
CallSignatureDeclaration,
canHaveLocals,
CaseBlock,
CaseClause,
CaseOrDefaultClause,
Expand Down Expand Up @@ -181,6 +182,7 @@ import {
getTransformers,
getTypeNode,
guessIndentation,
HasLocals,
hasRecordedExternalHelpers,
HeritageClause,
Identifier,
Expand Down Expand Up @@ -412,6 +414,7 @@ import {
tracing,
TransformationResult,
transformNodes,
tryCast,
tryParseRawSourceMap,
TryStatement,
TupleTypeNode,
Expand Down Expand Up @@ -2475,8 +2478,7 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
//

function emitPrivateIdentifier(node: PrivateIdentifier) {
const writeText = node.symbol ? writeSymbol : write;
writeText(getTextOfNode(node, /*includeTrivia*/ false), node.symbol);
write(getTextOfNode(node, /*includeTrivia*/ false));
}


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

/**
Expand Down
Loading

0 comments on commit 6d41964

Please sign in to comment.