Keep alive declaration script info and map file info if source file info is alive

This commit is contained in:
Sheetal Nandi
2018-12-06 15:22:42 -08:00
parent 0aa4da43ad
commit 56a39b754c
7 changed files with 47 additions and 27 deletions
+7 -7
View File
@@ -16,7 +16,7 @@ namespace ts {
fileExists?(path: string): boolean;
readFile?(path: string, encoding?: string): string | undefined;
getSourceFileLike?(fileName: string): SourceFileLike | undefined;
getDocumentPositionMapper?(fileName: string): DocumentPositionMapper | undefined;
getDocumentPositionMapper?(generatedFileName: string, sourceFileName?: string): DocumentPositionMapper | undefined;
log(s: string): void;
}
@@ -31,20 +31,20 @@ namespace ts {
return ts.toPath(fileName, currentDirectory, getCanonicalFileName);
}
function getDocumentPositionMapper(fileName: string) {
const path = toPath(fileName);
function getDocumentPositionMapper(generatedFileName: string, sourceFileName?: string) {
const path = toPath(generatedFileName);
const value = documentPositionMappers.get(path);
if (value) return value;
let mapper: DocumentPositionMapper | undefined;
if (host.getDocumentPositionMapper) {
mapper = host.getDocumentPositionMapper(fileName);
mapper = host.getDocumentPositionMapper(generatedFileName, sourceFileName);
}
else if (host.readFile) {
const file = getSourceFileLike(fileName);
const file = getSourceFileLike(generatedFileName);
mapper = file && ts.getDocumentPositionMapper(
{ getSourceFileLike, getCanonicalFileName, log: s => host.log(s) },
fileName,
generatedFileName,
getLineInfo(file.text, getLineStarts(file)),
f => !host.fileExists || host.fileExists(f) ? host.readFile!(f) : undefined
);
@@ -78,7 +78,7 @@ namespace ts {
getDeclarationEmitOutputFilePathWorker(info.fileName, program.getCompilerOptions(), currentDirectory, program.getCommonSourceDirectory(), getCanonicalFileName);
if (declarationPath === undefined) return undefined;
const newLoc = getDocumentPositionMapper(declarationPath).getGeneratedPosition(info);
const newLoc = getDocumentPositionMapper(declarationPath, info.fileName).getGeneratedPosition(info);
return newLoc === info ? undefined : newLoc;
}