mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-27 15:54:00 -05:00
Inspect all possible module paths when looking for the best one to create a specifier with (#25850)
* Inspect all possible specifier paths when looking for the best one * Add missing secondary option from test
This commit is contained in:
committed by
Wesley Wigham
parent
bde711583c
commit
a4d3bddf62
@@ -194,7 +194,12 @@ namespace ts.moduleSpecifiers {
|
||||
const symlinks = mapDefined(files, sf =>
|
||||
sf.resolvedModules && firstDefinedIterator(sf.resolvedModules.values(), res =>
|
||||
res && res.resolvedFileName === importedFileName ? res.originalPath : undefined));
|
||||
return symlinks.length === 0 ? getAllModulePathsUsingIndirectSymlinks(files, getNormalizedAbsolutePath(importedFileName, host.getCurrentDirectory ? host.getCurrentDirectory() : ""), getCanonicalFileName, host) : symlinks;
|
||||
const cwd = host.getCurrentDirectory ? host.getCurrentDirectory() : "";
|
||||
const baseOptions = getAllModulePathsUsingIndirectSymlinks(files, getNormalizedAbsolutePath(importedFileName, cwd), getCanonicalFileName, host);
|
||||
if (symlinks.length === 0) {
|
||||
return baseOptions;
|
||||
}
|
||||
return deduplicate(concatenate(baseOptions, flatMap(symlinks, importedFileName => getAllModulePathsUsingIndirectSymlinks(files, getNormalizedAbsolutePath(importedFileName, cwd), getCanonicalFileName, host))));
|
||||
}
|
||||
|
||||
function getRelativePathNParents(relativePath: string): number {
|
||||
|
||||
@@ -53,6 +53,7 @@ namespace compiler {
|
||||
public readonly js: ReadonlyMap<string, documents.TextDocument>;
|
||||
public readonly dts: ReadonlyMap<string, documents.TextDocument>;
|
||||
public readonly maps: ReadonlyMap<string, documents.TextDocument>;
|
||||
public symlinks?: vfs.FileSet; // Location to store original symlinks so they may be used in both original and declaration file compilations
|
||||
|
||||
private _inputs: documents.TextDocument[] = [];
|
||||
private _inputsAndOutputs: collections.SortedMap<string, CompilationOutput>;
|
||||
|
||||
@@ -1220,7 +1220,9 @@ namespace Harness {
|
||||
fs.apply(symlinks);
|
||||
}
|
||||
const host = new fakes.CompilerHost(fs, options);
|
||||
return compiler.compileFiles(host, programFileNames, options);
|
||||
const result = compiler.compileFiles(host, programFileNames, options);
|
||||
result.symlinks = symlinks;
|
||||
return result;
|
||||
}
|
||||
|
||||
export interface DeclarationCompilationContext {
|
||||
@@ -1261,7 +1263,7 @@ namespace Harness {
|
||||
}
|
||||
|
||||
function addDtsFile(file: TestFile, dtsFiles: TestFile[]) {
|
||||
if (vpath.isDeclaration(file.unitName)) {
|
||||
if (vpath.isDeclaration(file.unitName) || vpath.isJson(file.unitName)) {
|
||||
dtsFiles.push(file);
|
||||
}
|
||||
else if (vpath.isTypeScript(file.unitName)) {
|
||||
@@ -1302,12 +1304,12 @@ namespace Harness {
|
||||
}
|
||||
}
|
||||
|
||||
export function compileDeclarationFiles(context: DeclarationCompilationContext | undefined) {
|
||||
export function compileDeclarationFiles(context: DeclarationCompilationContext | undefined, symlinks: vfs.FileSet | undefined) {
|
||||
if (!context) {
|
||||
return;
|
||||
}
|
||||
const { declInputFiles, declOtherFiles, harnessSettings, options, currentDirectory } = context;
|
||||
const output = compileFiles(declInputFiles, declOtherFiles, harnessSettings, options, currentDirectory);
|
||||
const output = compileFiles(declInputFiles, declOtherFiles, harnessSettings, options, currentDirectory, symlinks);
|
||||
return { declInputFiles, declOtherFiles, declResult: output };
|
||||
}
|
||||
|
||||
@@ -1686,7 +1688,7 @@ namespace Harness {
|
||||
const declFileContext = prepareDeclarationCompilationContext(
|
||||
toBeCompiled, otherFiles, result, harnessSettings, options, /*currentDirectory*/ undefined
|
||||
);
|
||||
const declFileCompilationResult = compileDeclarationFiles(declFileContext);
|
||||
const declFileCompilationResult = compileDeclarationFiles(declFileContext, result.symlinks);
|
||||
|
||||
if (declFileCompilationResult && declFileCompilationResult.declResult.diagnostics.length) {
|
||||
jsCode += "\r\n\r\n//// [DtsFileErrors]\r\n";
|
||||
@@ -1890,6 +1892,7 @@ namespace Harness {
|
||||
for (const line of lines) {
|
||||
let testMetaData: RegExpExecArray | null;
|
||||
const linkMetaData = linkRegex.exec(line);
|
||||
linkRegex.lastIndex = 0;
|
||||
if (linkMetaData) {
|
||||
if (!symlinks) symlinks = {};
|
||||
symlinks[linkMetaData[2].trim()] = new vfs.Symlink(linkMetaData[1].trim());
|
||||
|
||||
@@ -198,8 +198,9 @@ namespace RWC {
|
||||
inputFiles, otherFiles, compilerResult, /*harnessSettings*/ undefined!, compilerOptions, currentDirectory // TODO: GH#18217
|
||||
);
|
||||
// Reset compilerResult before calling into `compileDeclarationFiles` so the memory from the original compilation can be freed
|
||||
const links = compilerResult.symlinks;
|
||||
compilerResult = undefined!;
|
||||
const declFileCompilationResult = Harness.Compiler.compileDeclarationFiles(declContext)!;
|
||||
const declFileCompilationResult = Harness.Compiler.compileDeclarationFiles(declContext, links)!;
|
||||
|
||||
return Harness.Compiler.iterateErrorBaseline(tsconfigFiles.concat(declFileCompilationResult.declInputFiles, declFileCompilationResult.declOtherFiles), declFileCompilationResult.declResult.diagnostics, { caseSensitive, currentDirectory });
|
||||
}, baselineOpts);
|
||||
|
||||
Reference in New Issue
Block a user