Cherry-pick PR #32878 into release-3.6

Component commits:
c78c88f447 Fix references to path-mapped ambient modules in declaration files

48a1fc33f5 Fix lint
This commit is contained in:
Wesley Wigham
2019-08-13 23:41:54 +00:00
committed by typescript-bot
parent 635a158d4f
commit ef222a5892
8 changed files with 139 additions and 0 deletions

View File

@@ -748,6 +748,7 @@ namespace ts {
useCaseSensitiveFileNames: () => host.useCaseSensitiveFileNames(),
getProgramBuildInfo: returnUndefined,
getSourceFileFromReference: returnUndefined,
redirectTargetsMap: createMultiMap()
};
emitFiles(
notImplementedResolver,

View File

@@ -1446,6 +1446,7 @@ namespace ts {
useCaseSensitiveFileNames: () => host.useCaseSensitiveFileNames(),
getProgramBuildInfo: () => program.getProgramBuildInfo && program.getProgramBuildInfo(),
getSourceFileFromReference: (file, ref) => program.getSourceFileFromReference(file, ref),
redirectTargetsMap,
};
}

View File

@@ -327,6 +327,26 @@ namespace ts {
}
if (declFileName) {
const specifier = moduleSpecifiers.getModuleSpecifier(
// We pathify the baseUrl since we pathify the other paths here, so we can still easily check if the other paths are within the baseUrl
// TODO: Should we _always_ be pathifying the baseUrl as we read it in?
{ ...options, baseUrl: options.baseUrl && toPath(options.baseUrl, host.getCurrentDirectory(), host.getCanonicalFileName) },
currentSourceFile,
toPath(outputFilePath, host.getCurrentDirectory(), host.getCanonicalFileName),
toPath(declFileName, host.getCurrentDirectory(), host.getCanonicalFileName),
host,
host.getSourceFiles(),
/*preferences*/ undefined,
host.redirectTargetsMap
);
if (!pathIsRelative(specifier)) {
// If some compiler option/symlink/whatever allows access to the file containing the ambient module declaration
// via a non-relative name, emit a type reference directive to that non-relative name, rather than
// a relative path to the declaration file
recordTypeReferenceDirectivesIfNecessary([specifier]);
return;
}
let fileName = getRelativePathToDirectoryOrUrl(
outputFilePath,
declFileName,

View File

@@ -5444,6 +5444,7 @@ namespace ts {
writeFile: WriteFileCallback;
getProgramBuildInfo(): ProgramBuildInfo | undefined;
getSourceFileFromReference: Program["getSourceFileFromReference"];
readonly redirectTargetsMap: RedirectTargetsMap;
}
export interface TransformationContext {