diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index 4906abc8f8cc7..9dadbce2f8403 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -675,6 +675,9 @@ namespace ts { function tryLoadModuleUsingOptionalResolutionSettings(extensions: Extensions, moduleName: string, containingDirectory: string, loader: ResolutionKindSpecificLoader, state: ModuleResolutionState): Resolved | undefined { + const resolved = tryLoadModuleUsingPathsIfEligible(extensions, moduleName, loader, state); + if (resolved) return resolved.value; + if (!isExternalModuleNameRelative(moduleName)) { return tryLoadModuleUsingBaseUrl(extensions, moduleName, loader, state); } @@ -683,6 +686,24 @@ namespace ts { } } + function tryLoadModuleUsingPathsIfEligible(extensions: Extensions, moduleName: string, loader: ResolutionKindSpecificLoader, state: ModuleResolutionState) { + const { baseUrl, paths } = state.compilerOptions; + if (baseUrl && paths && isEligibleForPathMapping(moduleName, paths)) { + if (state.traceEnabled) trace(state.host, Diagnostics.paths_option_is_specified_looking_for_a_pattern_to_match_module_name_0, moduleName); + return tryLoadModuleUsingPaths(extensions, moduleName, baseUrl, paths, loader, /*onlyRecordFailures*/ false, state); + } + } + + function isEligibleForPathMapping(moduleName: string, paths: MapLike): boolean { + if (isRootedDiskPath(moduleName) || isUrl(moduleName)) { + // check for potential alias otherwise { '*': './src/*' } will match + const root = moduleName.slice(0, getRootLength(moduleName)); + const potentialAlias = getOwnKeys(paths).find(path => path.startsWith(root)); + return Boolean(potentialAlias); + } + else return !pathIsRelative(moduleName); + } + function tryLoadModuleUsingRootDirs(extensions: Extensions, moduleName: string, containingDirectory: string, loader: ResolutionKindSpecificLoader, state: ModuleResolutionState): Resolved | undefined { @@ -761,22 +782,13 @@ namespace ts { } function tryLoadModuleUsingBaseUrl(extensions: Extensions, moduleName: string, loader: ResolutionKindSpecificLoader, state: ModuleResolutionState): Resolved | undefined { - const { baseUrl, paths } = state.compilerOptions; + const { baseUrl } = state.compilerOptions; if (!baseUrl) { return undefined; } if (state.traceEnabled) { trace(state.host, Diagnostics.baseUrl_option_is_set_to_0_using_this_value_to_resolve_non_relative_module_name_1, baseUrl, moduleName); } - if (paths) { - if (state.traceEnabled) { - trace(state.host, Diagnostics.paths_option_is_specified_looking_for_a_pattern_to_match_module_name_0, moduleName); - } - const resolved = tryLoadModuleUsingPaths(extensions, moduleName, baseUrl, paths, loader, /*onlyRecordFailures*/ false, state); - if (resolved) { - return resolved.value; - } - } const candidate = normalizePath(combinePaths(baseUrl, moduleName)); if (state.traceEnabled) { trace(state.host, Diagnostics.Resolving_module_name_0_relative_to_base_url_1_2, moduleName, baseUrl, candidate); diff --git a/src/services/pathCompletions.ts b/src/services/pathCompletions.ts index 22cc56903c0fc..1e709ae936120 100644 --- a/src/services/pathCompletions.ts +++ b/src/services/pathCompletions.ts @@ -26,21 +26,33 @@ namespace ts.Completions.PathCompletions { const scriptPath = sourceFile.path; const scriptDirectory = getDirectoryPath(scriptPath); - if (isPathRelativeToScript(literalValue) || isRootedDiskPath(literalValue)) { - const extensions = getSupportedExtensionsForModuleResolution(compilerOptions); - if (compilerOptions.rootDirs) { - return getCompletionEntriesForDirectoryFragmentWithRootDirs( - compilerOptions.rootDirs, literalValue, scriptDirectory, extensions, /*includeExtensions*/ false, compilerOptions, host, scriptPath); + if (isRootedDiskPath(literalValue) || isUrl(literalValue)) { + if (compilerOptions.baseUrl) { + return getCompletionEntriesForNonRelativeModules(literalValue, scriptDirectory, compilerOptions, host, typeChecker); } else { - return getCompletionEntriesForDirectoryFragment(literalValue, scriptDirectory, extensions, /*includeExtensions*/ false, host, scriptPath); + return getCompletionEntriesForRelativeModules(literalValue, scriptDirectory, compilerOptions, host, scriptPath); } } + else if (isPathRelativeToScript(literalValue)) { + return getCompletionEntriesForRelativeModules(literalValue, scriptDirectory, compilerOptions, host, scriptPath); + } else { return getCompletionEntriesForNonRelativeModules(literalValue, scriptDirectory, compilerOptions, host, typeChecker); } } + function getCompletionEntriesForRelativeModules(literalValue: string, scriptDirectory: string, compilerOptions: CompilerOptions, host: LanguageServiceHost, scriptPath: Path) { + const extensions = getSupportedExtensionsForModuleResolution(compilerOptions); + if (compilerOptions.rootDirs) { + return getCompletionEntriesForDirectoryFragmentWithRootDirs( + compilerOptions.rootDirs, literalValue, scriptDirectory, extensions, /*includeExtensions*/ false, compilerOptions, host, scriptPath); + } + else { + return getCompletionEntriesForDirectoryFragment(literalValue, scriptDirectory, extensions, /*includeExtensions*/ false, host, scriptPath); + } + } + function getSupportedExtensionsForModuleResolution(compilerOptions: CompilerOptions) { const extensions = getSupportedExtensions(compilerOptions); return compilerOptions.resolveJsonModule && getEmitModuleResolutionKind(compilerOptions) === ModuleResolutionKind.NodeJs ? diff --git a/src/testRunner/unittests/moduleResolution.ts b/src/testRunner/unittests/moduleResolution.ts index 27331d6d007af..05e17384978f9 100644 --- a/src/testRunner/unittests/moduleResolution.ts +++ b/src/testRunner/unittests/moduleResolution.ts @@ -757,6 +757,9 @@ import b = require("./moduleB"); ], "somefolder/*": [ "someanotherfolder/*" + ], + "/rooted/*": [ + "generated/*" ] } }; @@ -773,6 +776,7 @@ import b = require("./moduleB"); "/root/folder1/file2/index.d.ts", // then first attempt on 'generated/*' was successful ]); + check("/rooted/folder1/file2", file2, []); check("folder2/file3", file3, [ // first try '*' "/root/folder2/file3.ts", @@ -900,6 +904,9 @@ import b = require("./moduleB"); ], "somefolder/*": [ "someanotherfolder/*" + ], + "/rooted/*": [ + "generated/*" ] } }; @@ -911,6 +918,7 @@ import b = require("./moduleB"); "/root/folder1/file2.d.ts", // success when using 'generated/*' ]); + check("/rooted/folder1/file2", file2, []); check("folder1/file3", file3, [ // first try '*' "/root/folder1/file3.ts", diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution5_classic.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution5_classic.trace.json index 4fa08fc9cc1d4..45a6cf286d870 100644 --- a/tests/baselines/reference/pathMappingBasedModuleResolution5_classic.trace.json +++ b/tests/baselines/reference/pathMappingBasedModuleResolution5_classic.trace.json @@ -1,7 +1,6 @@ [ "======== Resolving module 'folder2/file1' from 'c:/root/folder1/file1.ts'. ========", "Module resolution kind is not specified, using 'Classic'.", - "'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name 'folder2/file1'.", "'paths' option is specified, looking for a pattern to match module name 'folder2/file1'.", "Module name 'folder2/file1', matched pattern '*'.", "Trying substitution '*', candidate module location: 'folder2/file1'.", @@ -9,7 +8,6 @@ "======== Module name 'folder2/file1' was successfully resolved to 'c:/root/folder2/file1.ts'. ========", "======== Resolving module 'folder3/file2' from 'c:/root/folder1/file1.ts'. ========", "Module resolution kind is not specified, using 'Classic'.", - "'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name 'folder3/file2'.", "'paths' option is specified, looking for a pattern to match module name 'folder3/file2'.", "Module name 'folder3/file2', matched pattern '*'.", "Trying substitution '*', candidate module location: 'folder3/file2'.", @@ -18,7 +16,6 @@ "======== Module name 'folder3/file2' was successfully resolved to 'c:/root/generated/folder3/file2.ts'. ========", "======== Resolving module 'components/file3' from 'c:/root/folder1/file1.ts'. ========", "Module resolution kind is not specified, using 'Classic'.", - "'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name 'components/file3'.", "'paths' option is specified, looking for a pattern to match module name 'components/file3'.", "Module name 'components/file3', matched pattern 'components/*'.", "Trying substitution 'shared/components/*', candidate module location: 'shared/components/file3'.", @@ -26,7 +23,6 @@ "======== Module name 'components/file3' was successfully resolved to 'c:/root/shared/components/file3.ts'. ========", "======== Resolving module 'file4' from 'c:/root/folder1/file1.ts'. ========", "Module resolution kind is not specified, using 'Classic'.", - "'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name 'file4'.", "'paths' option is specified, looking for a pattern to match module name 'file4'.", "Module name 'file4', matched pattern '*'.", "Trying substitution '*', candidate module location: 'file4'.", diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution5_node.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution5_node.trace.json index 3b6710408fc0f..a86b40c881226 100644 --- a/tests/baselines/reference/pathMappingBasedModuleResolution5_node.trace.json +++ b/tests/baselines/reference/pathMappingBasedModuleResolution5_node.trace.json @@ -1,7 +1,6 @@ [ "======== Resolving module 'folder2/file1' from 'c:/root/folder1/file1.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", - "'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name 'folder2/file1'.", "'paths' option is specified, looking for a pattern to match module name 'folder2/file1'.", "Module name 'folder2/file1', matched pattern '*'.", "Trying substitution '*', candidate module location: 'folder2/file1'.", @@ -10,7 +9,6 @@ "======== Module name 'folder2/file1' was successfully resolved to 'c:/root/folder2/file1.ts'. ========", "======== Resolving module 'folder3/file2' from 'c:/root/folder1/file1.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", - "'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name 'folder3/file2'.", "'paths' option is specified, looking for a pattern to match module name 'folder3/file2'.", "Module name 'folder3/file2', matched pattern '*'.", "Trying substitution '*', candidate module location: 'folder3/file2'.", @@ -21,7 +19,6 @@ "======== Module name 'folder3/file2' was successfully resolved to 'c:/root/generated/folder3/file2.ts'. ========", "======== Resolving module 'components/file3' from 'c:/root/folder1/file1.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", - "'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name 'components/file3'.", "'paths' option is specified, looking for a pattern to match module name 'components/file3'.", "Module name 'components/file3', matched pattern 'components/*'.", "Trying substitution 'shared/components/*', candidate module location: 'shared/components/file3'.", @@ -36,7 +33,6 @@ "======== Module name 'components/file3' was successfully resolved to 'c:/root/shared/components/file3/index.d.ts'. ========", "======== Resolving module 'file4' from 'c:/root/folder1/file1.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", - "'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name 'file4'.", "'paths' option is specified, looking for a pattern to match module name 'file4'.", "Module name 'file4', matched pattern '*'.", "Trying substitution '*', candidate module location: 'file4'.", diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution7_classic.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution7_classic.trace.json index 78a273ae0593b..3b6c754b72b8a 100644 --- a/tests/baselines/reference/pathMappingBasedModuleResolution7_classic.trace.json +++ b/tests/baselines/reference/pathMappingBasedModuleResolution7_classic.trace.json @@ -12,7 +12,6 @@ "======== Module name './project/file2' was successfully resolved to 'c:/root/generated/src/project/file2.ts'. ========", "======== Resolving module 'module3' from 'c:/root/src/file1.ts'. ========", "Module resolution kind is not specified, using 'Classic'.", - "'baseUrl' option is set to 'c:/root/', using this value to resolve non-relative module name 'module3'.", "'paths' option is specified, looking for a pattern to match module name 'module3'.", "Module name 'module3', matched pattern '*'.", "Trying substitution '*', candidate module location: 'module3'.", @@ -35,7 +34,6 @@ "======== Module name 'module3' was successfully resolved to 'c:/module3.d.ts'. ========", "======== Resolving module 'module1' from 'c:/root/generated/src/project/file2.ts'. ========", "Module resolution kind is not specified, using 'Classic'.", - "'baseUrl' option is set to 'c:/root/', using this value to resolve non-relative module name 'module1'.", "'paths' option is specified, looking for a pattern to match module name 'module1'.", "Module name 'module1', matched pattern '*'.", "Trying substitution '*', candidate module location: 'module1'.", @@ -49,7 +47,6 @@ "======== Module name 'module1' was successfully resolved to 'c:/shared/module1.d.ts'. ========", "======== Resolving module 'templates/module2' from 'c:/root/generated/src/project/file2.ts'. ========", "Module resolution kind is not specified, using 'Classic'.", - "'baseUrl' option is set to 'c:/root/', using this value to resolve non-relative module name 'templates/module2'.", "'paths' option is specified, looking for a pattern to match module name 'templates/module2'.", "Module name 'templates/module2', matched pattern 'templates/*'.", "Trying substitution 'generated/src/templates/*', candidate module location: 'generated/src/templates/module2'.", diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution7_node.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution7_node.trace.json index 50e4a6fabeb4e..389b959d54798 100644 --- a/tests/baselines/reference/pathMappingBasedModuleResolution7_node.trace.json +++ b/tests/baselines/reference/pathMappingBasedModuleResolution7_node.trace.json @@ -15,7 +15,6 @@ "======== Module name './project/file2' was successfully resolved to 'c:/root/generated/src/project/file2.ts'. ========", "======== Resolving module 'module3' from 'c:/root/src/file1.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", - "'baseUrl' option is set to 'c:/root/', using this value to resolve non-relative module name 'module3'.", "'paths' option is specified, looking for a pattern to match module name 'module3'.", "Module name 'module3', matched pattern '*'.", "Trying substitution '*', candidate module location: 'module3'.", @@ -40,7 +39,6 @@ "======== Module name 'module3' was successfully resolved to 'c:/node_modules/module3.d.ts'. ========", "======== Resolving module 'module1' from 'c:/root/generated/src/project/file2.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", - "'baseUrl' option is set to 'c:/root/', using this value to resolve non-relative module name 'module1'.", "'paths' option is specified, looking for a pattern to match module name 'module1'.", "Module name 'module1', matched pattern '*'.", "Trying substitution '*', candidate module location: 'module1'.", @@ -61,7 +59,6 @@ "======== Module name 'module1' was successfully resolved to 'c:/shared/module1/index.d.ts'. ========", "======== Resolving module 'templates/module2' from 'c:/root/generated/src/project/file2.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", - "'baseUrl' option is set to 'c:/root/', using this value to resolve non-relative module name 'templates/module2'.", "'paths' option is specified, looking for a pattern to match module name 'templates/module2'.", "Module name 'templates/module2', matched pattern 'templates/*'.", "Trying substitution 'generated/src/templates/*', candidate module location: 'generated/src/templates/module2'.", diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution8_classic.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution8_classic.trace.json index 2f236bda9be9a..d4c527b3f940d 100644 --- a/tests/baselines/reference/pathMappingBasedModuleResolution8_classic.trace.json +++ b/tests/baselines/reference/pathMappingBasedModuleResolution8_classic.trace.json @@ -1,7 +1,6 @@ [ "======== Resolving module '@speedy/folder1/testing' from 'c:/root/index.ts'. ========", "Explicitly specified module resolution kind: 'Classic'.", - "'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name '@speedy/folder1/testing'.", "'paths' option is specified, looking for a pattern to match module name '@speedy/folder1/testing'.", "Module name '@speedy/folder1/testing', matched pattern '@speedy/*/testing'.", "Trying substitution '*/dist/index.ts', candidate module location: 'folder1/dist/index.ts'.", diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution8_node.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution8_node.trace.json index dc6c614fa645d..c3086642262cb 100644 --- a/tests/baselines/reference/pathMappingBasedModuleResolution8_node.trace.json +++ b/tests/baselines/reference/pathMappingBasedModuleResolution8_node.trace.json @@ -1,7 +1,6 @@ [ "======== Resolving module '@speedy/folder1/testing' from 'c:/root/index.ts'. ========", "Explicitly specified module resolution kind: 'NodeJs'.", - "'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name '@speedy/folder1/testing'.", "'paths' option is specified, looking for a pattern to match module name '@speedy/folder1/testing'.", "Module name '@speedy/folder1/testing', matched pattern '@speedy/*/testing'.", "Trying substitution '*/dist/index.ts', candidate module location: 'folder1/dist/index.ts'.", diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot.js b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot.js new file mode 100644 index 0000000000000..b880a69fe2d41 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot.js @@ -0,0 +1,26 @@ +//// [tests/cases/compiler/pathMappingBasedModuleResolution_rootImport_aliasWithRoot.ts] //// + +//// [foo.ts] +export function foo() {} + +//// [bar.js] +export function bar() {} + +//// [a.ts] +import { foo } from "/foo"; +import { bar } from "/bar"; + + +//// [foo.js] +"use strict"; +exports.__esModule = true; +function foo() { } +exports.foo = foo; +//// [bar.js] +"use strict"; +exports.__esModule = true; +function bar() { } +exports.bar = bar; +//// [a.js] +"use strict"; +exports.__esModule = true; diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot.symbols b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot.symbols new file mode 100644 index 0000000000000..3509e873a6528 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot.symbols @@ -0,0 +1,15 @@ +=== /root/a.ts === +import { foo } from "/foo"; +>foo : Symbol(foo, Decl(a.ts, 0, 8)) + +import { bar } from "/bar"; +>bar : Symbol(bar, Decl(a.ts, 1, 8)) + +=== /root/src/foo.ts === +export function foo() {} +>foo : Symbol(foo, Decl(foo.ts, 0, 0)) + +=== /root/src/bar.js === +export function bar() {} +>bar : Symbol(bar, Decl(bar.js, 0, 0)) + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot.trace.json new file mode 100644 index 0000000000000..4ca81f3b20520 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot.trace.json @@ -0,0 +1,31 @@ +[ + "======== Resolving module '/foo' from '/root/a.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "'paths' option is specified, looking for a pattern to match module name '/foo'.", + "Module name '/foo', matched pattern '/*'.", + "Trying substitution './src/*', candidate module location: './src/foo'.", + "Loading module as file / folder, candidate module location '/root/src/foo', target file type 'TypeScript'.", + "File '/root/src/foo.ts' exist - use it as a name resolution result.", + "======== Module name '/foo' was successfully resolved to '/root/src/foo.ts'. ========", + "======== Resolving module '/bar' from '/root/a.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "'paths' option is specified, looking for a pattern to match module name '/bar'.", + "Module name '/bar', matched pattern '/*'.", + "Trying substitution './src/*', candidate module location: './src/bar'.", + "Loading module as file / folder, candidate module location '/root/src/bar', target file type 'TypeScript'.", + "File '/root/src/bar.ts' does not exist.", + "File '/root/src/bar.tsx' does not exist.", + "File '/root/src/bar.d.ts' does not exist.", + "Directory '/root/src/bar' does not exist, skipping all lookups in it.", + "Loading module as file / folder, candidate module location '/bar', target file type 'TypeScript'.", + "File '/bar.ts' does not exist.", + "File '/bar.tsx' does not exist.", + "File '/bar.d.ts' does not exist.", + "Directory '/bar' does not exist, skipping all lookups in it.", + "'paths' option is specified, looking for a pattern to match module name '/bar'.", + "Module name '/bar', matched pattern '/*'.", + "Trying substitution './src/*', candidate module location: './src/bar'.", + "Loading module as file / folder, candidate module location '/root/src/bar', target file type 'JavaScript'.", + "File '/root/src/bar.js' exist - use it as a name resolution result.", + "======== Module name '/bar' was successfully resolved to '/root/src/bar.js'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot.types b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot.types new file mode 100644 index 0000000000000..67c03269afe7a --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot.types @@ -0,0 +1,15 @@ +=== /root/a.ts === +import { foo } from "/foo"; +>foo : () => void + +import { bar } from "/bar"; +>bar : () => void + +=== /root/src/foo.ts === +export function foo() {} +>foo : () => void + +=== /root/src/bar.js === +export function bar() {} +>bar : () => void + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_differentRootTypes.js b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_differentRootTypes.js new file mode 100644 index 0000000000000..a7e74a35a45e7 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_differentRootTypes.js @@ -0,0 +1,42 @@ +//// [tests/cases/compiler/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_differentRootTypes.ts] //// + +//// [foo.ts] +export function foo() {} + +//// [bar.js] +export function bar() {} + +//// [a.ts] +import { foo as foo1 } from "/foo"; +import { bar as bar1 } from "/bar"; +import { foo as foo2 } from "c:/foo"; +import { bar as bar2 } from "c:/bar"; +import { foo as foo3 } from "c:\\foo"; +import { bar as bar3 } from "c:\\bar"; +import { foo as foo4 } from "//server/foo"; +import { bar as bar4 } from "//server/bar"; +import { foo as foo5 } from "\\\\server\\foo"; +import { bar as bar5 } from "\\\\server\\bar"; +import { foo as foo6 } from "file:///foo"; +import { bar as bar6 } from "file:///bar"; +import { foo as foo7 } from "file://c:/foo"; +import { bar as bar7 } from "file://c:/bar"; +import { foo as foo8 } from "file://server/foo"; +import { bar as bar8 } from "file://server/bar"; +import { foo as foo9 } from "http://server/foo"; +import { bar as bar9 } from "http://server/bar"; + + +//// [foo.js] +"use strict"; +exports.__esModule = true; +function foo() { } +exports.foo = foo; +//// [bar.js] +"use strict"; +exports.__esModule = true; +function bar() { } +exports.bar = bar; +//// [a.js] +"use strict"; +exports.__esModule = true; diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_differentRootTypes.symbols b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_differentRootTypes.symbols new file mode 100644 index 0000000000000..5572ccfb5d02c --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_differentRootTypes.symbols @@ -0,0 +1,81 @@ +=== /root/a.ts === +import { foo as foo1 } from "/foo"; +>foo : Symbol(foo1, Decl(a.ts, 0, 8)) +>foo1 : Symbol(foo1, Decl(a.ts, 0, 8)) + +import { bar as bar1 } from "/bar"; +>bar : Symbol(bar1, Decl(a.ts, 1, 8)) +>bar1 : Symbol(bar1, Decl(a.ts, 1, 8)) + +import { foo as foo2 } from "c:/foo"; +>foo : Symbol(foo2, Decl(a.ts, 2, 8)) +>foo2 : Symbol(foo2, Decl(a.ts, 2, 8)) + +import { bar as bar2 } from "c:/bar"; +>bar : Symbol(bar2, Decl(a.ts, 3, 8)) +>bar2 : Symbol(bar2, Decl(a.ts, 3, 8)) + +import { foo as foo3 } from "c:\\foo"; +>foo : Symbol(foo3, Decl(a.ts, 4, 8)) +>foo3 : Symbol(foo3, Decl(a.ts, 4, 8)) + +import { bar as bar3 } from "c:\\bar"; +>bar : Symbol(bar3, Decl(a.ts, 5, 8)) +>bar3 : Symbol(bar3, Decl(a.ts, 5, 8)) + +import { foo as foo4 } from "//server/foo"; +>foo : Symbol(foo4, Decl(a.ts, 6, 8)) +>foo4 : Symbol(foo4, Decl(a.ts, 6, 8)) + +import { bar as bar4 } from "//server/bar"; +>bar : Symbol(bar4, Decl(a.ts, 7, 8)) +>bar4 : Symbol(bar4, Decl(a.ts, 7, 8)) + +import { foo as foo5 } from "\\\\server\\foo"; +>foo : Symbol(foo5, Decl(a.ts, 8, 8)) +>foo5 : Symbol(foo5, Decl(a.ts, 8, 8)) + +import { bar as bar5 } from "\\\\server\\bar"; +>bar : Symbol(bar5, Decl(a.ts, 9, 8)) +>bar5 : Symbol(bar5, Decl(a.ts, 9, 8)) + +import { foo as foo6 } from "file:///foo"; +>foo : Symbol(foo6, Decl(a.ts, 10, 8)) +>foo6 : Symbol(foo6, Decl(a.ts, 10, 8)) + +import { bar as bar6 } from "file:///bar"; +>bar : Symbol(bar6, Decl(a.ts, 11, 8)) +>bar6 : Symbol(bar6, Decl(a.ts, 11, 8)) + +import { foo as foo7 } from "file://c:/foo"; +>foo : Symbol(foo7, Decl(a.ts, 12, 8)) +>foo7 : Symbol(foo7, Decl(a.ts, 12, 8)) + +import { bar as bar7 } from "file://c:/bar"; +>bar : Symbol(bar7, Decl(a.ts, 13, 8)) +>bar7 : Symbol(bar7, Decl(a.ts, 13, 8)) + +import { foo as foo8 } from "file://server/foo"; +>foo : Symbol(foo8, Decl(a.ts, 14, 8)) +>foo8 : Symbol(foo8, Decl(a.ts, 14, 8)) + +import { bar as bar8 } from "file://server/bar"; +>bar : Symbol(bar8, Decl(a.ts, 15, 8)) +>bar8 : Symbol(bar8, Decl(a.ts, 15, 8)) + +import { foo as foo9 } from "http://server/foo"; +>foo : Symbol(foo9, Decl(a.ts, 16, 8)) +>foo9 : Symbol(foo9, Decl(a.ts, 16, 8)) + +import { bar as bar9 } from "http://server/bar"; +>bar : Symbol(bar9, Decl(a.ts, 17, 8)) +>bar9 : Symbol(bar9, Decl(a.ts, 17, 8)) + +=== /root/src/foo.ts === +export function foo() {} +>foo : Symbol(foo, Decl(foo.ts, 0, 0)) + +=== /root/src/bar.js === +export function bar() {} +>bar : Symbol(bar, Decl(bar.js, 0, 0)) + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_differentRootTypes.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_differentRootTypes.trace.json new file mode 100644 index 0000000000000..2f9d3f036d9e0 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_differentRootTypes.trace.json @@ -0,0 +1,243 @@ +[ + "======== Resolving module '/foo' from '/root/a.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "'paths' option is specified, looking for a pattern to match module name '/foo'.", + "Module name '/foo', matched pattern '/*'.", + "Trying substitution './src/*', candidate module location: './src/foo'.", + "Loading module as file / folder, candidate module location '/root/src/foo', target file type 'TypeScript'.", + "File '/root/src/foo.ts' exist - use it as a name resolution result.", + "======== Module name '/foo' was successfully resolved to '/root/src/foo.ts'. ========", + "======== Resolving module '/bar' from '/root/a.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "'paths' option is specified, looking for a pattern to match module name '/bar'.", + "Module name '/bar', matched pattern '/*'.", + "Trying substitution './src/*', candidate module location: './src/bar'.", + "Loading module as file / folder, candidate module location '/root/src/bar', target file type 'TypeScript'.", + "File '/root/src/bar.ts' does not exist.", + "File '/root/src/bar.tsx' does not exist.", + "File '/root/src/bar.d.ts' does not exist.", + "Directory '/root/src/bar' does not exist, skipping all lookups in it.", + "Loading module as file / folder, candidate module location '/bar', target file type 'TypeScript'.", + "File '/bar.ts' does not exist.", + "File '/bar.tsx' does not exist.", + "File '/bar.d.ts' does not exist.", + "Directory '/bar' does not exist, skipping all lookups in it.", + "'paths' option is specified, looking for a pattern to match module name '/bar'.", + "Module name '/bar', matched pattern '/*'.", + "Trying substitution './src/*', candidate module location: './src/bar'.", + "Loading module as file / folder, candidate module location '/root/src/bar', target file type 'JavaScript'.", + "File '/root/src/bar.js' exist - use it as a name resolution result.", + "======== Module name '/bar' was successfully resolved to '/root/src/bar.js'. ========", + "======== Resolving module 'c:/foo' from '/root/a.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "'paths' option is specified, looking for a pattern to match module name 'c:/foo'.", + "Module name 'c:/foo', matched pattern 'c:/*'.", + "Trying substitution './src/*', candidate module location: './src/foo'.", + "Loading module as file / folder, candidate module location '/root/src/foo', target file type 'TypeScript'.", + "File '/root/src/foo.ts' exist - use it as a name resolution result.", + "======== Module name 'c:/foo' was successfully resolved to '/root/src/foo.ts'. ========", + "======== Resolving module 'c:/bar' from '/root/a.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "'paths' option is specified, looking for a pattern to match module name 'c:/bar'.", + "Module name 'c:/bar', matched pattern 'c:/*'.", + "Trying substitution './src/*', candidate module location: './src/bar'.", + "Loading module as file / folder, candidate module location '/root/src/bar', target file type 'TypeScript'.", + "File '/root/src/bar.ts' does not exist.", + "File '/root/src/bar.tsx' does not exist.", + "File '/root/src/bar.d.ts' does not exist.", + "Directory '/root/src/bar' does not exist, skipping all lookups in it.", + "Loading module as file / folder, candidate module location 'c:/bar', target file type 'TypeScript'.", + "Directory 'c:/' does not exist, skipping all lookups in it.", + "'paths' option is specified, looking for a pattern to match module name 'c:/bar'.", + "Module name 'c:/bar', matched pattern 'c:/*'.", + "Trying substitution './src/*', candidate module location: './src/bar'.", + "Loading module as file / folder, candidate module location '/root/src/bar', target file type 'JavaScript'.", + "File '/root/src/bar.js' exist - use it as a name resolution result.", + "======== Module name 'c:/bar' was successfully resolved to '/root/src/bar.js'. ========", + "======== Resolving module 'c:\\foo' from '/root/a.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "'paths' option is specified, looking for a pattern to match module name 'c:\\foo'.", + "Module name 'c:\\foo', matched pattern 'c:\\*'.", + "Trying substitution './src/*', candidate module location: './src/foo'.", + "Loading module as file / folder, candidate module location '/root/src/foo', target file type 'TypeScript'.", + "File '/root/src/foo.ts' exist - use it as a name resolution result.", + "======== Module name 'c:\\foo' was successfully resolved to '/root/src/foo.ts'. ========", + "======== Resolving module 'c:\\bar' from '/root/a.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "'paths' option is specified, looking for a pattern to match module name 'c:\\bar'.", + "Module name 'c:\\bar', matched pattern 'c:\\*'.", + "Trying substitution './src/*', candidate module location: './src/bar'.", + "Loading module as file / folder, candidate module location '/root/src/bar', target file type 'TypeScript'.", + "File '/root/src/bar.ts' does not exist.", + "File '/root/src/bar.tsx' does not exist.", + "File '/root/src/bar.d.ts' does not exist.", + "Directory '/root/src/bar' does not exist, skipping all lookups in it.", + "Loading module as file / folder, candidate module location 'c:/bar', target file type 'TypeScript'.", + "Directory 'c:/' does not exist, skipping all lookups in it.", + "'paths' option is specified, looking for a pattern to match module name 'c:\\bar'.", + "Module name 'c:\\bar', matched pattern 'c:\\*'.", + "Trying substitution './src/*', candidate module location: './src/bar'.", + "Loading module as file / folder, candidate module location '/root/src/bar', target file type 'JavaScript'.", + "File '/root/src/bar.js' exist - use it as a name resolution result.", + "======== Module name 'c:\\bar' was successfully resolved to '/root/src/bar.js'. ========", + "======== Resolving module '//server/foo' from '/root/a.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "'paths' option is specified, looking for a pattern to match module name '//server/foo'.", + "Module name '//server/foo', matched pattern '//server/*'.", + "Trying substitution './src/*', candidate module location: './src/foo'.", + "Loading module as file / folder, candidate module location '/root/src/foo', target file type 'TypeScript'.", + "File '/root/src/foo.ts' exist - use it as a name resolution result.", + "======== Module name '//server/foo' was successfully resolved to '/root/src/foo.ts'. ========", + "======== Resolving module '//server/bar' from '/root/a.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "'paths' option is specified, looking for a pattern to match module name '//server/bar'.", + "Module name '//server/bar', matched pattern '//server/*'.", + "Trying substitution './src/*', candidate module location: './src/bar'.", + "Loading module as file / folder, candidate module location '/root/src/bar', target file type 'TypeScript'.", + "File '/root/src/bar.ts' does not exist.", + "File '/root/src/bar.tsx' does not exist.", + "File '/root/src/bar.d.ts' does not exist.", + "Directory '/root/src/bar' does not exist, skipping all lookups in it.", + "Loading module as file / folder, candidate module location '//server/bar', target file type 'TypeScript'.", + "Directory '//server/' does not exist, skipping all lookups in it.", + "'paths' option is specified, looking for a pattern to match module name '//server/bar'.", + "Module name '//server/bar', matched pattern '//server/*'.", + "Trying substitution './src/*', candidate module location: './src/bar'.", + "Loading module as file / folder, candidate module location '/root/src/bar', target file type 'JavaScript'.", + "File '/root/src/bar.js' exist - use it as a name resolution result.", + "======== Module name '//server/bar' was successfully resolved to '/root/src/bar.js'. ========", + "======== Resolving module '\\\\server\\foo' from '/root/a.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "'paths' option is specified, looking for a pattern to match module name '\\\\server\\foo'.", + "Module name '\\\\server\\foo', matched pattern '\\\\server\\*'.", + "Trying substitution './src/*', candidate module location: './src/foo'.", + "Loading module as file / folder, candidate module location '/root/src/foo', target file type 'TypeScript'.", + "File '/root/src/foo.ts' exist - use it as a name resolution result.", + "======== Module name '\\\\server\\foo' was successfully resolved to '/root/src/foo.ts'. ========", + "======== Resolving module '\\\\server\\bar' from '/root/a.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "'paths' option is specified, looking for a pattern to match module name '\\\\server\\bar'.", + "Module name '\\\\server\\bar', matched pattern '\\\\server\\*'.", + "Trying substitution './src/*', candidate module location: './src/bar'.", + "Loading module as file / folder, candidate module location '/root/src/bar', target file type 'TypeScript'.", + "File '/root/src/bar.ts' does not exist.", + "File '/root/src/bar.tsx' does not exist.", + "File '/root/src/bar.d.ts' does not exist.", + "Directory '/root/src/bar' does not exist, skipping all lookups in it.", + "Loading module as file / folder, candidate module location '//server/bar', target file type 'TypeScript'.", + "Directory '//server/' does not exist, skipping all lookups in it.", + "'paths' option is specified, looking for a pattern to match module name '\\\\server\\bar'.", + "Module name '\\\\server\\bar', matched pattern '\\\\server\\*'.", + "Trying substitution './src/*', candidate module location: './src/bar'.", + "Loading module as file / folder, candidate module location '/root/src/bar', target file type 'JavaScript'.", + "File '/root/src/bar.js' exist - use it as a name resolution result.", + "======== Module name '\\\\server\\bar' was successfully resolved to '/root/src/bar.js'. ========", + "======== Resolving module 'file:///foo' from '/root/a.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "'paths' option is specified, looking for a pattern to match module name 'file:///foo'.", + "Module name 'file:///foo', matched pattern 'file:///*'.", + "Trying substitution './src/*', candidate module location: './src/foo'.", + "Loading module as file / folder, candidate module location '/root/src/foo', target file type 'TypeScript'.", + "File '/root/src/foo.ts' exist - use it as a name resolution result.", + "======== Module name 'file:///foo' was successfully resolved to '/root/src/foo.ts'. ========", + "======== Resolving module 'file:///bar' from '/root/a.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "'paths' option is specified, looking for a pattern to match module name 'file:///bar'.", + "Module name 'file:///bar', matched pattern 'file:///*'.", + "Trying substitution './src/*', candidate module location: './src/bar'.", + "Loading module as file / folder, candidate module location '/root/src/bar', target file type 'TypeScript'.", + "File '/root/src/bar.ts' does not exist.", + "File '/root/src/bar.tsx' does not exist.", + "File '/root/src/bar.d.ts' does not exist.", + "Directory '/root/src/bar' does not exist, skipping all lookups in it.", + "Loading module 'file:///bar' from 'node_modules' folder, target file type 'TypeScript'.", + "Directory '/root/node_modules' does not exist, skipping all lookups in it.", + "Directory '/node_modules' does not exist, skipping all lookups in it.", + "'paths' option is specified, looking for a pattern to match module name 'file:///bar'.", + "Module name 'file:///bar', matched pattern 'file:///*'.", + "Trying substitution './src/*', candidate module location: './src/bar'.", + "Loading module as file / folder, candidate module location '/root/src/bar', target file type 'JavaScript'.", + "File '/root/src/bar.js' exist - use it as a name resolution result.", + "======== Module name 'file:///bar' was successfully resolved to '/root/src/bar.js'. ========", + "======== Resolving module 'file://c:/foo' from '/root/a.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "'paths' option is specified, looking for a pattern to match module name 'file://c:/foo'.", + "Module name 'file://c:/foo', matched pattern 'file://c:/*'.", + "Trying substitution './src/*', candidate module location: './src/foo'.", + "Loading module as file / folder, candidate module location '/root/src/foo', target file type 'TypeScript'.", + "File '/root/src/foo.ts' exist - use it as a name resolution result.", + "======== Module name 'file://c:/foo' was successfully resolved to '/root/src/foo.ts'. ========", + "======== Resolving module 'file://c:/bar' from '/root/a.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "'paths' option is specified, looking for a pattern to match module name 'file://c:/bar'.", + "Module name 'file://c:/bar', matched pattern 'file://c:/*'.", + "Trying substitution './src/*', candidate module location: './src/bar'.", + "Loading module as file / folder, candidate module location '/root/src/bar', target file type 'TypeScript'.", + "File '/root/src/bar.ts' does not exist.", + "File '/root/src/bar.tsx' does not exist.", + "File '/root/src/bar.d.ts' does not exist.", + "Directory '/root/src/bar' does not exist, skipping all lookups in it.", + "Loading module 'file://c:/bar' from 'node_modules' folder, target file type 'TypeScript'.", + "Directory '/root/node_modules' does not exist, skipping all lookups in it.", + "Directory '/node_modules' does not exist, skipping all lookups in it.", + "'paths' option is specified, looking for a pattern to match module name 'file://c:/bar'.", + "Module name 'file://c:/bar', matched pattern 'file://c:/*'.", + "Trying substitution './src/*', candidate module location: './src/bar'.", + "Loading module as file / folder, candidate module location '/root/src/bar', target file type 'JavaScript'.", + "File '/root/src/bar.js' exist - use it as a name resolution result.", + "======== Module name 'file://c:/bar' was successfully resolved to '/root/src/bar.js'. ========", + "======== Resolving module 'file://server/foo' from '/root/a.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "'paths' option is specified, looking for a pattern to match module name 'file://server/foo'.", + "Module name 'file://server/foo', matched pattern 'file://server/*'.", + "Trying substitution './src/*', candidate module location: './src/foo'.", + "Loading module as file / folder, candidate module location '/root/src/foo', target file type 'TypeScript'.", + "File '/root/src/foo.ts' exist - use it as a name resolution result.", + "======== Module name 'file://server/foo' was successfully resolved to '/root/src/foo.ts'. ========", + "======== Resolving module 'file://server/bar' from '/root/a.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "'paths' option is specified, looking for a pattern to match module name 'file://server/bar'.", + "Module name 'file://server/bar', matched pattern 'file://server/*'.", + "Trying substitution './src/*', candidate module location: './src/bar'.", + "Loading module as file / folder, candidate module location '/root/src/bar', target file type 'TypeScript'.", + "File '/root/src/bar.ts' does not exist.", + "File '/root/src/bar.tsx' does not exist.", + "File '/root/src/bar.d.ts' does not exist.", + "Directory '/root/src/bar' does not exist, skipping all lookups in it.", + "Loading module 'file://server/bar' from 'node_modules' folder, target file type 'TypeScript'.", + "Directory '/root/node_modules' does not exist, skipping all lookups in it.", + "Directory '/node_modules' does not exist, skipping all lookups in it.", + "'paths' option is specified, looking for a pattern to match module name 'file://server/bar'.", + "Module name 'file://server/bar', matched pattern 'file://server/*'.", + "Trying substitution './src/*', candidate module location: './src/bar'.", + "Loading module as file / folder, candidate module location '/root/src/bar', target file type 'JavaScript'.", + "File '/root/src/bar.js' exist - use it as a name resolution result.", + "======== Module name 'file://server/bar' was successfully resolved to '/root/src/bar.js'. ========", + "======== Resolving module 'http://server/foo' from '/root/a.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "'paths' option is specified, looking for a pattern to match module name 'http://server/foo'.", + "Module name 'http://server/foo', matched pattern 'http://server/*'.", + "Trying substitution './src/*', candidate module location: './src/foo'.", + "Loading module as file / folder, candidate module location '/root/src/foo', target file type 'TypeScript'.", + "File '/root/src/foo.ts' exist - use it as a name resolution result.", + "======== Module name 'http://server/foo' was successfully resolved to '/root/src/foo.ts'. ========", + "======== Resolving module 'http://server/bar' from '/root/a.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "'paths' option is specified, looking for a pattern to match module name 'http://server/bar'.", + "Module name 'http://server/bar', matched pattern 'http://server/*'.", + "Trying substitution './src/*', candidate module location: './src/bar'.", + "Loading module as file / folder, candidate module location '/root/src/bar', target file type 'TypeScript'.", + "File '/root/src/bar.ts' does not exist.", + "File '/root/src/bar.tsx' does not exist.", + "File '/root/src/bar.d.ts' does not exist.", + "Directory '/root/src/bar' does not exist, skipping all lookups in it.", + "Loading module 'http://server/bar' from 'node_modules' folder, target file type 'TypeScript'.", + "Directory '/root/node_modules' does not exist, skipping all lookups in it.", + "Directory '/node_modules' does not exist, skipping all lookups in it.", + "'paths' option is specified, looking for a pattern to match module name 'http://server/bar'.", + "Module name 'http://server/bar', matched pattern 'http://server/*'.", + "Trying substitution './src/*', candidate module location: './src/bar'.", + "Loading module as file / folder, candidate module location '/root/src/bar', target file type 'JavaScript'.", + "File '/root/src/bar.js' exist - use it as a name resolution result.", + "======== Module name 'http://server/bar' was successfully resolved to '/root/src/bar.js'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_differentRootTypes.types b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_differentRootTypes.types new file mode 100644 index 0000000000000..17c00ec2ccb64 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_differentRootTypes.types @@ -0,0 +1,81 @@ +=== /root/a.ts === +import { foo as foo1 } from "/foo"; +>foo : () => void +>foo1 : () => void + +import { bar as bar1 } from "/bar"; +>bar : () => void +>bar1 : () => void + +import { foo as foo2 } from "c:/foo"; +>foo : () => void +>foo2 : () => void + +import { bar as bar2 } from "c:/bar"; +>bar : () => void +>bar2 : () => void + +import { foo as foo3 } from "c:\\foo"; +>foo : () => void +>foo3 : () => void + +import { bar as bar3 } from "c:\\bar"; +>bar : () => void +>bar3 : () => void + +import { foo as foo4 } from "//server/foo"; +>foo : () => void +>foo4 : () => void + +import { bar as bar4 } from "//server/bar"; +>bar : () => void +>bar4 : () => void + +import { foo as foo5 } from "\\\\server\\foo"; +>foo : () => void +>foo5 : () => void + +import { bar as bar5 } from "\\\\server\\bar"; +>bar : () => void +>bar5 : () => void + +import { foo as foo6 } from "file:///foo"; +>foo : () => void +>foo6 : () => void + +import { bar as bar6 } from "file:///bar"; +>bar : () => void +>bar6 : () => void + +import { foo as foo7 } from "file://c:/foo"; +>foo : () => void +>foo7 : () => void + +import { bar as bar7 } from "file://c:/bar"; +>bar : () => void +>bar7 : () => void + +import { foo as foo8 } from "file://server/foo"; +>foo : () => void +>foo8 : () => void + +import { bar as bar8 } from "file://server/bar"; +>bar : () => void +>bar8 : () => void + +import { foo as foo9 } from "http://server/foo"; +>foo : () => void +>foo9 : () => void + +import { bar as bar9 } from "http://server/bar"; +>bar : () => void +>bar9 : () => void + +=== /root/src/foo.ts === +export function foo() {} +>foo : () => void + +=== /root/src/bar.js === +export function bar() {} +>bar : () => void + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_multipleAliases.js b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_multipleAliases.js new file mode 100644 index 0000000000000..59b7c08567628 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_multipleAliases.js @@ -0,0 +1,26 @@ +//// [tests/cases/compiler/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_multipleAliases.ts] //// + +//// [foo.ts] +export function foo() {} + +//// [bar.js] +export function bar() {} + +//// [a.ts] +import { foo } from "/import/foo"; +import { bar } from "/client/bar"; + + +//// [foo.js] +"use strict"; +exports.__esModule = true; +function foo() { } +exports.foo = foo; +//// [bar.js] +"use strict"; +exports.__esModule = true; +function bar() { } +exports.bar = bar; +//// [a.js] +"use strict"; +exports.__esModule = true; diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_multipleAliases.symbols b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_multipleAliases.symbols new file mode 100644 index 0000000000000..a088f80ad3df2 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_multipleAliases.symbols @@ -0,0 +1,15 @@ +=== /root/src/a.ts === +import { foo } from "/import/foo"; +>foo : Symbol(foo, Decl(a.ts, 0, 8)) + +import { bar } from "/client/bar"; +>bar : Symbol(bar, Decl(a.ts, 1, 8)) + +=== /root/import/foo.ts === +export function foo() {} +>foo : Symbol(foo, Decl(foo.ts, 0, 0)) + +=== /root/client/bar.js === +export function bar() {} +>bar : Symbol(bar, Decl(bar.js, 0, 0)) + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_multipleAliases.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_multipleAliases.trace.json new file mode 100644 index 0000000000000..70201ae705055 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_multipleAliases.trace.json @@ -0,0 +1,28 @@ +[ + "======== Resolving module '/import/foo' from '/root/src/a.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "'paths' option is specified, looking for a pattern to match module name '/import/foo'.", + "Module name '/import/foo', matched pattern '/import/*'.", + "Trying substitution './import/*', candidate module location: './import/foo'.", + "Loading module as file / folder, candidate module location '/root/import/foo', target file type 'TypeScript'.", + "File '/root/import/foo.ts' exist - use it as a name resolution result.", + "======== Module name '/import/foo' was successfully resolved to '/root/import/foo.ts'. ========", + "======== Resolving module '/client/bar' from '/root/src/a.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "'paths' option is specified, looking for a pattern to match module name '/client/bar'.", + "Module name '/client/bar', matched pattern '/client/*'.", + "Trying substitution './client/*', candidate module location: './client/bar'.", + "Loading module as file / folder, candidate module location '/root/client/bar', target file type 'TypeScript'.", + "File '/root/client/bar.ts' does not exist.", + "File '/root/client/bar.tsx' does not exist.", + "File '/root/client/bar.d.ts' does not exist.", + "Directory '/root/client/bar' does not exist, skipping all lookups in it.", + "Loading module as file / folder, candidate module location '/client/bar', target file type 'TypeScript'.", + "Directory '/client' does not exist, skipping all lookups in it.", + "'paths' option is specified, looking for a pattern to match module name '/client/bar'.", + "Module name '/client/bar', matched pattern '/client/*'.", + "Trying substitution './client/*', candidate module location: './client/bar'.", + "Loading module as file / folder, candidate module location '/root/client/bar', target file type 'JavaScript'.", + "File '/root/client/bar.js' exist - use it as a name resolution result.", + "======== Module name '/client/bar' was successfully resolved to '/root/client/bar.js'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_multipleAliases.types b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_multipleAliases.types new file mode 100644 index 0000000000000..556f6fbb1cd94 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_multipleAliases.types @@ -0,0 +1,15 @@ +=== /root/src/a.ts === +import { foo } from "/import/foo"; +>foo : () => void + +import { bar } from "/client/bar"; +>bar : () => void + +=== /root/import/foo.ts === +export function foo() {} +>foo : () => void + +=== /root/client/bar.js === +export function bar() {} +>bar : () => void + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_realRootFile.js b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_realRootFile.js new file mode 100644 index 0000000000000..aa8645bc401e7 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_realRootFile.js @@ -0,0 +1,26 @@ +//// [tests/cases/compiler/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_realRootFile.ts] //// + +//// [foo.ts] +export function foo() {} + +//// [bar.js] +export function bar() {} + +//// [a.ts] +import { foo } from "/foo"; +import { bar } from "/bar"; + + +//// [foo.js] +"use strict"; +exports.__esModule = true; +function foo() { } +exports.foo = foo; +//// [bar.js] +"use strict"; +exports.__esModule = true; +function bar() { } +exports.bar = bar; +//// [a.js] +"use strict"; +exports.__esModule = true; diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_realRootFile.symbols b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_realRootFile.symbols new file mode 100644 index 0000000000000..e3abb84bf63c8 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_realRootFile.symbols @@ -0,0 +1,15 @@ +=== /root/a.ts === +import { foo } from "/foo"; +>foo : Symbol(foo, Decl(a.ts, 0, 8)) + +import { bar } from "/bar"; +>bar : Symbol(bar, Decl(a.ts, 1, 8)) + +=== /foo.ts === +export function foo() {} +>foo : Symbol(foo, Decl(foo.ts, 0, 0)) + +=== /bar.js === +export function bar() {} +>bar : Symbol(bar, Decl(bar.js, 0, 0)) + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_realRootFile.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_realRootFile.trace.json new file mode 100644 index 0000000000000..1592ee639faa7 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_realRootFile.trace.json @@ -0,0 +1,29 @@ +[ + "======== Resolving module '/foo' from '/root/a.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "'paths' option is specified, looking for a pattern to match module name '/foo'.", + "Module name '/foo', matched pattern '/*'.", + "Trying substitution './src/*', candidate module location: './src/foo'.", + "Loading module as file / folder, candidate module location '/root/src/foo', target file type 'TypeScript'.", + "Loading module as file / folder, candidate module location '/foo', target file type 'TypeScript'.", + "File '/foo.ts' exist - use it as a name resolution result.", + "======== Module name '/foo' was successfully resolved to '/foo.ts'. ========", + "======== Resolving module '/bar' from '/root/a.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "'paths' option is specified, looking for a pattern to match module name '/bar'.", + "Module name '/bar', matched pattern '/*'.", + "Trying substitution './src/*', candidate module location: './src/bar'.", + "Loading module as file / folder, candidate module location '/root/src/bar', target file type 'TypeScript'.", + "Loading module as file / folder, candidate module location '/bar', target file type 'TypeScript'.", + "File '/bar.ts' does not exist.", + "File '/bar.tsx' does not exist.", + "File '/bar.d.ts' does not exist.", + "Directory '/bar' does not exist, skipping all lookups in it.", + "'paths' option is specified, looking for a pattern to match module name '/bar'.", + "Module name '/bar', matched pattern '/*'.", + "Trying substitution './src/*', candidate module location: './src/bar'.", + "Loading module as file / folder, candidate module location '/root/src/bar', target file type 'JavaScript'.", + "Loading module as file / folder, candidate module location '/bar', target file type 'JavaScript'.", + "File '/bar.js' exist - use it as a name resolution result.", + "======== Module name '/bar' was successfully resolved to '/bar.js'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_realRootFile.types b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_realRootFile.types new file mode 100644 index 0000000000000..538b612723614 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_realRootFile.types @@ -0,0 +1,15 @@ +=== /root/a.ts === +import { foo } from "/foo"; +>foo : () => void + +import { bar } from "/bar"; +>bar : () => void + +=== /foo.ts === +export function foo() {} +>foo : () => void + +=== /bar.js === +export function bar() {} +>bar : () => void + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_noAliasWithRoot_failedLookup.errors.txt b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_noAliasWithRoot_failedLookup.errors.txt new file mode 100644 index 0000000000000..2e630ed625c2c --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_noAliasWithRoot_failedLookup.errors.txt @@ -0,0 +1,30 @@ +/root/a.ts(1,21): error TS2307: Cannot find module '/foo'. +/root/a.ts(2,21): error TS2307: Cannot find module '/bar'. + + +==== /root/tsconfig.json (0 errors) ==== + { + "compilerOptions": { + "baseUrl": ".", + "paths": { + "*": ["./src/*"] + }, + "allowJs": true, + "outDir": "bin" + } + } + +==== /root/a.ts (2 errors) ==== + import { foo } from "/foo"; + ~~~~~~ +!!! error TS2307: Cannot find module '/foo'. + import { bar } from "/bar"; + ~~~~~~ +!!! error TS2307: Cannot find module '/bar'. + +==== /root/src/foo.ts (0 errors) ==== + export function foo() {} + +==== /root/src/bar.js (0 errors) ==== + export function bar() {} + \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_noAliasWithRoot_failedLookup.js b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_noAliasWithRoot_failedLookup.js new file mode 100644 index 0000000000000..138729c9cac5a --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_noAliasWithRoot_failedLookup.js @@ -0,0 +1,16 @@ +//// [tests/cases/compiler/pathMappingBasedModuleResolution_rootImport_noAliasWithRoot_failedLookup.ts] //// + +//// [foo.ts] +export function foo() {} + +//// [bar.js] +export function bar() {} + +//// [a.ts] +import { foo } from "/foo"; +import { bar } from "/bar"; + + +//// [a.js] +"use strict"; +exports.__esModule = true; diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_noAliasWithRoot_failedLookup.symbols b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_noAliasWithRoot_failedLookup.symbols new file mode 100644 index 0000000000000..014c782077192 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_noAliasWithRoot_failedLookup.symbols @@ -0,0 +1,7 @@ +=== /root/a.ts === +import { foo } from "/foo"; +>foo : Symbol(foo, Decl(a.ts, 0, 8)) + +import { bar } from "/bar"; +>bar : Symbol(bar, Decl(a.ts, 1, 8)) + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_noAliasWithRoot_failedLookup.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_noAliasWithRoot_failedLookup.trace.json new file mode 100644 index 0000000000000..abc6afc5d6d48 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_noAliasWithRoot_failedLookup.trace.json @@ -0,0 +1,26 @@ +[ + "======== Resolving module '/foo' from '/root/a.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "Loading module as file / folder, candidate module location '/foo', target file type 'TypeScript'.", + "File '/foo.ts' does not exist.", + "File '/foo.tsx' does not exist.", + "File '/foo.d.ts' does not exist.", + "Directory '/foo' does not exist, skipping all lookups in it.", + "Loading module as file / folder, candidate module location '/foo', target file type 'JavaScript'.", + "File '/foo.js' does not exist.", + "File '/foo.jsx' does not exist.", + "Directory '/foo' does not exist, skipping all lookups in it.", + "======== Module name '/foo' was not resolved. ========", + "======== Resolving module '/bar' from '/root/a.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "Loading module as file / folder, candidate module location '/bar', target file type 'TypeScript'.", + "File '/bar.ts' does not exist.", + "File '/bar.tsx' does not exist.", + "File '/bar.d.ts' does not exist.", + "Directory '/bar' does not exist, skipping all lookups in it.", + "Loading module as file / folder, candidate module location '/bar', target file type 'JavaScript'.", + "File '/bar.js' does not exist.", + "File '/bar.jsx' does not exist.", + "Directory '/bar' does not exist, skipping all lookups in it.", + "======== Module name '/bar' was not resolved. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_noAliasWithRoot_failedLookup.types b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_noAliasWithRoot_failedLookup.types new file mode 100644 index 0000000000000..29ff85450ce01 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_noAliasWithRoot_failedLookup.types @@ -0,0 +1,7 @@ +=== /root/a.ts === +import { foo } from "/foo"; +>foo : any + +import { bar } from "/bar"; +>bar : any + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_noAliasWithRoot_realRootFile.js b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_noAliasWithRoot_realRootFile.js new file mode 100644 index 0000000000000..23dd9fb91e0a4 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_noAliasWithRoot_realRootFile.js @@ -0,0 +1,26 @@ +//// [tests/cases/compiler/pathMappingBasedModuleResolution_rootImport_noAliasWithRoot_realRootFile.ts] //// + +//// [foo.ts] +export function foo() {} + +//// [bar.js] +export function bar() {} + +//// [a.ts] +import { foo } from "/foo"; +import { bar } from "/bar"; + + +//// [foo.js] +"use strict"; +exports.__esModule = true; +function foo() { } +exports.foo = foo; +//// [bar.js] +"use strict"; +exports.__esModule = true; +function bar() { } +exports.bar = bar; +//// [a.js] +"use strict"; +exports.__esModule = true; diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_noAliasWithRoot_realRootFile.symbols b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_noAliasWithRoot_realRootFile.symbols new file mode 100644 index 0000000000000..e3abb84bf63c8 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_noAliasWithRoot_realRootFile.symbols @@ -0,0 +1,15 @@ +=== /root/a.ts === +import { foo } from "/foo"; +>foo : Symbol(foo, Decl(a.ts, 0, 8)) + +import { bar } from "/bar"; +>bar : Symbol(bar, Decl(a.ts, 1, 8)) + +=== /foo.ts === +export function foo() {} +>foo : Symbol(foo, Decl(foo.ts, 0, 0)) + +=== /bar.js === +export function bar() {} +>bar : Symbol(bar, Decl(bar.js, 0, 0)) + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_noAliasWithRoot_realRootFile.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_noAliasWithRoot_realRootFile.trace.json new file mode 100644 index 0000000000000..cd7428e80d993 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_noAliasWithRoot_realRootFile.trace.json @@ -0,0 +1,17 @@ +[ + "======== Resolving module '/foo' from '/root/a.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "Loading module as file / folder, candidate module location '/foo', target file type 'TypeScript'.", + "File '/foo.ts' exist - use it as a name resolution result.", + "======== Module name '/foo' was successfully resolved to '/foo.ts'. ========", + "======== Resolving module '/bar' from '/root/a.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "Loading module as file / folder, candidate module location '/bar', target file type 'TypeScript'.", + "File '/bar.ts' does not exist.", + "File '/bar.tsx' does not exist.", + "File '/bar.d.ts' does not exist.", + "Directory '/bar' does not exist, skipping all lookups in it.", + "Loading module as file / folder, candidate module location '/bar', target file type 'JavaScript'.", + "File '/bar.js' exist - use it as a name resolution result.", + "======== Module name '/bar' was successfully resolved to '/bar.js'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_noAliasWithRoot_realRootFile.types b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_noAliasWithRoot_realRootFile.types new file mode 100644 index 0000000000000..538b612723614 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution_rootImport_noAliasWithRoot_realRootFile.types @@ -0,0 +1,15 @@ +=== /root/a.ts === +import { foo } from "/foo"; +>foo : () => void + +import { bar } from "/bar"; +>bar : () => void + +=== /foo.ts === +export function foo() {} +>foo : () => void + +=== /bar.js === +export function bar() {} +>bar : () => void + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution_withExtension.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution_withExtension.trace.json index 39a12996d4268..17c98978db99e 100644 --- a/tests/baselines/reference/pathMappingBasedModuleResolution_withExtension.trace.json +++ b/tests/baselines/reference/pathMappingBasedModuleResolution_withExtension.trace.json @@ -1,7 +1,6 @@ [ "======== Resolving module 'foo' from '/a.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", - "'baseUrl' option is set to '/', using this value to resolve non-relative module name 'foo'.", "'paths' option is specified, looking for a pattern to match module name 'foo'.", "Module name 'foo', matched pattern 'foo'.", "Trying substitution 'foo/foo.ts', candidate module location: 'foo/foo.ts'.", @@ -9,7 +8,6 @@ "======== Module name 'foo' was successfully resolved to '/foo/foo.ts'. ========", "======== Resolving module 'bar' from '/a.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", - "'baseUrl' option is set to '/', using this value to resolve non-relative module name 'bar'.", "'paths' option is specified, looking for a pattern to match module name 'bar'.", "Module name 'bar', matched pattern 'bar'.", "Trying substitution 'bar/bar.js', candidate module location: 'bar/bar.js'.", diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution_withExtensionInName.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution_withExtensionInName.trace.json index 216442fb378df..d704500e714d0 100644 --- a/tests/baselines/reference/pathMappingBasedModuleResolution_withExtensionInName.trace.json +++ b/tests/baselines/reference/pathMappingBasedModuleResolution_withExtensionInName.trace.json @@ -1,7 +1,6 @@ [ "======== Resolving module 'zone.js' from '/a.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", - "'baseUrl' option is set to '/', using this value to resolve non-relative module name 'zone.js'.", "'paths' option is specified, looking for a pattern to match module name 'zone.js'.", "Module name 'zone.js', matched pattern '*'.", "Trying substitution 'foo/*', candidate module location: 'foo/zone.js'.", @@ -21,7 +20,6 @@ "======== Module name 'zone.js' was successfully resolved to '/foo/zone.js/index.d.ts'. ========", "======== Resolving module 'zone.tsx' from '/a.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", - "'baseUrl' option is set to '/', using this value to resolve non-relative module name 'zone.tsx'.", "'paths' option is specified, looking for a pattern to match module name 'zone.tsx'.", "Module name 'zone.tsx', matched pattern '*'.", "Trying substitution 'foo/*', candidate module location: 'foo/zone.tsx'.", diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution_withExtension_MapedToNodeModules.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution_withExtension_MapedToNodeModules.trace.json index dac9d19bc0f2c..0cdec33cf56d5 100644 --- a/tests/baselines/reference/pathMappingBasedModuleResolution_withExtension_MapedToNodeModules.trace.json +++ b/tests/baselines/reference/pathMappingBasedModuleResolution_withExtension_MapedToNodeModules.trace.json @@ -1,7 +1,6 @@ [ "======== Resolving module 'foo/bar/foobar.js' from '/a.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", - "'baseUrl' option is set to '/', using this value to resolve non-relative module name 'foo/bar/foobar.js'.", "'paths' option is specified, looking for a pattern to match module name 'foo/bar/foobar.js'.", "Module name 'foo/bar/foobar.js', matched pattern '*'.", "Trying substitution 'node_modules/*', candidate module location: 'node_modules/foo/bar/foobar.js'.", diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution_withExtension_failedLookup.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution_withExtension_failedLookup.trace.json index 803520f12fd5a..ee36b04ef10f5 100644 --- a/tests/baselines/reference/pathMappingBasedModuleResolution_withExtension_failedLookup.trace.json +++ b/tests/baselines/reference/pathMappingBasedModuleResolution_withExtension_failedLookup.trace.json @@ -1,7 +1,6 @@ [ "======== Resolving module 'foo' from '/a.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", - "'baseUrl' option is set to '/', using this value to resolve non-relative module name 'foo'.", "'paths' option is specified, looking for a pattern to match module name 'foo'.", "Module name 'foo', matched pattern 'foo'.", "Trying substitution 'foo/foo.ts', candidate module location: 'foo/foo.ts'.", @@ -9,7 +8,6 @@ "Loading module as file / folder, candidate module location '/foo/foo.ts', target file type 'TypeScript'.", "Loading module 'foo' from 'node_modules' folder, target file type 'TypeScript'.", "Directory '/node_modules' does not exist, skipping all lookups in it.", - "'baseUrl' option is set to '/', using this value to resolve non-relative module name 'foo'.", "'paths' option is specified, looking for a pattern to match module name 'foo'.", "Module name 'foo', matched pattern 'foo'.", "Trying substitution 'foo/foo.ts', candidate module location: 'foo/foo.ts'.", diff --git a/tests/baselines/reference/requireOfJsonFileWithoutResolveJsonModuleAndPathMapping.trace.json b/tests/baselines/reference/requireOfJsonFileWithoutResolveJsonModuleAndPathMapping.trace.json index ed48ec5baac85..27fd9d96cfdea 100644 --- a/tests/baselines/reference/requireOfJsonFileWithoutResolveJsonModuleAndPathMapping.trace.json +++ b/tests/baselines/reference/requireOfJsonFileWithoutResolveJsonModuleAndPathMapping.trace.json @@ -1,7 +1,6 @@ [ "======== Resolving module 'foo/bar/foobar.json' from '/a.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", - "'baseUrl' option is set to '/', using this value to resolve non-relative module name 'foo/bar/foobar.json'.", "'paths' option is specified, looking for a pattern to match module name 'foo/bar/foobar.json'.", "Module name 'foo/bar/foobar.json', matched pattern '*'.", "Trying substitution 'node_modules/*', candidate module location: 'node_modules/foo/bar/foobar.json'.", diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution_rootImport_aliasWithRoot.ts b/tests/cases/compiler/pathMappingBasedModuleResolution_rootImport_aliasWithRoot.ts new file mode 100644 index 0000000000000..9af12c71a9547 --- /dev/null +++ b/tests/cases/compiler/pathMappingBasedModuleResolution_rootImport_aliasWithRoot.ts @@ -0,0 +1,25 @@ +// @noImplicitReferences: true +// @traceResolution: true +// @allowJs: true + +// @filename: /root/src/foo.ts +export function foo() {} + +// @filename: /root/src/bar.js +export function bar() {} + +// @filename: /root/a.ts +import { foo } from "/foo"; +import { bar } from "/bar"; + +// @filename: /root/tsconfig.json +{ + "compilerOptions": { + "baseUrl": ".", + "paths": { + "/*": ["./src/*"] + }, + "allowJs": true, + "outDir": "bin" + } +} diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_differentRootTypes.ts b/tests/cases/compiler/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_differentRootTypes.ts new file mode 100644 index 0000000000000..a9fd2cde5bd9a --- /dev/null +++ b/tests/cases/compiler/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_differentRootTypes.ts @@ -0,0 +1,49 @@ +// @noImplicitReferences: true +// @traceResolution: true +// @allowJs: true + +// @filename: /root/src/foo.ts +export function foo() {} + +// @filename: /root/src/bar.js +export function bar() {} + +// @filename: /root/a.ts +import { foo as foo1 } from "/foo"; +import { bar as bar1 } from "/bar"; +import { foo as foo2 } from "c:/foo"; +import { bar as bar2 } from "c:/bar"; +import { foo as foo3 } from "c:\\foo"; +import { bar as bar3 } from "c:\\bar"; +import { foo as foo4 } from "//server/foo"; +import { bar as bar4 } from "//server/bar"; +import { foo as foo5 } from "\\\\server\\foo"; +import { bar as bar5 } from "\\\\server\\bar"; +import { foo as foo6 } from "file:///foo"; +import { bar as bar6 } from "file:///bar"; +import { foo as foo7 } from "file://c:/foo"; +import { bar as bar7 } from "file://c:/bar"; +import { foo as foo8 } from "file://server/foo"; +import { bar as bar8 } from "file://server/bar"; +import { foo as foo9 } from "http://server/foo"; +import { bar as bar9 } from "http://server/bar"; + +// @filename: /root/tsconfig.json +{ + "compilerOptions": { + "baseUrl": ".", + "paths": { + "/*": ["./src/*"], + "c:/*": ["./src/*"], + "c:\\*": ["./src/*"], + "//server/*": ["./src/*"], + "\\\\server\\*": ["./src/*"], + "file:///*": ["./src/*"], + "file://c:/*": ["./src/*"], + "file://server/*": ["./src/*"], + "http://server/*": ["./src/*"] + }, + "allowJs": true, + "outDir": "bin" + } +} diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_multipleAliases.ts b/tests/cases/compiler/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_multipleAliases.ts new file mode 100644 index 0000000000000..5225f1dbd0561 --- /dev/null +++ b/tests/cases/compiler/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_multipleAliases.ts @@ -0,0 +1,26 @@ +// @noImplicitReferences: true +// @traceResolution: true +// @allowJs: true + +// @filename: /root/import/foo.ts +export function foo() {} + +// @filename: /root/client/bar.js +export function bar() {} + +// @filename: /root/src/a.ts +import { foo } from "/import/foo"; +import { bar } from "/client/bar"; + +// @filename: /root/tsconfig.json +{ + "compilerOptions": { + "baseUrl": ".", + "paths": { + "/client/*": ["./client/*"], + "/import/*": ["./import/*"] + }, + "allowJs": true, + "outDir": "bin" + } +} diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_realRootFile.ts b/tests/cases/compiler/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_realRootFile.ts new file mode 100644 index 0000000000000..e45a25b1e1142 --- /dev/null +++ b/tests/cases/compiler/pathMappingBasedModuleResolution_rootImport_aliasWithRoot_realRootFile.ts @@ -0,0 +1,25 @@ +// @noImplicitReferences: true +// @traceResolution: true +// @allowJs: true + +// @filename: /foo.ts +export function foo() {} + +// @filename: /bar.js +export function bar() {} + +// @filename: /root/a.ts +import { foo } from "/foo"; +import { bar } from "/bar"; + +// @filename: /root/tsconfig.json +{ + "compilerOptions": { + "baseUrl": ".", + "paths": { + "/*": ["./src/*"] + }, + "allowJs": true, + "outDir": "bin" + } +} diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution_rootImport_noAliasWithRoot_failedLookup.ts b/tests/cases/compiler/pathMappingBasedModuleResolution_rootImport_noAliasWithRoot_failedLookup.ts new file mode 100644 index 0000000000000..d05ea12b257b0 --- /dev/null +++ b/tests/cases/compiler/pathMappingBasedModuleResolution_rootImport_noAliasWithRoot_failedLookup.ts @@ -0,0 +1,25 @@ +// @noImplicitReferences: true +// @traceResolution: true +// @allowJs: true + +// @filename: /root/src/foo.ts +export function foo() {} + +// @filename: /root/src/bar.js +export function bar() {} + +// @filename: /root/a.ts +import { foo } from "/foo"; +import { bar } from "/bar"; + +// @filename: /root/tsconfig.json +{ + "compilerOptions": { + "baseUrl": ".", + "paths": { + "*": ["./src/*"] + }, + "allowJs": true, + "outDir": "bin" + } +} diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution_rootImport_noAliasWithRoot_realRootFile.ts b/tests/cases/compiler/pathMappingBasedModuleResolution_rootImport_noAliasWithRoot_realRootFile.ts new file mode 100644 index 0000000000000..eb552c73c8213 --- /dev/null +++ b/tests/cases/compiler/pathMappingBasedModuleResolution_rootImport_noAliasWithRoot_realRootFile.ts @@ -0,0 +1,25 @@ +// @noImplicitReferences: true +// @traceResolution: true +// @allowJs: true + +// @filename: /foo.ts +export function foo() {} + +// @filename: /bar.js +export function bar() {} + +// @filename: /root/a.ts +import { foo } from "/foo"; +import { bar } from "/bar"; + +// @filename: /root/tsconfig.json +{ + "compilerOptions": { + "baseUrl": ".", + "paths": { + "*": ["./src/*"] + }, + "allowJs": true, + "outDir": "bin" + } +} diff --git a/tests/cases/fourslash/completionForStringLiteralNonrelativeImport14.ts b/tests/cases/fourslash/completionForStringLiteralNonrelativeImport14.ts new file mode 100644 index 0000000000000..dac27a6c30785 --- /dev/null +++ b/tests/cases/fourslash/completionForStringLiteralNonrelativeImport14.ts @@ -0,0 +1,28 @@ +/// + +// Should give completions for modules referenced via baseUrl and paths compiler options with explicit name mappings + +// @Filename: tsconfig.json +//// { +//// "compilerOptions": { +//// "baseUrl": "./modules", +//// "paths": { +//// "/module1": ["some/path/whatever.ts"], +//// "/module2": ["some/other/path.ts"] +//// } +//// } +//// } + + +// @Filename: tests/test0.ts +//// import * as foo1 from "//*import_as0*/ +//// import foo2 = require("//*import_equals0*/ +//// var foo3 = require("//*require0*/ + +// @Filename: some/path/whatever.ts +//// export var x = 9; + +// @Filename: some/other/path.ts +//// export var y = 10; + +verify.completions({ marker: test.markerNames(), exact: ["lib", "tests", "/module1", "/module2"], isNewIdentifierLocation: true }); diff --git a/tests/cases/fourslash/completionForStringLiteralNonrelativeImport15.ts b/tests/cases/fourslash/completionForStringLiteralNonrelativeImport15.ts new file mode 100644 index 0000000000000..170fdd01be1fa --- /dev/null +++ b/tests/cases/fourslash/completionForStringLiteralNonrelativeImport15.ts @@ -0,0 +1,28 @@ +/// + +// Should give completions for modules referenced via baseUrl and paths compiler options with explicit name mappings + +// @Filename: tsconfig.json +//// { +//// "compilerOptions": { +//// "baseUrl": "./modules", +//// "paths": { +//// "/module1": ["some/path/whatever.ts"], +//// "/module2": ["some/other/path.ts"] +//// } +//// } +//// } + + +// @Filename: tests/test0.ts +//// import * as foo1 from "//m*import_as0*/ +//// import foo2 = require("//m*import_equals0*/ +//// var foo3 = require("//m*require0*/ + +// @Filename: some/path/whatever.ts +//// export var x = 9; + +// @Filename: some/other/path.ts +//// export var y = 10; + +verify.completions({ marker: test.markerNames(), exact: ["/module1", "/module2"], isNewIdentifierLocation: true }); diff --git a/tests/cases/user/TypeScript-Node-Starter/TypeScript-Node-Starter b/tests/cases/user/TypeScript-Node-Starter/TypeScript-Node-Starter index 40bdb4eadabc9..4779cb7e182cf 160000 --- a/tests/cases/user/TypeScript-Node-Starter/TypeScript-Node-Starter +++ b/tests/cases/user/TypeScript-Node-Starter/TypeScript-Node-Starter @@ -1 +1 @@ -Subproject commit 40bdb4eadabc9fbed7d83e3f26817a931c0763b6 +Subproject commit 4779cb7e182cf41d5c62289bb80d2850e0265b71