fix(compiler-cli): Return original sourceFile instead of redirected sourceFile from getSourceFile (#26036)

Closes #22524

PR Close #26036
This commit is contained in:
Jon Wallsten
2019-07-08 16:50:19 +02:00
committed by Matias Niemelä
parent 40705f3366
commit 3166cffd28
4 changed files with 85 additions and 0 deletions

View File

@ -39,6 +39,13 @@ export class TypeCheckProgramHost implements ts.CompilerHost {
sf = this.delegate.getSourceFile(
fileName, languageVersion, onError, shouldCreateNewSourceFile);
sf && this.sfMap.set(fileName, sf);
} else {
// TypeScript doesn't allow returning redirect source files. To avoid unforseen errors we
// return the original source file instead of the redirect target.
const redirectInfo = (sf as any).redirectInfo;
if (redirectInfo !== undefined) {
sf = redirectInfo.unredirected;
}
}
return sf;
}

View File

@ -441,6 +441,12 @@ export class TsCompilerAotCompilerTypeCheckHostAdapter implements ts.CompilerHos
fileName, summary.text, this.options.target || ts.ScriptTarget.Latest);
}
sf = summary.sourceFile;
// TypeScript doesn't allow returning redirect source files. To avoid unforseen errors we
// return the original source file instead of the redirect target.
const redirectInfo = (sf as any).redirectInfo;
if (redirectInfo !== undefined) {
sf = redirectInfo.unredirected;
}
genFileNames = [];
}
}