Skip to content

Commit fecafeb

Browse files
committed
Add getParsedCommandLine optional method on compiler host to be able to provide parsedCommandLine instead of redoing work
1 parent 4b81e37 commit fecafeb

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

src/compiler/program.ts

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2677,18 +2677,30 @@ namespace ts {
26772677
return fromCache || undefined;
26782678
}
26792679

2680-
// An absolute path pointing to the containing directory of the config file
2681-
const basePath = getNormalizedAbsolutePath(getDirectoryPath(refPath), host.getCurrentDirectory());
2682-
const sourceFile = host.getSourceFile(refPath, ScriptTarget.JSON) as JsonSourceFile | undefined;
2683-
addFileToFilesByName(sourceFile, sourceFilePath, /*redirectedPath*/ undefined);
2684-
if (sourceFile === undefined) {
2685-
projectReferenceRedirects.set(sourceFilePath, false);
2686-
return undefined;
2680+
let commandLine: ParsedCommandLine | undefined;
2681+
let sourceFile: JsonSourceFile | undefined;
2682+
if (host.getParsedCommandLine) {
2683+
commandLine = host.getParsedCommandLine(refPath);
2684+
if (!commandLine) {
2685+
projectReferenceRedirects.set(sourceFilePath, false);
2686+
return undefined;
2687+
}
2688+
sourceFile = Debug.assertDefined(commandLine.options.configFile);
2689+
}
2690+
else {
2691+
// An absolute path pointing to the containing directory of the config file
2692+
const basePath = getNormalizedAbsolutePath(getDirectoryPath(refPath), host.getCurrentDirectory());
2693+
sourceFile = host.getSourceFile(refPath, ScriptTarget.JSON) as JsonSourceFile | undefined;
2694+
addFileToFilesByName(sourceFile, sourceFilePath, /*redirectedPath*/ undefined);
2695+
if (sourceFile === undefined) {
2696+
projectReferenceRedirects.set(sourceFilePath, false);
2697+
return undefined;
2698+
}
2699+
sourceFile.path = sourceFilePath;
2700+
sourceFile.resolvedPath = sourceFilePath;
2701+
sourceFile.originalFileName = refPath;
2702+
commandLine = parseJsonSourceFileConfigFileContent(sourceFile, configParsingHost, basePath, /*existingOptions*/ undefined, refPath);
26872703
}
2688-
sourceFile.path = sourceFilePath;
2689-
sourceFile.resolvedPath = sourceFilePath;
2690-
sourceFile.originalFileName = refPath;
2691-
const commandLine = parseJsonSourceFileConfigFileContent(sourceFile, configParsingHost, basePath, /*existingOptions*/ undefined, refPath);
26922704
const resolvedRef: ResolvedProjectReference = { commandLine, sourceFile };
26932705
projectReferenceRedirects.set(sourceFilePath, resolvedRef);
26942706
if (commandLine.projectReferences) {

src/compiler/tsbuild.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ namespace ts {
399399
let projectCompilerOptions = baseCompilerOptions;
400400
const compilerHost = createCompilerHostFromProgramHost(host, () => projectCompilerOptions);
401401
setGetSourceFileAsHashVersioned(compilerHost, host);
402+
compilerHost.getParsedCommandLine = parseConfigFile;
402403

403404
const buildInfoChecked = createFileMap<true>(toPath);
404405

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5130,6 +5130,7 @@ namespace ts {
51305130
/* @internal */ hasInvalidatedResolution?: HasInvalidatedResolution;
51315131
/* @internal */ hasChangedAutomaticTypeDirectiveNames?: boolean;
51325132
createHash?(data: string): string;
5133+
/*@internal*/getParsedCommandLine?(fileName: string): ParsedCommandLine | undefined;
51335134

51345135
// TODO: later handle this in better way in builder host instead once the api for tsbuild finalizes and doesnt use compilerHost as base
51355136
/*@internal*/createDirectory?(directory: string): void;

0 commit comments

Comments
 (0)