mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-09 02:30:15 -06:00
Merge pull request #6803 from Microsoft/noDirExistsCheckInClassic
don't do 'directoryExists' check in classic resolution scheme
This commit is contained in:
commit
555f35e2cd
@ -88,6 +88,8 @@ namespace ts {
|
||||
host: ModuleResolutionHost;
|
||||
compilerOptions: CompilerOptions;
|
||||
traceEnabled: boolean;
|
||||
// skip .tsx files if jsx is not enabled
|
||||
skipTsx: boolean;
|
||||
}
|
||||
|
||||
export function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations {
|
||||
@ -369,7 +371,7 @@ namespace ts {
|
||||
const traceEnabled = isTraceEnabled(compilerOptions, host);
|
||||
|
||||
const failedLookupLocations: string[] = [];
|
||||
const state = {compilerOptions, host, traceEnabled};
|
||||
const state = {compilerOptions, host, traceEnabled, skipTsx: false};
|
||||
let resolvedFileName = tryLoadModuleUsingOptionalResolutionSettings(moduleName, containingDirectory, nodeLoadModuleByRelativeName,
|
||||
failedLookupLocations, supportedExtensions, state);
|
||||
|
||||
@ -418,6 +420,9 @@ namespace ts {
|
||||
return forEach(extensions, tryLoad);
|
||||
|
||||
function tryLoad(ext: string): string {
|
||||
if (ext === ".tsx" && state.skipTsx) {
|
||||
return undefined;
|
||||
}
|
||||
const fileName = fileExtensionIs(candidate, ext) ? candidate : candidate + ext;
|
||||
if (!onlyRecordFailures && state.host.fileExists(fileName)) {
|
||||
if (state.traceEnabled) {
|
||||
@ -517,7 +522,7 @@ namespace ts {
|
||||
|
||||
export function classicNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations {
|
||||
const traceEnabled = isTraceEnabled(compilerOptions, host);
|
||||
const state = { compilerOptions, host, traceEnabled };
|
||||
const state = { compilerOptions, host, traceEnabled, skipTsx: !compilerOptions.jsx };
|
||||
const failedLookupLocations: string[] = [];
|
||||
const supportedExtensions = getSupportedExtensions(compilerOptions);
|
||||
let containingDirectory = getDirectoryPath(containingFile);
|
||||
@ -530,8 +535,7 @@ namespace ts {
|
||||
let referencedSourceFile: string;
|
||||
while (true) {
|
||||
const searchName = normalizePath(combinePaths(containingDirectory, moduleName));
|
||||
const directoryName = getDirectoryPath(searchName);
|
||||
referencedSourceFile = loadModuleFromFile(searchName, supportedExtensions, failedLookupLocations, !directoryProbablyExists(directoryName, host), state);
|
||||
referencedSourceFile = loadModuleFromFile(searchName, supportedExtensions, failedLookupLocations, /*onlyRecordFailures*/ false, state);
|
||||
if (referencedSourceFile) {
|
||||
break;
|
||||
}
|
||||
|
||||
@ -14,13 +14,10 @@
|
||||
"'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name 'file4'",
|
||||
"Resolving module name 'file4' relative to base url 'c:/root' - 'c:/root/file4'.",
|
||||
"File 'c:/root/file4.ts' does not exist.",
|
||||
"File 'c:/root/file4.tsx' does not exist.",
|
||||
"File 'c:/root/file4.d.ts' does not exist.",
|
||||
"File 'c:/root/folder2/file4.ts' does not exist.",
|
||||
"File 'c:/root/folder2/file4.tsx' does not exist.",
|
||||
"File 'c:/root/folder2/file4.d.ts' does not exist.",
|
||||
"File 'c:/root/file4.ts' does not exist.",
|
||||
"File 'c:/root/file4.tsx' does not exist.",
|
||||
"File 'c:/root/file4.d.ts' does not exist.",
|
||||
"File 'c:/file4.ts' exist - use it as a module resolution result.",
|
||||
"======== Module name 'file4' was successfully resolved to 'c:/file4.ts'. ========"
|
||||
|
||||
@ -14,13 +14,10 @@
|
||||
"'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name 'file4'",
|
||||
"Resolving module name 'file4' relative to base url 'c:/root' - 'c:/root/file4'.",
|
||||
"File 'c:/root/file4.ts' does not exist.",
|
||||
"File 'c:/root/file4.tsx' does not exist.",
|
||||
"File 'c:/root/file4.d.ts' does not exist.",
|
||||
"File 'c:/root/folder2/file4.ts' does not exist.",
|
||||
"File 'c:/root/folder2/file4.tsx' does not exist.",
|
||||
"File 'c:/root/folder2/file4.d.ts' does not exist.",
|
||||
"File 'c:/root/file4.ts' does not exist.",
|
||||
"File 'c:/root/file4.tsx' does not exist.",
|
||||
"File 'c:/root/file4.d.ts' does not exist.",
|
||||
"File 'c:/file4.ts' exist - use it as a module resolution result.",
|
||||
"======== Module name 'file4' was successfully resolved to 'c:/file4.ts'. ========"
|
||||
|
||||
@ -14,7 +14,6 @@
|
||||
"Module name 'folder3/file2', matched pattern '*'.",
|
||||
"Trying substitution '*', candidate module location: 'folder3/file2'.",
|
||||
"File 'c:/root/folder3/file2.ts' does not exist.",
|
||||
"File 'c:/root/folder3/file2.tsx' does not exist.",
|
||||
"File 'c:/root/folder3/file2.d.ts' does not exist.",
|
||||
"Trying substitution 'generated/*', candidate module location: 'generated/folder3/file2'.",
|
||||
"File 'c:/root/generated/folder3/file2.ts' exist - use it as a module resolution result.",
|
||||
@ -34,17 +33,13 @@
|
||||
"Module name 'file4', matched pattern '*'.",
|
||||
"Trying substitution '*', candidate module location: 'file4'.",
|
||||
"File 'c:/root/file4.ts' does not exist.",
|
||||
"File 'c:/root/file4.tsx' does not exist.",
|
||||
"File 'c:/root/file4.d.ts' does not exist.",
|
||||
"Trying substitution 'generated/*', candidate module location: 'generated/file4'.",
|
||||
"File 'c:/root/generated/file4.ts' does not exist.",
|
||||
"File 'c:/root/generated/file4.tsx' does not exist.",
|
||||
"File 'c:/root/generated/file4.d.ts' does not exist.",
|
||||
"File 'c:/root/folder1/file4.ts' does not exist.",
|
||||
"File 'c:/root/folder1/file4.tsx' does not exist.",
|
||||
"File 'c:/root/folder1/file4.d.ts' does not exist.",
|
||||
"File 'c:/root/file4.ts' does not exist.",
|
||||
"File 'c:/root/file4.tsx' does not exist.",
|
||||
"File 'c:/root/file4.d.ts' does not exist.",
|
||||
"File 'c:/file4.ts' exist - use it as a module resolution result.",
|
||||
"======== Module name 'file4' was successfully resolved to 'c:/file4.ts'. ========"
|
||||
|
||||
@ -7,7 +7,6 @@
|
||||
"Longest matching prefix for 'c:/root/src/project/file3' is 'c:/root/src/'",
|
||||
"Loading 'project/file3' from the root dir 'c:/root/src/', candidate location 'c:/root/src/project/file3'",
|
||||
"File 'c:/root/src/project/file3.ts' does not exist.",
|
||||
"File 'c:/root/src/project/file3.tsx' does not exist.",
|
||||
"File 'c:/root/src/project/file3.d.ts' does not exist.",
|
||||
"Trying other entries in 'rootDirs'",
|
||||
"Loading 'project/file3' from the root dir 'c:/root/generated/src', candidate location 'c:/root/generated/src/project/file3'",
|
||||
@ -21,12 +20,10 @@
|
||||
"Longest matching prefix for 'c:/root/generated/src/file2' is 'c:/root/generated/src/'",
|
||||
"Loading 'file2' from the root dir 'c:/root/generated/src/', candidate location 'c:/root/generated/src/file2'",
|
||||
"File 'c:/root/generated/src/file2.ts' does not exist.",
|
||||
"File 'c:/root/generated/src/file2.tsx' does not exist.",
|
||||
"File 'c:/root/generated/src/file2.d.ts' does not exist.",
|
||||
"Trying other entries in 'rootDirs'",
|
||||
"Loading 'file2' from the root dir 'c:/root/src', candidate location 'c:/root/src/file2'",
|
||||
"File 'c:/root/src/file2.ts' does not exist.",
|
||||
"File 'c:/root/src/file2.tsx' does not exist.",
|
||||
"File 'c:/root/src/file2.d.ts' exist - use it as a module resolution result.",
|
||||
"======== Module name '../file2' was successfully resolved to 'c:/root/src/file2.d.ts'. ========"
|
||||
]
|
||||
@ -7,7 +7,6 @@
|
||||
"Longest matching prefix for 'c:/root/src/project/file2' is 'c:/root/src/'",
|
||||
"Loading 'project/file2' from the root dir 'c:/root/src/', candidate location 'c:/root/src/project/file2'",
|
||||
"File 'c:/root/src/project/file2.ts' does not exist.",
|
||||
"File 'c:/root/src/project/file2.tsx' does not exist.",
|
||||
"File 'c:/root/src/project/file2.d.ts' does not exist.",
|
||||
"Trying other entries in 'rootDirs'",
|
||||
"Loading 'project/file2' from the root dir 'c:/root/generated/src', candidate location 'c:/root/generated/src/project/file2'",
|
||||
@ -20,20 +19,15 @@
|
||||
"Module name 'module3', matched pattern '*'.",
|
||||
"Trying substitution '*', candidate module location: 'module3'.",
|
||||
"File 'c:/root/module3.ts' does not exist.",
|
||||
"File 'c:/root/module3.tsx' does not exist.",
|
||||
"File 'c:/root/module3.d.ts' does not exist.",
|
||||
"Trying substitution 'c:/shared/*', candidate module location: 'c:/shared/module3'.",
|
||||
"File 'c:/shared/module3.ts' does not exist.",
|
||||
"File 'c:/shared/module3.tsx' does not exist.",
|
||||
"File 'c:/shared/module3.d.ts' does not exist.",
|
||||
"File 'c:/root/src/module3.ts' does not exist.",
|
||||
"File 'c:/root/src/module3.tsx' does not exist.",
|
||||
"File 'c:/root/src/module3.d.ts' does not exist.",
|
||||
"File 'c:/root/module3.ts' does not exist.",
|
||||
"File 'c:/root/module3.tsx' does not exist.",
|
||||
"File 'c:/root/module3.d.ts' does not exist.",
|
||||
"File 'c:/module3.ts' does not exist.",
|
||||
"File 'c:/module3.tsx' does not exist.",
|
||||
"File 'c:/module3.d.ts' exist - use it as a module resolution result.",
|
||||
"======== Module name 'module3' was successfully resolved to 'c:/module3.d.ts'. ========",
|
||||
"======== Resolving module 'module1' from 'c:/root/generated/src/project/file2.ts'. ========",
|
||||
@ -43,11 +37,9 @@
|
||||
"Module name 'module1', matched pattern '*'.",
|
||||
"Trying substitution '*', candidate module location: 'module1'.",
|
||||
"File 'c:/root/module1.ts' does not exist.",
|
||||
"File 'c:/root/module1.tsx' does not exist.",
|
||||
"File 'c:/root/module1.d.ts' does not exist.",
|
||||
"Trying substitution 'c:/shared/*', candidate module location: 'c:/shared/module1'.",
|
||||
"File 'c:/shared/module1.ts' does not exist.",
|
||||
"File 'c:/shared/module1.tsx' does not exist.",
|
||||
"File 'c:/shared/module1.d.ts' exist - use it as a module resolution result.",
|
||||
"======== Module name 'module1' was successfully resolved to 'c:/shared/module1.d.ts'. ========",
|
||||
"======== Resolving module 'templates/module2' from 'c:/root/generated/src/project/file2.ts'. ========",
|
||||
@ -66,12 +58,10 @@
|
||||
"Longest matching prefix for 'c:/root/generated/src/file3' is 'c:/root/generated/src/'",
|
||||
"Loading 'file3' from the root dir 'c:/root/generated/src/', candidate location 'c:/root/generated/src/file3'",
|
||||
"File 'c:/root/generated/src/file3.ts' does not exist.",
|
||||
"File 'c:/root/generated/src/file3.tsx' does not exist.",
|
||||
"File 'c:/root/generated/src/file3.d.ts' does not exist.",
|
||||
"Trying other entries in 'rootDirs'",
|
||||
"Loading 'file3' from the root dir 'c:/root/src', candidate location 'c:/root/src/file3'",
|
||||
"File 'c:/root/src/file3.ts' does not exist.",
|
||||
"File 'c:/root/src/file3.tsx' does not exist.",
|
||||
"File 'c:/root/src/file3.d.ts' exist - use it as a module resolution result.",
|
||||
"======== Module name '../file3' was successfully resolved to 'c:/root/src/file3.d.ts'. ========"
|
||||
]
|
||||
@ -532,7 +532,7 @@ import b = require("./moduleB.ts");
|
||||
const m1: File = { name: "/root/x/m1.ts" }; // load from base url
|
||||
const m2: File = { name: "/m2.ts" }; // fallback to classic
|
||||
|
||||
const options: CompilerOptions = { moduleResolution: ModuleResolutionKind.Classic, baseUrl: "/root/x" };
|
||||
const options: CompilerOptions = { moduleResolution: ModuleResolutionKind.Classic, baseUrl: "/root/x", jsx: JsxEmit.React };
|
||||
const host = createModuleResolutionHost(hasDirectoryExists, main, m1, m2);
|
||||
|
||||
check("m1", main, m1);
|
||||
@ -565,6 +565,7 @@ import b = require("./moduleB.ts");
|
||||
const options: CompilerOptions = {
|
||||
moduleResolution: ModuleResolutionKind.NodeJs,
|
||||
baseUrl: "/root",
|
||||
jsx: JsxEmit.React,
|
||||
paths: {
|
||||
"*": [
|
||||
"*",
|
||||
@ -676,8 +677,8 @@ import b = require("./moduleB.ts");
|
||||
});
|
||||
|
||||
it ("classic + baseUrl + path mappings", () => {
|
||||
// classic mode does not use directoryExists
|
||||
test(/*hasDirectoryExists*/ false);
|
||||
test(/*hasDirectoryExists*/ true);
|
||||
|
||||
function test(hasDirectoryExists: boolean) {
|
||||
const main: File = { name: "/root/folder1/main.ts" };
|
||||
@ -690,6 +691,7 @@ import b = require("./moduleB.ts");
|
||||
const options: CompilerOptions = {
|
||||
moduleResolution: ModuleResolutionKind.Classic,
|
||||
baseUrl: "/root",
|
||||
jsx: JsxEmit.React,
|
||||
paths: {
|
||||
"*": [
|
||||
"*",
|
||||
@ -822,6 +824,7 @@ import b = require("./moduleB.ts");
|
||||
const host = createModuleResolutionHost(hasDirectoryExists, file1, file2, file3, file4);
|
||||
const options: CompilerOptions = {
|
||||
moduleResolution: ModuleResolutionKind.Classic,
|
||||
jsx: JsxEmit.React,
|
||||
rootDirs: [
|
||||
"/root",
|
||||
"/root/generated/"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user