Skip to content

Commit 012ecda

Browse files
committed
Add sourceOf project reference redirect to filesByName list for redirect path so that module symbol is correctly resolved
1 parent f472868 commit 012ecda

File tree

4 files changed

+102
-80
lines changed

4 files changed

+102
-80
lines changed

src/compiler/program.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1411,6 +1411,13 @@ namespace ts {
14111411
for (const newSourceFile of newSourceFiles) {
14121412
const filePath = newSourceFile.path;
14131413
addFileToFilesByName(newSourceFile, filePath, newSourceFile.resolvedPath);
1414+
if (useSourceOfReference) {
1415+
const redirectProject = getProjectReferenceRedirectProject(newSourceFile.fileName);
1416+
if (redirectProject && !(redirectProject.commandLine.options.outFile || redirectProject.commandLine.options.out)) {
1417+
const redirect = getProjectReferenceOutputName(redirectProject, newSourceFile.fileName);
1418+
addFileToFilesByName(newSourceFile, toPath(redirect), /*redirectedPath*/ undefined);
1419+
}
1420+
}
14141421
// Set the file as found during node modules search if it was found that way in old progra,
14151422
if (oldProgram.isSourceFileFromExternalLibrary(oldProgram.getSourceFileByPath(filePath)!)) {
14161423
sourceFilesFoundSearchingNodeModules.set(filePath, true);
@@ -2240,9 +2247,11 @@ namespace ts {
22402247
if (useSourceOfReference) {
22412248
const source = getSourceOfProjectReferenceRedirect(fileName);
22422249
if (source) {
2243-
return isString(source) ?
2250+
const file = isString(source) ?
22442251
findSourceFile(source, toPath(source), isDefaultLib, ignoreNoDefaultLib, refFile, refPos, refEnd, packageId) :
22452252
undefined;
2253+
if (file) addFileToFilesByName(file, path, /*redirectedPath*/ undefined);
2254+
return file;
22462255
}
22472256
}
22482257
const originalFileName = fileName;

src/services/services.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,10 +1148,11 @@ namespace ts {
11481148
useCaseSensitiveFileNames: () => useCaseSensitiveFileNames,
11491149
getCurrentDirectory: () => currentDirectory,
11501150
getProgram,
1151-
fileExists: host.fileExists && (f => host.fileExists!(f)),
1152-
readFile: host.readFile && ((f, encoding) => host.readFile!(f, encoding)),
1153-
getDocumentPositionMapper: host.getDocumentPositionMapper && ((generatedFileName, sourceFileName) => host.getDocumentPositionMapper!(generatedFileName, sourceFileName)),
1154-
getSourceFileLike: host.getSourceFileLike && (f => host.getSourceFileLike!(f)),
1151+
fileExists: maybeBind(host, host.fileExists),
1152+
readFile: maybeBind(host, host.readFile),
1153+
getDocumentPositionMapper: maybeBind(host, host.getDocumentPositionMapper),
1154+
useSourceInsteadOfReferenceRedirect: maybeBind(host, host.useSourceInsteadOfReferenceRedirect),
1155+
getSourceFileLike: maybeBind(host, host.getSourceFileLike),
11551156
log
11561157
});
11571158

src/services/sourcemaps.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace ts {
1717
readFile?(path: string, encoding?: string): string | undefined;
1818
getSourceFileLike?(fileName: string): SourceFileLike | undefined;
1919
getDocumentPositionMapper?(generatedFileName: string, sourceFileName?: string): DocumentPositionMapper | undefined;
20+
/* @internal */ useSourceInsteadOfReferenceRedirect?(): boolean;
2021
log(s: string): void;
2122
}
2223

@@ -70,6 +71,11 @@ namespace ts {
7071
if (!sourceFile) return undefined;
7172

7273
const program = host.getProgram()!;
74+
// If this is source file of project reference source (instead of redirect) there is no generated position
75+
if (host.useSourceInsteadOfReferenceRedirect &&
76+
host.useSourceInsteadOfReferenceRedirect() &&
77+
program.getResolvedProjectReferenceToRedirect(sourceFile.fileName)) return undefined;
78+
7379
const options = program.getCompilerOptions();
7480
const outPath = options.outFile || options.out;
7581

0 commit comments

Comments
 (0)