Skip to content
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
27 changes: 17 additions & 10 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -533,18 +533,25 @@ namespace ts {
}

let referencedSourceFile: string;
while (true) {
const searchName = normalizePath(combinePaths(containingDirectory, moduleName));
referencedSourceFile = loadModuleFromFile(searchName, supportedExtensions, failedLookupLocations, /*onlyRecordFailures*/ false, state);
if (referencedSourceFile) {
break;
}
const parentPath = getDirectoryPath(containingDirectory);
if (parentPath === containingDirectory) {
break;
if (moduleHasNonRelativeName(moduleName)) {
while (true) {
const searchName = normalizePath(combinePaths(containingDirectory, moduleName));
referencedSourceFile = loadModuleFromFile(searchName, supportedExtensions, failedLookupLocations, /*onlyRecordFailures*/ false, state);
if (referencedSourceFile) {
break;
}
const parentPath = getDirectoryPath(containingDirectory);
if (parentPath === containingDirectory) {
break;
}
containingDirectory = parentPath;
}
containingDirectory = parentPath;
}
else {
const candidate = normalizePath(combinePaths(containingDirectory, moduleName));
referencedSourceFile = loadModuleFromFile(candidate, supportedExtensions, failedLookupLocations, /*onlyRecordFailures*/ false, state);
}


return referencedSourceFile
? { resolvedModule: { resolvedFileName: referencedSourceFile }, failedLookupLocations }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
tests/cases/compiler/somefolder/a.ts(2,17): error TS2307: Cannot find module './b'.


==== tests/cases/compiler/somefolder/a.ts (1 errors) ====

import {x} from "./b"
~~~~~
!!! error TS2307: Cannot find module './b'.

==== tests/cases/compiler/b.ts (0 errors) ====
export let x = 1;
18 changes: 18 additions & 0 deletions tests/baselines/reference/relativeNamesInClassicResolution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//// [tests/cases/compiler/relativeNamesInClassicResolution.ts] ////

//// [a.ts]

import {x} from "./b"

//// [b.ts]
export let x = 1;

//// [a.js]
define(["require", "exports"], function (require, exports) {
"use strict";
});
//// [b.js]
define(["require", "exports"], function (require, exports) {
"use strict";
exports.x = 1;
});
7 changes: 7 additions & 0 deletions tests/cases/compiler/relativeNamesInClassicResolution.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// @module:amd

// @filename: somefolder/a.ts
import {x} from "./b"

// @filename: b.ts
export let x = 1;
23 changes: 9 additions & 14 deletions tests/cases/unittests/moduleResolution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module ts {
return hasProperty(directories, path);
},
fileExists: path => {
assert.isTrue(hasProperty(directories, getDirectoryPath(path)), "'fileExists' request in non-existing directory");
assert.isTrue(hasProperty(directories, getDirectoryPath(path)), `'fileExists' '${path}' request in non-existing directory`);
return hasProperty(map, path);
}
}
Expand Down Expand Up @@ -814,7 +814,6 @@ import b = require("./moduleB.ts");

it ("classic + rootDirs", () => {
test(/*hasDirectoryExists*/ false);
test(/*hasDirectoryExists*/ true);

function test(hasDirectoryExists: boolean) {
let file1: File = { name: "/root/folder1/file1.ts" };
Expand Down Expand Up @@ -844,24 +843,20 @@ import b = require("./moduleB.ts");
"/root/generated/folder1/file1.d.ts",
// then try alternative rootDir entry
]);
check("../folder1/file1_1", file3, file4, [
// load from initial location
"/root/generated/folder1/file1_1.ts",
"/root/generated/folder1/file1_1.tsx",
"/root/generated/folder1/file1_1.d.ts",
// load from alternative rootDir entry
"/root/folder1/file1_1.ts",
"/root/folder1/file1_1.tsx",
"/root/folder1/file1_1.d.ts",
// fallback to classic
// step1: initial location
check("folder1/file1_1", file3, file4, [
// current location
"/root/generated/folder2/folder1/file1_1.ts",
"/root/generated/folder2/folder1/file1_1.tsx",
"/root/generated/folder2/folder1/file1_1.d.ts",
// other entry in rootDirs
"/root/generated/folder1/file1_1.ts",
"/root/generated/folder1/file1_1.tsx",
"/root/generated/folder1/file1_1.d.ts",
// step2: walk 1 level up
// fallback
"/root/folder1/file1_1.ts",
"/root/folder1/file1_1.tsx",
"/root/folder1/file1_1.d.ts",
// found one
]);

function check(name: string, container: File, expected: File, expectedFailedLookups: string[]) {
Expand Down