mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-16 07:13:43 -05:00
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:
@@ -239,6 +239,7 @@ import {
|
||||
ParsedCommandLine,
|
||||
parseIsolatedEntityName,
|
||||
parseJsonSourceFileConfigFileContent,
|
||||
parseNodeFactory,
|
||||
Path,
|
||||
pathIsAbsolute,
|
||||
pathIsRelative,
|
||||
@@ -3343,26 +3344,15 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
|
||||
}
|
||||
}
|
||||
|
||||
function createRedirectSourceFile(redirectTarget: SourceFile, unredirected: SourceFile, fileName: string, path: Path, resolvedPath: Path, originalFileName: string, sourceFileOptions: CreateSourceFileOptions): SourceFile {
|
||||
const redirect: SourceFile = Object.create(redirectTarget);
|
||||
function createRedirectedSourceFile(redirectTarget: SourceFile, unredirected: SourceFile, fileName: string, path: Path, resolvedPath: Path, originalFileName: string, sourceFileOptions: CreateSourceFileOptions): SourceFile {
|
||||
const redirect = parseNodeFactory.createRedirectedSourceFile({ redirectTarget, unredirected });
|
||||
redirect.fileName = fileName;
|
||||
redirect.path = path;
|
||||
redirect.resolvedPath = resolvedPath;
|
||||
redirect.originalFileName = originalFileName;
|
||||
redirect.redirectInfo = { redirectTarget, unredirected };
|
||||
redirect.packageJsonLocations = sourceFileOptions.packageJsonLocations?.length ? sourceFileOptions.packageJsonLocations : undefined;
|
||||
redirect.packageJsonScope = sourceFileOptions.packageJsonScope;
|
||||
sourceFilesFoundSearchingNodeModules.set(path, currentNodeModulesDepth > 0);
|
||||
Object.defineProperties(redirect, {
|
||||
id: {
|
||||
get(this: SourceFile) { return this.redirectInfo!.redirectTarget.id; },
|
||||
set(this: SourceFile, value: SourceFile["id"]) { this.redirectInfo!.redirectTarget.id = value; },
|
||||
},
|
||||
symbol: {
|
||||
get(this: SourceFile) { return this.redirectInfo!.redirectTarget.symbol; },
|
||||
set(this: SourceFile, value: SourceFile["symbol"]) { this.redirectInfo!.redirectTarget.symbol = value; },
|
||||
},
|
||||
});
|
||||
return redirect;
|
||||
}
|
||||
|
||||
@@ -3494,7 +3484,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
|
||||
if (fileFromPackageId) {
|
||||
// Some other SourceFile already exists with this package name and version.
|
||||
// Instead of creating a duplicate, just redirect to the existing one.
|
||||
const dupFile = createRedirectSourceFile(fileFromPackageId, file!, fileName, path, toPath(fileName), originalFileName, sourceFileOptions);
|
||||
const dupFile = createRedirectedSourceFile(fileFromPackageId, file!, fileName, path, toPath(fileName), originalFileName, sourceFileOptions);
|
||||
redirectTargetsMap.add(fileFromPackageId.path, fileName);
|
||||
addFileToFilesByName(dupFile, path, redirectedPath);
|
||||
addFileIncludeReason(dupFile, reason);
|
||||
|
||||
Reference in New Issue
Block a user