Skip to content

Resolve module specifier relative to moduleFile.originalFileName #32722

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/moduleSpecifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ namespace ts.moduleSpecifiers {

const info = getInfo(importingSourceFile.path, host);
const moduleSourceFile = getSourceFileOfNode(moduleSymbol.valueDeclaration || getNonAugmentationDeclaration(moduleSymbol));
const modulePaths = getAllModulePaths(files, importingSourceFile.path, moduleSourceFile.fileName, info.getCanonicalFileName, host, redirectTargetsMap);
const modulePaths = getAllModulePaths(files, importingSourceFile.path, moduleSourceFile.originalFileName, info.getCanonicalFileName, host, redirectTargetsMap);

const preferences = getPreferences(userPreferences, compilerOptions, importingSourceFile);
const global = mapDefined(modulePaths, moduleFileName => tryGetModuleNameAsNodeModule(moduleFileName, info, host, compilerOptions));
Expand Down
26 changes: 24 additions & 2 deletions src/harness/vfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1525,8 +1525,11 @@ namespace vfs {
return typeof value === "string" || Buffer.isBuffer(value) ? new File(value) : new Directory(value);
}

export function formatPatch(patch: FileSet) {
return formatPatchWorker("", patch);
export function formatPatch(patch: FileSet): string;
export function formatPatch(patch: FileSet | undefined): string | null;
export function formatPatch(patch: FileSet | undefined) {
// tslint:disable-next-line:no-null-keyword
return patch ? formatPatchWorker("", patch) : null;
}

function formatPatchWorker(dirname: string, container: FileSet): string {
Expand Down Expand Up @@ -1559,5 +1562,24 @@ namespace vfs {
}
return text;
}

export function iteratePatch(patch: FileSet | undefined): IterableIterator<[string, string]> | null {
// tslint:disable-next-line:no-null-keyword
return patch ? Harness.Compiler.iterateOutputs(iteratePatchWorker("", patch)) : null;
}

function* iteratePatchWorker(dirname: string, container: FileSet): IterableIterator<documents.TextDocument> {
for (const name of Object.keys(container)) {
const entry = normalizeFileSetEntry(container[name]);
const file = dirname ? vpath.combine(dirname, name) : name;
if (entry instanceof Directory) {
yield* ts.arrayFrom(iteratePatchWorker(file, entry.files));
}
else if (entry instanceof File) {
const content = typeof entry.data === "string" ? entry.data : entry.data.toString("utf8");
yield new documents.TextDocument(file, content);
}
}
}
}
// tslint:enable:no-null-keyword
1 change: 1 addition & 0 deletions src/testRunner/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"unittests/tsbuild/inferredTypeFromTransitiveModule.ts",
"unittests/tsbuild/lateBoundSymbol.ts",
"unittests/tsbuild/missingExtendedFile.ts",
"unittests/tsbuild/moduleSpecifiers.ts",
"unittests/tsbuild/outFile.ts",
"unittests/tsbuild/referencesWithRootDirInParent.ts",
"unittests/tsbuild/resolveJsonModule.ts",
Expand Down
1 change: 0 additions & 1 deletion src/testRunner/unittests/config/projectReferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,5 +348,4 @@ namespace ts {
});
});
});

}
98 changes: 98 additions & 0 deletions src/testRunner/unittests/tsbuild/moduleSpecifiers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
namespace ts {
// https://github.com/microsoft/TypeScript/issues/31696
it("unittests:: tsbuild:: moduleSpecifiers:: synthesized module specifiers to referenced projects resolve correctly", () => {
const baseFs = vfs.createFromFileSystem(Harness.IO, /*ignoreCase*/ false, {
files: {
"/src/common/nominal.ts": utils.dedent`
export declare type Nominal<T, Name extends string> = T & {
[Symbol.species]: Name;
};
`,
"/src/common/tsconfig.json": utils.dedent`
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"composite": true
},
"include": ["nominal.ts"]
}`,
"/src/sub-project/index.ts": utils.dedent`
import { Nominal } from '../common/nominal';

export type MyNominal = Nominal<string, 'MyNominal'>;
`,
"/src/sub-project/tsconfig.json": utils.dedent`
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"composite": true
},
"references": [
{ "path": "../common" }
],
"include": ["./index.ts"]
}`,
"/src/sub-project-2/index.ts": utils.dedent`
import { MyNominal } from '../sub-project/index';

const variable = {
key: 'value' as MyNominal,
};

export function getVar(): keyof typeof variable {
return 'key';
}
`,
"/src/sub-project-2/tsconfig.json": utils.dedent`
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"composite": true
},
"references": [
{ "path": "../sub-project" }
],
"include": ["./index.ts"]
}`,
"/src/tsconfig.json": utils.dedent`
{
"compilerOptions": {
"composite": true
},
"references": [
{ "path": "./sub-project" },
{ "path": "./sub-project-2" }
],
"include": []
}`,
"/tsconfig.base.json": utils.dedent`
{
"compilerOptions": {
"skipLibCheck": true,
"rootDir": "./",
"outDir": "lib",
"lib": ["dom", "es2015", "es2015.symbol.wellknown"]
}
}`,
"/tsconfig.json": utils.dedent`{
"compilerOptions": {
"composite": true
},
"references": [
{ "path": "./src" }
],
"include": []
}`
},
cwd: "/"
});
const fs = baseFs.makeReadonly().shadow();
const sys = new fakes.System(fs, { executingFilePath: "/", newLine: "\n" });
const host = new fakes.SolutionBuilderHost(sys);
const builder = createSolutionBuilder(host, ["/tsconfig.json"], { dry: false, force: false, verbose: false });
builder.build();

// Prior to fixing GH31696 the import in `/lib/src/sub-project-2/index.d.ts` was `import("../../lib/src/common/nonterminal")`, which was invalid.
Harness.Baseline.runBaseline("tsbuild/moduleSpecifiers/initial-build/resolves-correctly.js", vfs.formatPatch(fs.diff(baseFs)));
});
}
Loading