diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 195122c5f2b..99a1c52913c 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -256,8 +256,6 @@ namespace ts { type: { "node": ModuleResolutionKind.NodeJs, "classic": ModuleResolutionKind.Classic, - // name is lowercased so we can still use hasProperty(userValue.toLower()) to check if user has entered the right value - "baseurl": ModuleResolutionKind.BaseUrl, }, description: Diagnostics.Specifies_module_resolution_strategy_Colon_node_Node_js_or_classic_TypeScript_pre_1_6, error: Diagnostics.Argument_for_moduleResolution_option_must_be_node_classic_or_baseUrl, @@ -529,8 +527,6 @@ namespace ts { const { options: optionsFromJsonConfigFile, errors } = convertCompilerOptionsFromJson(json["compilerOptions"], basePath, configFileName); const options = extend(existingOptions, optionsFromJsonConfigFile); - // set basePath as inferredBaseUrl so baseUrl module resolution strategy can still work even if user have not specified baseUrl explicity - options.inferredBaseUrl = basePath; return { options, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 1b58d960c50..3bb5fb31750 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2159,7 +2159,7 @@ "category": "Error", "code": 5059 }, - "Option '{0}' can only be used when option 'moduleResolution' is 'baseUrl'.": { + "Option 'paths' cannot be used without specifying '--baseUrl' option.": { "category": "Error", "code": 5060 }, @@ -2171,14 +2171,6 @@ "category": "Error", "code": 5062 }, - "'moduleResolution' kind 'baseUrl' cannot be used without specifying '--baseUrl' option.": { - "category": "Error", - "code": 5063 - }, - "Module resolution kind cannot be determined automatically. Please specify module resolution explicitly via 'moduleResolution' option.": { - "category": "Error", - "code": 5064 - }, "Concatenate and emit output to single file.": { "category": "Message", "code": 6001 @@ -2479,101 +2471,93 @@ "category": "Message", "code": 6090 }, - "Resolving rooted module name '{0}' - use it as a candidate location.": { + "'paths' option is specified, looking for a pattern to match module name '{0}'.": { "category": "Message", "code": 6091 }, - "Resolving relative module name '{0}'.": { + "Module name '{0}', matched pattern '{1}'.": { "category": "Message", "code": 6092 }, - "Resolving non-relative module name '{0}'.": { + "Trying substitution '{0}', candidate module location: '{1}'.": { "category": "Message", "code": 6093 }, - "Converting relative module name '{0}' to absolute using '{1}' as a base directory => '{2}'.": { + "Resolving module name '{0}' relative to base url '{1}' - '{2}'.": { "category": "Message", "code": 6094 }, - "'rootDirs' option is specified, searching for a longest matching prefix...": { + "Loading module as file / folder, candidate module location '{0}'.": { "category": "Message", "code": 6095 }, - "Found longest matching rootDir '{0}', 'converted relative path '{1}', to non-relative path '{2}'": { + "File '{0}' does not exist.": { "category": "Message", "code": 6096 }, - "'rootDirs' option is not specified, using '{0}' as candidate location.": { + "File '{0}' exist - use it as a module resolution result.": { "category": "Message", "code": 6097 }, - "'paths' option is specified, looking for a pattern to match module name '{0}'.": { + "Loading module '{0}' from 'node_modules' folder.": { "category": "Message", "code": 6098 }, - "Module name '{0}', matched pattern '{1}'.": { + "Found 'package.json' at '{0}'.": { "category": "Message", "code": 6099 }, - "Trying substitution '{0}', candidate module location: '{1}'.": { + "'package.json' does not have 'typings' field.": { "category": "Message", "code": 6100 }, - "Resolving module name '{0}' relative to base url '{1}' - '{2}'.": { + "'package.json' has 'typings' field '{0}' that references '{1}'.": { "category": "Message", "code": 6101 }, - "Loading module '{0}' as file / folder, candidate module location '{1}'.": { + "Module name '{0}' contains '!' character.": { "category": "Message", "code": 6102 }, - "File '{0}' does not exist.": { + "Allow javascript files to be compiled.": { "category": "Message", "code": 6103 }, - "File '{0}' exist - use it as a module resolution result.": { - "category": "Message", - "code": 6104 - }, - "Loading module '{0}' from 'node_modules' folder.": { - "category": "Message", - "code": 6105 - }, - "Found 'package.json' at '{0}'.": { - "category": "Message", - "code": 6106 - }, - "'package.json' does not have 'typings' field.": { - "category": "Message", - "code": 6107 - }, - "'package.json' has 'typings' field '{0}' that references '{1}'.": { - "category": "Message", - "code": 6108 - }, - "Module name '{0}' contains '!' character.": { - "category": "Message", - "code": 6109 - }, - "Allow javascript files to be compiled.": { - "category": "Message", - "code": 6110 - }, - "Base url: '{0}'.": { - "category": "Message", - "code": 6111 - }, "Option '{0}' should have array of strings as a value.": { "category": "Error", - "code": 6112 + "code": 6104 }, "Checking if '{0}' is the longest matching prefix for '{1}' - '{2}'.": { "category": "Message", - "code": 6113 + "code": 6105 }, "Expected type of 'typings' field in 'package.json' to be 'string', got '{0}'.": { "category": "Message", - "code": 6114 + "code": 6106 + }, + "'baseUrl' option is set to '{0}', using this value to resolve non-relative module name '{1}'": { + "category": "Message", + "code": 6107 + }, + "'rootDirs' option is set, using it to resolve relative module name '{0}'": { + "category": "Message", + "code": 6108 + }, + "Longest matching prefix for '{0}' is '{1}'": { + "category": "Message", + "code": 6109 + }, + "Loading '{0}' from the root dir '{1}', candidate location '{2}'": { + "category": "Message", + "code": 6110 + }, + "Trying other entries in 'rootDirs'": { + "category": "Message", + "code": 6111 + }, + "Module resolution using 'rootDirs' has failed": { + "category": "Message", + "code": 6112 }, "Variable '{0}' implicitly has an '{1}' type.": { "category": "Error", diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 065304dc078..910525aa8d2 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -45,6 +45,51 @@ namespace ts { return compilerOptions.traceModuleResolution && host.trace !== undefined; } + function startsWith(str: string, prefix: string): boolean { + return str.lastIndexOf(prefix, 0) === 0; + } + + function endsWith(str: string, suffix: string): boolean { + const expectedPos = str.length - suffix.length; + return str.indexOf(suffix, expectedPos) === expectedPos; + } + + function hasZeroOrOneAsteriskCharacter(str: string): boolean { + let seenAsterisk = false; + for (let i = 0; i < str.length; i++) { + if (str.charCodeAt(i) === CharacterCodes.asterisk) { + if (!seenAsterisk) { + seenAsterisk = true; + } + else { + // have already seen asterisk + return false; + } + } + } + return true; + } + + function createResolvedModule(resolvedFileName: string, isExternalLibraryImport: boolean, failedLookupLocations: string[]): ResolvedModuleWithFailedLookupLocations { + return { resolvedModule: resolvedFileName ? { resolvedFileName, isExternalLibraryImport } : undefined, failedLookupLocations }; + } + + function moduleHasNonRelativeName(moduleName: string): boolean { + if (isRootedDiskPath(moduleName)) { + return false; + } + + const i = moduleName.lastIndexOf("./", 1); + const startsWithDotSlashOrDotDotSlash = i === 0 || (i === 1 && moduleName.charCodeAt(0) === CharacterCodes.dot); + return !startsWithDotSlashOrDotDotSlash; + } + + interface ModuleResolutionState { + host: ModuleResolutionHost; + compilerOptions: CompilerOptions; + traceEnabled: boolean; + } + export function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations { const traceEnabled = isTraceEnabled(compilerOptions, host); if (traceEnabled) { @@ -53,16 +98,7 @@ namespace ts { let moduleResolution = compilerOptions.moduleResolution; if (moduleResolution === undefined) { - if (compilerOptions.module === ModuleKind.CommonJS) { - moduleResolution = ModuleResolutionKind.NodeJs; - } - else if (compilerOptions.baseUrl !== undefined || compilerOptions.paths || compilerOptions.rootDirs) { - moduleResolution = ModuleResolutionKind.BaseUrl; - } - else { - moduleResolution = ModuleResolutionKind.Classic; - } - + moduleResolution = compilerOptions.module === ModuleKind.CommonJS ? ModuleResolutionKind.NodeJs : ModuleResolutionKind.Classic; if (traceEnabled) { trace(host, Diagnostics.Module_resolution_kind_is_not_specified_using_0, ModuleResolutionKind[moduleResolution]); } @@ -81,9 +117,6 @@ namespace ts { case ModuleResolutionKind.Classic: result = classicNameResolver(moduleName, containingFile, compilerOptions, host); break; - case ModuleResolutionKind.BaseUrl: - result = baseUrlModuleNameResolver(moduleName, containingFile, compilerOptions, host); - break; } if (traceEnabled) { @@ -98,192 +131,184 @@ namespace ts { return result; } - // Path mapping based module resolution strategy uses base url to resolve non-absolute file names. This resolution strategy can be enabled - // by setting 'moduleResolution' option to 'baseUrl' and as it implied by the name it uses base url to resolve module names. - // Base url can be specified: - // - explicitly via command line option 'baseUrl'. If this value is relative it will be computed relative to current directory. - // - explicitly in 'tsconfig.json' via 'baseUrl' compiler option. If this value is relative it will be computed relative to the location - // of 'tsconfig.json'. - // - if value is not provided explicitly but project uses tsconfig.json then 'baseUrl' will be set of folder that contains 'tsconfig.json' - // If baseUrl is the only provided option then non-relative module names will be resolved relative to baseUrl. Relative module names - // will still be resolved relative to the folder that contains file with import. - // User can specify additional options in tsconfig.json to tweak module resolution. - // - 'paths' option allows to tune how non-relative module names will be resolved based on the content of the module name. - // Structure of 'paths' compiler options - // 'paths': { - // pattern-1: list of substitutions 1, - // pattern-2: list of substitutions 2, - // ... - // pattern-n: list of substitutions-n - // } - // Pattern here is a string that can contain zero or one '*' character. During module resolution module name will be matched against - // all patterns in the list. Matching for patterns that don't contain '*' means that module name must be equal to pattern respecting the case. - // If pattern contains '*' then to match pattern "*" module name must start with the and end with . - // denotes part of the module name between and . - // If module name can be matches with multiple patterns then pattern with the longest prefix will be picked. - // After selecting pattern we'll use list of substitutions to get candidate locations of the module and the try to load module from the candidate location. - // Substitiution is a string that can contain zero or one '*'. To get candidate location from substitution we'll pick every substitution in the list - // and replace '*' with string. If candidate location is not rooted it will be converted to absolute using baseUrl. - // For example: - // baseUrl: /a/b/c - // "paths": { - // // match all module names - // "*": [ - // "*", // use matched name as is, - // // will be looked as /a/b/c/ - // - // "folder1/*" // substitution will convert matched name to 'folder1/', - // // since it is not rooted then final candidate location will be /a/b/c/folder1/ - // ], - // // match module names that start with 'components/' - // "components/*": [ "/root/components/*" ] // substitution will convert /components/folder1/ to '/root/components/folder1/', - // // it is rooted so it will be final candidate location - // } - // 'paths' allows to remap locations of non-relative module names. Relative module names usually are resolved relative to the folder - // that contains import. However sometimes it might be useful to apply mappings to relative module names as well. - // Since the there might be different relative file names that refer to the same file we need to convert relative module name to non-relative - // so we can just apply path mapping to it. This conversion can be performed using 'rootDirs' compiler option - this options stores list of root directories - // for the project (if root directory is not absolute it will be converted to absolute using baseUrl as a base path). - // First - we convert relative module name to absolute using location of file that contains import. - // Then we try to find what element is rootDirs is the longest prefix for this absolute file name (respecting case): - // = - // Once it is done - value of is a be non-relative name for initially relative module name. - // Note that if element in rootDirs should always end with '/' so it will be appended automatically if value in configuration does not have it. - // For example: - // baseUrl: /a/b/c - // "paths": { - // "*": [ "*", "generated/*" ] // try to resolve module name as '/a/b/c/' then look it in '/a/b/c/generated/' - // } - // "rootDirs": [ - // "./src", // root dir is project baseUrl/src - // "./generated" // root dir is baseUrl/generated - // "/e/f" // root dir is /e/f - // ] - // @file: /a/b/c/src/form1.ts - // import {x} from "./form.content.ts" - // @file: /a/b/c/generated/form.content.ts - // export var x = ... - // first './form.content.ts' needs to be converted to non-relative name. - // 1. convert it to absolute name '/a/b/c/src/form.content.ts' -> - // find longest prefix in rootDirs that match this path, it will be './src' (after expansion '/a/b/c/src/') -> - // suffix is form.content.ts - // 2. apply path mappings to 'form1.content.ts' -> - // '*' pattern will be matched -> - // '*' substitution yields '/a/b/c/form1.content.ts' - file does not exists - // 'generated/*' substitution yields '/a/b/c/generated/form1.content' - file exists - OK - export function baseUrlModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations { - const baseUrl = compilerOptions.baseUrl !== undefined ? compilerOptions.baseUrl : compilerOptions.inferredBaseUrl; - Debug.assert(baseUrl !== undefined); + /* + * Every module resolution kind can has its specific understanding how to load module from a specific path on disk + * I.e. for path '/a/b/c': + * - Node loader will first to try to check if '/a/b/c' points to a file with some supported extension and if this fails + * it will try to load module from directory: directory '/a/b/c' should exist and it should have either 'package.json' with + * 'typings' entry or file 'index' with some supported extension + * - Classic loader will only try to interpret '/a/b/c' as file. + */ + type ResolutionKindSpecificLoader = (candidate: string, extensions: string[], failedLookupLocations: string[], onlyRecordFalures: boolean, state: ModuleResolutionState) => string; - const supportedExtensions = getSupportedExtensions(compilerOptions); - // NOTE: traceEnabled check is delibirately no inside the 'trace' at evert callside to avoid runtime impact of calling vararg function - const traceEnabled = isTraceEnabled(compilerOptions, host); + /** + * Any module resolution kind can be augmented with optional settings: 'baseUrl', 'paths' and 'rootDirs' - they are used to + * mitigate differences between design time structure of the project and its runtime counterpart so the same import name + * can be resolved successfully by TypeScript compiler and runtime module loader. + * If these settings are set then loading procedure will try to use them to resolve module name and it can of failure it will + * fallback to standard resolution routine. + * + * - baseUrl - this setting controls how non-relative module names are resolved. If this setting is specified then non-relative + * names will be resolved relative to baseUrl: i.e. if baseUrl is '/a/b' then canditate location to resolve module name 'c/d' will + * be '/a/b/c/d' + * - paths - this setting can only be used when baseUrl is specified. allows to tune how non-relative module names + * will be resolved based on the content of the module name. + * Structure of 'paths' compiler options + * 'paths': { + * pattern-1: [...substitutions], + * pattern-2: [...substitutions], + * ... + * pattern-n: [...substitutions] + * } + * Pattern here is a string that can contain zero or one '*' character. During module resolution module name will be matched against + * all patterns in the list. Matching for patterns that don't contain '*' means that module name must be equal to pattern respecting the case. + * If pattern contains '*' then to match pattern "*" module name must start with the and end with . + * denotes part of the module name between and . + * If module name can be matches with multiple patterns then pattern with the longest prefix will be picked. + * After selecting pattern we'll use list of substitutions to get candidate locations of the module and the try to load module + * from the candidate location. + * Substitiution is a string that can contain zero or one '*'. To get candidate location from substitution we'll pick every + * substitution in the list and replace '*' with string. If candidate location is not rooted it + * will be converted to absolute using baseUrl. + * For example: + * baseUrl: /a/b/c + * "paths": { + * // match all module names + * "*": [ + * "*", // use matched name as is, + * // will be looked as /a/b/c/ + * + * "folder1/*" // substitution will convert matched name to 'folder1/', + * // since it is not rooted then final candidate location will be /a/b/c/folder1/ + * ], + * // match module names that start with 'components/' + * "components/*": [ "/root/components/*" ] // substitution will convert /components/folder1/ to '/root/components/folder1/', + * // it is rooted so it will be final candidate location + * } + * + * 'rootDirs' allows the project to be spreaded across multiple locations and resolve modules with relative names as if + * they were in the same location. For example lets say there are two files + * '/local/src/content/file1.ts' + * '/shared/components/contracts/src/content/protocols/file2.ts' + * After bundling content of '/shared/components/contracts/src' will be merged with '/local/src' so + * if file1 has the following import 'import {x} from "./protocols/file2"' it will be resolved successfully in runtime. + * 'rootDirs' provides the way to tell compiler that in order to get the whole project it should behave as if content of all + * root dirs were merged together. + * I.e. for the example above 'rootDirs' will have two entries: [ '/local/src', '/shared/components/contracts/src' ]. + * Compiler wil first convert './protocols/file2' into absolute path relative to the location of containing file: + * '/local/src/content/protocols/file2' and try to load it - failure. + * Then it will search 'rootDirs' looking for a longest matching prefix of this absolute path and if such prefix is found - absolute path will + * be converted to a path relative to found rootDir entry './content/protocols/file2' (*). As a last step compiler will check all remainining + * entries in 'rootDirs', use them to build absolute path out of (*) and try to resolve module from this location. + */ + function tryLoadModuleUsingOptionalResolutionSettings(moduleName: string, containingDirectory: string, loader: ResolutionKindSpecificLoader, + failedLookupLocations: string[], supportedExtensions: string[], state: ModuleResolutionState): string { - if (traceEnabled) { - trace(host, Diagnostics.Base_url_Colon_0, baseUrl); - } - - if (isRootedDiskPath(moduleName)) { - if (traceEnabled) { - trace(host, Diagnostics.Resolving_rooted_module_name_0_use_it_as_a_candidate_location, moduleName); - } - - const failedLookupLocations: string[] = []; - const resolvedFileName = loadModuleFromFile(supportedExtensions, moduleName, failedLookupLocations, !directoryProbablyExists(getDirectoryPath(moduleName), host), host, traceEnabled); - return { - resolvedModule: resolvedFileName ? { resolvedFileName } : undefined, - failedLookupLocations - }; - } - - if (nameStartsWithDotSlashOrDotDotSlash(moduleName)) { - // relative name - if (traceEnabled) { - trace(host, Diagnostics.Resolving_relative_module_name_0, moduleName); - } - return baseUrlResolveRelativeModuleName(moduleName, containingFile, baseUrl, supportedExtensions, compilerOptions, host, traceEnabled); + if (moduleHasNonRelativeName(moduleName)) { + return tryLoadModuleUsingBaseUrl(moduleName, loader, failedLookupLocations, supportedExtensions, state); } else { - // non-relative name - if (traceEnabled) { - trace(host, Diagnostics.Resolving_non_relative_module_name_0, moduleName); - } - return baseUrlResolveNonRelativeModuleName(moduleName, baseUrl, supportedExtensions, compilerOptions, host, traceEnabled); + return tryLoadModuleUsingRootDirs(moduleName, containingDirectory, loader, failedLookupLocations, supportedExtensions, state); } } - function baseUrlResolveRelativeModuleName(moduleName: string, containingFile: string, baseUrl: string, supportedExtensions: string[], compilerOptions: CompilerOptions, host: ModuleResolutionHost, traceEnabled: boolean): ResolvedModuleWithFailedLookupLocations { - const failedLookupLocations: string[] = []; + function tryLoadModuleUsingRootDirs(moduleName: string, containingDirectory: string, loader: ResolutionKindSpecificLoader, + failedLookupLocations: string[], supportedExtensions: string[], state: ModuleResolutionState): string { + + if (!state.compilerOptions.rootDirs) { + return undefined; + } + + if (state.traceEnabled) { + trace(state.host, Diagnostics.rootDirs_option_is_set_using_it_to_resolve_relative_module_name_0, moduleName); + } - // we always pass absolute path to containing file so candidate location is also absolute - const containingDirectory = getDirectoryPath(containingFile); const candidate = normalizePath(combinePaths(containingDirectory, moduleName)); - if (traceEnabled) { - trace(host, Diagnostics.Converting_relative_module_name_0_to_absolute_using_1_as_a_base_directory_2, moduleName, containingDirectory, candidate); - } + let matchedRootDir: string; + let matchedNormalizedPrefix: string; + for (const rootDir of state.compilerOptions.rootDirs) { + // rootDirs are expected to be absolute + // in case of tsconfig.json this will happen automatically - compiler will expand relative names + // using locaton of tsconfig.json as base location + let normalizedRoot = normalizePath(rootDir); + if (!endsWith(normalizedRoot, directorySeparator)) { + normalizedRoot += directorySeparator; + } + const isLongestMatchingPrefix = + startsWith(candidate, normalizedRoot) && + (matchedNormalizedPrefix === undefined || matchedNormalizedPrefix.length < normalizedRoot.length); - if (compilerOptions.rootDirs) { - if (traceEnabled) { - trace(host, Diagnostics.rootDirs_option_is_specified_searching_for_a_longest_matching_prefix); + if (state.traceEnabled) { + trace(state.host, Diagnostics.Checking_if_0_is_the_longest_matching_prefix_for_1_2, normalizedRoot, candidate, isLongestMatchingPrefix); } - let matchedPrefix: string; - for (const rootDir of compilerOptions.rootDirs) { - // rootDirs are expected to be absolute - let normalizedRoot = normalizePath(rootDir); - if (!endsWith(normalizedRoot, directorySeparator)) { - normalizedRoot += directorySeparator; - } - const isLongestMatchingPrefix = - startsWith(candidate, normalizedRoot) && - (matchedPrefix === undefined || matchedPrefix.length < normalizedRoot.length); - - if (traceEnabled) { - trace(host, Diagnostics.Checking_if_0_is_the_longest_matching_prefix_for_1_2, normalizedRoot, candidate, isLongestMatchingPrefix); - } - - if (isLongestMatchingPrefix) { - matchedPrefix = normalizedRoot; - } - } - - if (matchedPrefix) { - const suffix = candidate.substr(matchedPrefix.length); - if (traceEnabled) { - trace(host, Diagnostics.Found_longest_matching_rootDir_0_converted_relative_path_1_to_non_relative_path_2, matchedPrefix, moduleName, suffix); - } - - return baseUrlResolveNonRelativeModuleName(suffix, baseUrl, supportedExtensions, compilerOptions, host, traceEnabled); - } - - // rootDirs does not contain prefix for candidate - fallthrough to load file from candidate location. - } - else { - if (traceEnabled) { - trace(host, Diagnostics.rootDirs_option_is_not_specified_using_0_as_candidate_location, candidate); + if (isLongestMatchingPrefix) { + matchedNormalizedPrefix = normalizedRoot; + matchedRootDir = rootDir; } } + if (matchedNormalizedPrefix) { + if (state.traceEnabled) { + trace(state.host, Diagnostics.Longest_matching_prefix_for_0_is_1, candidate, matchedNormalizedPrefix); + } + const suffix = candidate.substr(matchedNormalizedPrefix.length); - const resolvedFileName = loadModuleFromFile(supportedExtensions, candidate, failedLookupLocations, !directoryProbablyExists(getDirectoryPath(candidate), host), host, traceEnabled); - return { - resolvedModule: resolvedFileName ? { resolvedFileName } : undefined, - failedLookupLocations - }; + // first - try to load from a initial location + if (state.traceEnabled) { + trace(state.host, Diagnostics.Loading_0_from_the_root_dir_1_candidate_location_2, suffix, matchedNormalizedPrefix, candidate); + } + const resolvedFileName = loader(candidate, supportedExtensions, failedLookupLocations, !directoryProbablyExists(containingDirectory, state.host), state); + if (resolvedFileName) { + return resolvedFileName; + } + + if (state.traceEnabled) { + trace(state.host, Diagnostics.Trying_other_entries_in_rootDirs); + } + // then try to resolve using remaining entries in rootDirs + for (const rootDir of state.compilerOptions.rootDirs) { + if (rootDir === matchedRootDir) { + // skip the initially matched entry + continue; + } + const candidate = combinePaths(normalizePath(rootDir), suffix); + if (state.traceEnabled) { + trace(state.host, Diagnostics.Loading_0_from_the_root_dir_1_candidate_location_2, suffix, rootDir, candidate); + } + const baseDirectory = getDirectoryPath(candidate); + const resolvedFileName = loader(candidate, supportedExtensions, failedLookupLocations, !directoryProbablyExists(baseDirectory, state.host), state); + if (resolvedFileName) { + return resolvedFileName; + } + } + if (state.traceEnabled) { + trace(state.host, Diagnostics.Module_resolution_using_rootDirs_has_failed); + } + } + return undefined; } - function baseUrlResolveNonRelativeModuleName(moduleName: string, baseUrl: string, supportedExtensions: string[], compilerOptions: CompilerOptions, host: ModuleResolutionHost, traceEnabled: boolean): ResolvedModuleWithFailedLookupLocations { + function tryLoadModuleUsingBaseUrl(moduleName: string, loader: ResolutionKindSpecificLoader, failedLookupLocations: string[], + supportedExtensions: string[], state: ModuleResolutionState): string { + + if (!state.compilerOptions.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, state.compilerOptions.baseUrl, moduleName); + } + let longestMatchPrefixLength = -1; let matchedPattern: string; let matchedStar: string; - const failedLookupLocations: string[] = []; - if (compilerOptions.paths) { - if (traceEnabled) { - trace(host, Diagnostics.paths_option_is_specified_looking_for_a_pattern_to_match_module_name_0, moduleName); + if (state.compilerOptions.paths) { + if (state.traceEnabled) { + trace(state.host, Diagnostics.paths_option_is_specified_looking_for_a_pattern_to_match_module_name_0, moduleName); } - for (const key in compilerOptions.paths) { + for (const key in state.compilerOptions.paths) { const pattern: string = key; const indexOfStar = pattern.indexOf("*"); if (indexOfStar !== -1) { @@ -311,79 +336,72 @@ namespace ts { } if (matchedPattern) { - if (traceEnabled) { - trace(host, Diagnostics.Module_name_0_matched_pattern_1, moduleName, matchedPattern); + if (state.traceEnabled) { + trace(state.host, Diagnostics.Module_name_0_matched_pattern_1, moduleName, matchedPattern); } - - for (const subst of compilerOptions.paths[matchedPattern]) { + for (const subst of state.compilerOptions.paths[matchedPattern]) { const path = matchedStar ? subst.replace("\*", matchedStar) : subst; - const candidate = normalizePath(combinePaths(baseUrl, path)); - - if (traceEnabled) { - trace(host, Diagnostics.Trying_substitution_0_candidate_module_location_Colon_1, subst, path); + const candidate = normalizePath(combinePaths(state.compilerOptions.baseUrl, path)); + if (state.traceEnabled) { + trace(state.host, Diagnostics.Trying_substitution_0_candidate_module_location_Colon_1, subst, path); } - - const resolvedFileName = loadModuleFromFile(supportedExtensions, candidate, failedLookupLocations, !directoryProbablyExists(getDirectoryPath(candidate), host), host, traceEnabled); + const resolvedFileName = loader(candidate, supportedExtensions, failedLookupLocations, !directoryProbablyExists(getDirectoryPath(candidate), state.host), state); if (resolvedFileName) { - return { resolvedModule: { resolvedFileName }, failedLookupLocations }; + return resolvedFileName; } } - - return { resolvedModule: undefined, failedLookupLocations }; + return undefined; } else { - const candidate = normalizePath(combinePaths(baseUrl, moduleName)); + const candidate = normalizePath(combinePaths(state.compilerOptions.baseUrl, moduleName)); - if (traceEnabled) { - trace(host, Diagnostics.Resolving_module_name_0_relative_to_base_url_1_2, moduleName, baseUrl, candidate); + if (state.traceEnabled) { + trace(state.host, Diagnostics.Resolving_module_name_0_relative_to_base_url_1_2, moduleName, state.compilerOptions.baseUrl, candidate); } - const resolvedFileName = loadModuleFromFile(supportedExtensions, candidate, failedLookupLocations, !directoryProbablyExists(getDirectoryPath(candidate), host), host, traceEnabled); - return { - resolvedModule: resolvedFileName ? { resolvedFileName } : undefined, - failedLookupLocations - }; + return loader(candidate, supportedExtensions, failedLookupLocations, !directoryProbablyExists(getDirectoryPath(candidate), state.host), state); } } - function startsWith(str: string, prefix: string): boolean { - return str.lastIndexOf(prefix, 0) === 0; - } - - function endsWith(str: string, suffix: string): boolean { - const expectedPos = str.length - suffix.length; - return str.indexOf(suffix, expectedPos) === expectedPos; - } - export function nodeModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations { const containingDirectory = getDirectoryPath(containingFile); const supportedExtensions = getSupportedExtensions(compilerOptions); const traceEnabled = isTraceEnabled(compilerOptions, host); - if (isRootedDiskPath(moduleName) || nameStartsWithDotSlashOrDotDotSlash(moduleName)) { - const failedLookupLocations: string[] = []; - const candidate = normalizePath(combinePaths(containingDirectory, moduleName)); - if (traceEnabled) { - trace(host, Diagnostics.Loading_module_0_as_file_Slash_folder_candidate_module_location_1, moduleName, candidate); - } + const failedLookupLocations: string[] = []; + const state = {compilerOptions, host, traceEnabled}; + let resolvedFileName = tryLoadModuleUsingOptionalResolutionSettings(moduleName, containingDirectory, nodeLoadModuleByRelativeName, + failedLookupLocations, supportedExtensions, state); - let resolvedFileName = loadModuleFromFile(supportedExtensions, candidate, failedLookupLocations, /*onlyRecordFailures*/ false, host, traceEnabled); - if (resolvedFileName) { - return { resolvedModule: { resolvedFileName }, failedLookupLocations }; - } - - resolvedFileName = loadNodeModuleFromDirectory(supportedExtensions, candidate, failedLookupLocations, /*onlyRecordFailures*/ false, host, traceEnabled); - return resolvedFileName - ? { resolvedModule: { resolvedFileName }, failedLookupLocations } - : { resolvedModule: undefined, failedLookupLocations }; + if (resolvedFileName) { + return createResolvedModule(resolvedFileName, /*isExternalLibraryImport*/false, failedLookupLocations); } - else { + + let isExternalLibraryImport = false; + if (moduleHasNonRelativeName(moduleName)) { if (traceEnabled) { trace(host, Diagnostics.Loading_module_0_from_node_modules_folder, moduleName); } - - return loadModuleFromNodeModules(moduleName, containingDirectory, host, traceEnabled); + resolvedFileName = loadModuleFromNodeModules(moduleName, containingDirectory, failedLookupLocations, state); + isExternalLibraryImport = resolvedFileName !== undefined; } + else { + const candidate = normalizePath(combinePaths(containingDirectory, moduleName)); + resolvedFileName = nodeLoadModuleByRelativeName(candidate, supportedExtensions, failedLookupLocations, /*onlyRecordFailures*/ false, state); + } + return createResolvedModule(resolvedFileName, isExternalLibraryImport, failedLookupLocations); + } + + function nodeLoadModuleByRelativeName(candidate: string, supportedExtensions: string[], failedLookupLocations: string[], + onlyRecordFailures: boolean, state: ModuleResolutionState): string { + + if (state.traceEnabled) { + trace(state.host, Diagnostics.Loading_module_as_file_Slash_folder_candidate_module_location_0, candidate); + } + + const resolvedFileName = loadModuleFromFile(candidate, supportedExtensions, failedLookupLocations, onlyRecordFailures, state); + + return resolvedFileName || loadNodeModuleFromDirectory(supportedExtensions, candidate, failedLookupLocations, onlyRecordFailures, state); } /* @internal */ @@ -396,20 +414,20 @@ namespace ts { * @param {boolean} onlyRecordFailures - if true then function won't try to actually load files but instead record all attempts as failures. This flag is necessary * in cases when we know upfront that all load attempts will fail (because containing folder does not exists) however we still need to record all failed lookup locations. */ - function loadModuleFromFile(extensions: string[], candidate: string, failedLookupLocation: string[], onlyRecordFailures: boolean, host: ModuleResolutionHost, traceEnabled: boolean): string { + function loadModuleFromFile(candidate: string, extensions: string[], failedLookupLocation: string[], onlyRecordFailures: boolean, state: ModuleResolutionState): string { return forEach(extensions, tryLoad); function tryLoad(ext: string): string { const fileName = fileExtensionIs(candidate, ext) ? candidate : candidate + ext; - if (!onlyRecordFailures && host.fileExists(fileName)) { - if (traceEnabled) { - trace(host, Diagnostics.File_0_exist_use_it_as_a_module_resolution_result, fileName); + if (!onlyRecordFailures && state.host.fileExists(fileName)) { + if (state.traceEnabled) { + trace(state.host, Diagnostics.File_0_exist_use_it_as_a_module_resolution_result, fileName); } return fileName; } else { - if (traceEnabled) { - trace(host, Diagnostics.File_0_does_not_exist, fileName); + if (state.traceEnabled) { + trace(state.host, Diagnostics.File_0_does_not_exist, fileName); } failedLookupLocation.push(fileName); return undefined; @@ -417,18 +435,18 @@ namespace ts { } } - function loadNodeModuleFromDirectory(extensions: string[], candidate: string, failedLookupLocation: string[], onlyRecordFailures: boolean, host: ModuleResolutionHost, traceEnabled: boolean): string { + function loadNodeModuleFromDirectory(extensions: string[], candidate: string, failedLookupLocation: string[], onlyRecordFailures: boolean, state: ModuleResolutionState): string { const packageJsonPath = combinePaths(candidate, "package.json"); - const directoryExists = !onlyRecordFailures && directoryProbablyExists(candidate, host); - if (directoryExists && host.fileExists(packageJsonPath)) { - if (traceEnabled) { - trace(host, Diagnostics.Found_package_json_at_0, packageJsonPath); + const directoryExists = !onlyRecordFailures && directoryProbablyExists(candidate, state.host); + if (directoryExists && state.host.fileExists(packageJsonPath)) { + if (state.traceEnabled) { + trace(state.host, Diagnostics.Found_package_json_at_0, packageJsonPath); } let jsonContent: { typings?: string }; try { - const jsonText = host.readFile(packageJsonPath); + const jsonText = state.host.readFile(packageJsonPath); jsonContent = jsonText ? <{ typings?: string }>JSON.parse(jsonText) : { typings: undefined }; } catch (e) { @@ -439,52 +457,51 @@ namespace ts { if (jsonContent.typings) { if (typeof jsonContent.typings === "string") { const typingsFile = normalizePath(combinePaths(candidate, jsonContent.typings)); - if (traceEnabled) { - trace(host, Diagnostics.package_json_has_typings_field_0_that_references_1, jsonContent.typings, typingsFile); + if (state.traceEnabled) { + trace(state.host, Diagnostics.package_json_has_typings_field_0_that_references_1, jsonContent.typings, typingsFile); } - const result = loadModuleFromFile(extensions, typingsFile, failedLookupLocation, !directoryProbablyExists(getDirectoryPath(typingsFile), host), host, traceEnabled); + const result = loadModuleFromFile(typingsFile, extensions, failedLookupLocation, !directoryProbablyExists(getDirectoryPath(typingsFile), state.host), state); if (result) { return result; } } - else if (traceEnabled) { - trace(host, Diagnostics.Expected_type_of_typings_field_in_package_json_to_be_string_got_0, typeof jsonContent.typings); + else if (state.traceEnabled) { + trace(state.host, Diagnostics.Expected_type_of_typings_field_in_package_json_to_be_string_got_0, typeof jsonContent.typings); } } else { - if (traceEnabled) { - trace(host, Diagnostics.package_json_does_not_have_typings_field); + if (state.traceEnabled) { + trace(state.host, Diagnostics.package_json_does_not_have_typings_field); } } } else { - if (traceEnabled) { - trace(host, Diagnostics.File_0_does_not_exist, packageJsonPath); + if (state.traceEnabled) { + trace(state.host, Diagnostics.File_0_does_not_exist, packageJsonPath); } // record package json as one of failed lookup locations - in the future if this file will appear it will invalidate resolution results failedLookupLocation.push(packageJsonPath); } - return loadModuleFromFile(extensions, combinePaths(candidate, "index"), failedLookupLocation, !directoryExists, host, traceEnabled); + return loadModuleFromFile(combinePaths(candidate, "index"), extensions, failedLookupLocation, !directoryExists, state); } - function loadModuleFromNodeModules(moduleName: string, directory: string, host: ModuleResolutionHost, traceEnabled: boolean): ResolvedModuleWithFailedLookupLocations { - const failedLookupLocations: string[] = []; + function loadModuleFromNodeModules(moduleName: string, directory: string, failedLookupLocations: string[], state: ModuleResolutionState): string { directory = normalizeSlashes(directory); while (true) { const baseName = getBaseFileName(directory); if (baseName !== "node_modules") { const nodeModulesFolder = combinePaths(directory, "node_modules"); - const nodeModulesFolderExists = directoryProbablyExists(nodeModulesFolder, host); + const nodeModulesFolderExists = directoryProbablyExists(nodeModulesFolder, state.host); const candidate = normalizePath(combinePaths(nodeModulesFolder, moduleName)); // Load only typescript files irrespective of allowJs option if loading from node modules - let result = loadModuleFromFile(supportedTypeScriptExtensions, candidate, failedLookupLocations, !nodeModulesFolderExists, host, traceEnabled); + let result = loadModuleFromFile(candidate, supportedTypeScriptExtensions, failedLookupLocations, !nodeModulesFolderExists, state); if (result) { - return { resolvedModule: { resolvedFileName: result, isExternalLibraryImport: true }, failedLookupLocations }; + return result; } - result = loadNodeModuleFromDirectory(supportedTypeScriptExtensions, candidate, failedLookupLocations, !nodeModulesFolderExists, host, traceEnabled); + result = loadNodeModuleFromDirectory(supportedTypeScriptExtensions, candidate, failedLookupLocations, !nodeModulesFolderExists, state); if (result) { - return { resolvedModule: { resolvedFileName: result, isExternalLibraryImport: true }, failedLookupLocations }; + return result; } } @@ -495,34 +512,20 @@ namespace ts { directory = parentPath; } - - return { resolvedModule: undefined, failedLookupLocations }; - } - - function nameStartsWithDotSlashOrDotDotSlash(name: string) { - const i = name.lastIndexOf("./", 1); - return i === 0 || (i === 1 && name.charCodeAt(0) === CharacterCodes.dot); - } - - function hasZeroOrOneAsteriskCharacter(str: string): boolean { - let seenAsterisk = false; - for (let i = 0; i < str.length; i++) { - if (str.charCodeAt(i) === CharacterCodes.asterisk) { - if (!seenAsterisk) { - seenAsterisk = true; - } - else { - // have already seen asterisk - return false; - } - } - } - return true; + return undefined; } export function classicNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost): ResolvedModuleWithFailedLookupLocations { - const traceEnabled = isTraceEnabled(compilerOptions, host); + const state = { compilerOptions, host, traceEnabled }; + const failedLookupLocations: string[] = []; + const supportedExtensions = getSupportedExtensions(compilerOptions); + let containingDirectory = getDirectoryPath(containingFile); + + const resolvedFileName = tryLoadModuleUsingOptionalResolutionSettings(moduleName, containingDirectory, loadModuleFromFile, failedLookupLocations, supportedExtensions, state); + if (resolvedFileName) { + return createResolvedModule(resolvedFileName, /*isExternalLibraryImport*/false, failedLookupLocations); + } // module names that contain '!' are used to reference resources and are not resolved to actual files on disk if (moduleName.indexOf("!") != -1) { @@ -532,46 +535,19 @@ namespace ts { return { resolvedModule: undefined, failedLookupLocations: [] }; } - let searchPath = getDirectoryPath(containingFile); - let searchName: string; - - const failedLookupLocations: string[] = []; - let referencedSourceFile: string; - const supportedExtensions = getSupportedExtensions(compilerOptions); while (true) { - searchName = normalizePath(combinePaths(searchPath, moduleName)); - referencedSourceFile = forEach(supportedExtensions, extension => { - if (extension === ".tsx" && !compilerOptions.jsx) { - // resolve .tsx files only if jsx support is enabled - // 'logical not' handles both undefined and None cases - return undefined; - } - - const candidate = searchName + extension; - if (host.fileExists(candidate)) { - if (traceEnabled) { - trace(host, Diagnostics.File_0_exist_use_it_as_a_module_resolution_result, candidate); - } - return candidate; - } - else { - if (traceEnabled) { - trace(host, Diagnostics.File_0_does_not_exist, candidate); - } - failedLookupLocations.push(candidate); - } - }); - + const searchName = normalizePath(combinePaths(containingDirectory, moduleName)); + const directoryName = getDirectoryPath(searchName); + referencedSourceFile = loadModuleFromFile(searchName, supportedExtensions, failedLookupLocations, !directoryProbablyExists(directoryName, host), state); if (referencedSourceFile) { break; } - - const parentPath = getDirectoryPath(searchPath); - if (parentPath === searchPath) { + const parentPath = getDirectoryPath(containingDirectory); + if (parentPath === containingDirectory) { break; } - searchPath = parentPath; + containingDirectory = parentPath; } return referencedSourceFile @@ -1628,29 +1604,8 @@ namespace ts { } } - if (options.moduleResolution === ModuleResolutionKind.BaseUrl) { - if (options.baseUrl === undefined && options.inferredBaseUrl === undefined) { - programDiagnostics.add(createCompilerDiagnostic(Diagnostics.moduleResolution_kind_baseUrl_cannot_be_used_without_specifying_baseUrl_option)); - } - } - else if (options.moduleResolution === undefined) { - // if module resolution kind is not specified it is an error to have baseUrl\paths\rootDirs and module === CommonJs - // since the former one implies moduleResolutionKind to be BaseUrl and the latter one - Node - if (options.module === ModuleKind.CommonJS && (options.baseUrl || options.paths || options.rootDirs)) { - programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Module_resolution_kind_cannot_be_determined_automatically_Please_specify_module_resolution_explicitly_via_moduleResolution_option)); - } - } - else { - // here it is known that moduleResolution is not baseurl and is not undefined - if (options.baseUrl !== undefined) { - programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_can_only_be_used_when_option_moduleResolution_is_baseUrl, "baseUrl")); - } - if (options.paths) { - programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_can_only_be_used_when_option_moduleResolution_is_baseUrl, "paths")); - } - if (options.rootDirs) { - programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_can_only_be_used_when_option_moduleResolution_is_baseUrl, "rootDirs")); - } + if (options.paths && options.baseUrl === undefined) { + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_paths_cannot_be_used_without_specifying_baseUrl_option)); } if (options.paths) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 15913bb71f0..cc94cbd9ce2 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2376,8 +2376,7 @@ namespace ts { export enum ModuleResolutionKind { Classic = 1, - NodeJs = 2, - BaseUrl = 3 + NodeJs = 2 } export type RootPaths = string[]; @@ -2442,8 +2441,6 @@ namespace ts { // Skip checking lib.d.ts to help speed up tests. /* @internal */ skipDefaultLibCheck?: boolean; - // inferred baseUrl - currently this will be set in 'parseJsonConfigFileContent' to 'baseDir' - /* @internal */ inferredBaseUrl?: string; [option: string]: string | number | boolean | TsConfigOnlyOptions; } diff --git a/src/harness/compilerRunner.ts b/src/harness/compilerRunner.ts index 36aa6238f0e..8b199559412 100644 --- a/src/harness/compilerRunner.ts +++ b/src/harness/compilerRunner.ts @@ -139,6 +139,14 @@ class CompilerBaselineRunner extends RunnerBase { } }); + it (`Correct module resolution tracing for ${fileName}`, () => { + if (options.traceModuleResolution) { + Harness.Baseline.runBaseline("Correct sourcemap content for " + fileName, justName.replace(/\.tsx?$/, ".trace.json"), () => { + return JSON.stringify(result.traceResults || [], undefined, 4); + }); + } + }); + // Source maps? it("Correct sourcemap content for " + fileName, () => { if (options.sourceMap || options.inlineSourceMap) { diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 31987030c2e..2b0c95c0a61 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -985,9 +985,6 @@ namespace Harness { if (harnessSettings) { setCompilerOptionsFromHarnessSetting(harnessSettings, options); } - if (options.inferredBaseUrl) { - options.inferredBaseUrl = ts.getNormalizedAbsolutePath(options.inferredBaseUrl, currentDirectory); - } if (options.rootDirs) { options.rootDirs = ts.map(options.rootDirs, d => ts.getNormalizedAbsolutePath(d, currentDirectory)); } @@ -1025,13 +1022,19 @@ namespace Harness { useCaseSensitiveFileNames, currentDirectory, options.newLine); + + let traceResults: string[]; + if (options.traceModuleResolution) { + traceResults = []; + compilerHost.trace = text => traceResults.push(text); + } const program = ts.createProgram(programFileNames, options, compilerHost); const emitResult = program.emit(); const errors = ts.getPreEmitDiagnostics(program); - const result = new CompilerResult(fileOutputs, errors, program, Harness.IO.getCurrentDirectory(), emitResult.sourceMaps); + const result = new CompilerResult(fileOutputs, errors, program, Harness.IO.getCurrentDirectory(), emitResult.sourceMaps, traceResults); return { result, options }; } @@ -1312,7 +1315,7 @@ namespace Harness { /** @param fileResults an array of strings for the fileName and an ITextWriter with its code */ constructor(fileResults: GeneratedFile[], errors: ts.Diagnostic[], public program: ts.Program, - public currentDirectoryForProgram: string, private sourceMapData: ts.SourceMapData[]) { + public currentDirectoryForProgram: string, private sourceMapData: ts.SourceMapData[], public traceResults: string[]) { for (const emittedFile of fileResults) { if (isDTS(emittedFile.fileName)) { diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index a0cac439729..6ab9cd896c1 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -547,7 +547,8 @@ namespace Harness.LanguageService { } directoryExists(path: string): boolean { - return false; + // for tests assume that directory exists + return true; } getExecutingFilePath(): string { diff --git a/src/services/services.ts b/src/services/services.ts index 28f7f848835..cb57d415c66 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2777,6 +2777,9 @@ namespace ts { return directoryProbablyExists(directoryName, host); } }; + if (host.trace) { + compilerHost.trace = message => host.trace(message); + } if (host.resolveModuleNames) { compilerHost.resolveModuleNames = (moduleNames, containingFile) => host.resolveModuleNames(moduleNames, containingFile); diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution1.js b/tests/baselines/reference/pathMappingBasedModuleResolution1.js deleted file mode 100644 index ef296c5d1a1..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution1.js +++ /dev/null @@ -1,30 +0,0 @@ -//// [tests/cases/compiler/pathMappingBasedModuleResolution1.ts] //// - -//// [file1.ts] - -// user defined base url - -import {x} from "folder2/file2" - -declare function use(a: any): void; - -use(x.toExponential()); - -//// [file2.ts] -export {x} from "./file3" - -//// [file3.ts] -export var x = 1; - -//// [file3.js] -"use strict"; -exports.x = 1; -//// [file2.js] -"use strict"; -var file3_1 = require("./file3"); -exports.x = file3_1.x; -//// [file1.js] -// user defined base url -"use strict"; -var file2_1 = require("folder2/file2"); -use(file2_1.x.toExponential()); diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution1.symbols b/tests/baselines/reference/pathMappingBasedModuleResolution1.symbols deleted file mode 100644 index 377cd6a86dc..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution1.symbols +++ /dev/null @@ -1,25 +0,0 @@ -=== tests/cases/compiler/root/folder1/file1.ts === - -// user defined base url - -import {x} from "folder2/file2" ->x : Symbol(x, Decl(file1.ts, 3, 8)) - -declare function use(a: any): void; ->use : Symbol(use, Decl(file1.ts, 3, 31)) ->a : Symbol(a, Decl(file1.ts, 5, 21)) - -use(x.toExponential()); ->use : Symbol(use, Decl(file1.ts, 3, 31)) ->x.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) ->x : Symbol(x, Decl(file1.ts, 3, 8)) ->toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) - -=== tests/cases/compiler/root/folder2/file2.ts === -export {x} from "./file3" ->x : Symbol(x, Decl(file2.ts, 0, 8)) - -=== tests/cases/compiler/root/folder2/file3.ts === -export var x = 1; ->x : Symbol(x, Decl(file3.ts, 0, 10)) - diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution1.types b/tests/baselines/reference/pathMappingBasedModuleResolution1.types deleted file mode 100644 index 68fc42a28f2..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution1.types +++ /dev/null @@ -1,28 +0,0 @@ -=== tests/cases/compiler/root/folder1/file1.ts === - -// user defined base url - -import {x} from "folder2/file2" ->x : number - -declare function use(a: any): void; ->use : (a: any) => void ->a : any - -use(x.toExponential()); ->use(x.toExponential()) : void ->use : (a: any) => void ->x.toExponential() : string ->x.toExponential : (fractionDigits?: number) => string ->x : number ->toExponential : (fractionDigits?: number) => string - -=== tests/cases/compiler/root/folder2/file2.ts === -export {x} from "./file3" ->x : number - -=== tests/cases/compiler/root/folder2/file3.ts === -export var x = 1; ->x : number ->1 : number - diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution10.js b/tests/baselines/reference/pathMappingBasedModuleResolution10.js deleted file mode 100644 index 167a4d4e365..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution10.js +++ /dev/null @@ -1,38 +0,0 @@ -//// [tests/cases/compiler/pathMappingBasedModuleResolution10.ts] //// - -//// [file1.ts] -import {x} from "./file2" // should be resolved to 'generated/folder1/file2.ts' - -export var z = x.toExponential(); - -//// [file2.ts] -export {x} from "folder1/file3" // should be resolved to 'folder1/file3.ts' - -//// [file3.ts] -export var x = 1; - -//// [file3.ts] -import {z as y} from "../folder1/file1" // should be resolved to 'folder1/file1.ts' -let z = y.toLowerCase(); - - -//// [file3.js] -define(["require", "exports"], function (require, exports) { - "use strict"; - exports.x = 1; -}); -//// [file2.js] -define(["require", "exports", "folder1/file3"], function (require, exports, file3_1) { - "use strict"; - exports.x = file3_1.x; // should be resolved to 'folder1/file3.ts' -}); -//// [file1.js] -define(["require", "exports", "./file2"], function (require, exports, file2_1) { - "use strict"; - exports.z = file2_1.x.toExponential(); -}); -//// [file3.js] -define(["require", "exports", "../folder1/file1"], function (require, exports, file1_1) { - "use strict"; - var z = file1_1.z.toLowerCase(); -}); diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution10.symbols b/tests/baselines/reference/pathMappingBasedModuleResolution10.symbols deleted file mode 100644 index e01d12fc7e3..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution10.symbols +++ /dev/null @@ -1,29 +0,0 @@ -=== tests/cases/compiler/root/folder1/file1.ts === -import {x} from "./file2" // should be resolved to 'generated/folder1/file2.ts' ->x : Symbol(x, Decl(file1.ts, 0, 8)) - -export var z = x.toExponential(); ->z : Symbol(z, Decl(file1.ts, 2, 10)) ->x.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) ->x : Symbol(x, Decl(file1.ts, 0, 8)) ->toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) - -=== tests/cases/compiler/root/generated/folder1/file2.ts === -export {x} from "folder1/file3" // should be resolved to 'folder1/file3.ts' ->x : Symbol(x, Decl(file2.ts, 0, 8)) - -=== tests/cases/compiler/root/folder1/file3.ts === -export var x = 1; ->x : Symbol(x, Decl(file3.ts, 0, 10)) - -=== tests/cases/compiler/root/generated/folder2/file3.ts === -import {z as y} from "../folder1/file1" // should be resolved to 'folder1/file1.ts' ->z : Symbol(y, Decl(file3.ts, 0, 8)) ->y : Symbol(y, Decl(file3.ts, 0, 8)) - -let z = y.toLowerCase(); ->z : Symbol(z, Decl(file3.ts, 1, 3)) ->y.toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --)) ->y : Symbol(y, Decl(file3.ts, 0, 8)) ->toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --)) - diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution10.types b/tests/baselines/reference/pathMappingBasedModuleResolution10.types deleted file mode 100644 index ac3caa8b532..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution10.types +++ /dev/null @@ -1,32 +0,0 @@ -=== tests/cases/compiler/root/folder1/file1.ts === -import {x} from "./file2" // should be resolved to 'generated/folder1/file2.ts' ->x : number - -export var z = x.toExponential(); ->z : string ->x.toExponential() : string ->x.toExponential : (fractionDigits?: number) => string ->x : number ->toExponential : (fractionDigits?: number) => string - -=== tests/cases/compiler/root/generated/folder1/file2.ts === -export {x} from "folder1/file3" // should be resolved to 'folder1/file3.ts' ->x : number - -=== tests/cases/compiler/root/folder1/file3.ts === -export var x = 1; ->x : number ->1 : number - -=== tests/cases/compiler/root/generated/folder2/file3.ts === -import {z as y} from "../folder1/file1" // should be resolved to 'folder1/file1.ts' ->z : string ->y : string - -let z = y.toLowerCase(); ->z : string ->y.toLowerCase() : string ->y.toLowerCase : () => string ->y : string ->toLowerCase : () => string - diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution10_1.js b/tests/baselines/reference/pathMappingBasedModuleResolution10_1.js deleted file mode 100644 index b9dc60f053a..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution10_1.js +++ /dev/null @@ -1,38 +0,0 @@ -//// [tests/cases/compiler/pathMappingBasedModuleResolution10_1.ts] //// - -//// [file2.ts] -export {x} from "folder1/file3" // should be resolved to 'folder1/file3.ts' - -//// [file3.ts] -export var x = 1; - -//// [file3.ts] -import {z as y} from "../folder1/file1" // should be resolved to 'folder1/file1.ts' -let z = y.toLowerCase(); - -//// [file1.ts] -import {x} from "./file2" // should be resolved to 'generated/folder1/file2.ts' - -export var z = x.toExponential(); - - -//// [file3.js] -define(["require", "exports"], function (require, exports) { - "use strict"; - exports.x = 1; -}); -//// [file2.js] -define(["require", "exports", "folder1/file3"], function (require, exports, file3_1) { - "use strict"; - exports.x = file3_1.x; // should be resolved to 'folder1/file3.ts' -}); -//// [file1.js] -define(["require", "exports", "./file2"], function (require, exports, file2_1) { - "use strict"; - exports.z = file2_1.x.toExponential(); -}); -//// [file3.js] -define(["require", "exports", "../folder1/file1"], function (require, exports, file1_1) { - "use strict"; - var z = file1_1.z.toLowerCase(); -}); diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution10_1.symbols b/tests/baselines/reference/pathMappingBasedModuleResolution10_1.symbols deleted file mode 100644 index dbc1fc792d4..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution10_1.symbols +++ /dev/null @@ -1,29 +0,0 @@ -=== c:/root/generated/folder1/file2.ts === -export {x} from "folder1/file3" // should be resolved to 'folder1/file3.ts' ->x : Symbol(x, Decl(file2.ts, 0, 8)) - -=== c:/root/folder1/file3.ts === -export var x = 1; ->x : Symbol(x, Decl(file3.ts, 0, 10)) - -=== c:/root/generated/folder2/file3.ts === -import {z as y} from "../folder1/file1" // should be resolved to 'folder1/file1.ts' ->z : Symbol(y, Decl(file3.ts, 0, 8)) ->y : Symbol(y, Decl(file3.ts, 0, 8)) - -let z = y.toLowerCase(); ->z : Symbol(z, Decl(file3.ts, 1, 3)) ->y.toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --)) ->y : Symbol(y, Decl(file3.ts, 0, 8)) ->toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --)) - -=== c:/root/folder1/file1.ts === -import {x} from "./file2" // should be resolved to 'generated/folder1/file2.ts' ->x : Symbol(x, Decl(file1.ts, 0, 8)) - -export var z = x.toExponential(); ->z : Symbol(z, Decl(file1.ts, 2, 10)) ->x.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) ->x : Symbol(x, Decl(file1.ts, 0, 8)) ->toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) - diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution10_1.types b/tests/baselines/reference/pathMappingBasedModuleResolution10_1.types deleted file mode 100644 index bf617b2b1a3..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution10_1.types +++ /dev/null @@ -1,32 +0,0 @@ -=== c:/root/generated/folder1/file2.ts === -export {x} from "folder1/file3" // should be resolved to 'folder1/file3.ts' ->x : number - -=== c:/root/folder1/file3.ts === -export var x = 1; ->x : number ->1 : number - -=== c:/root/generated/folder2/file3.ts === -import {z as y} from "../folder1/file1" // should be resolved to 'folder1/file1.ts' ->z : string ->y : string - -let z = y.toLowerCase(); ->z : string ->y.toLowerCase() : string ->y.toLowerCase : () => string ->y : string ->toLowerCase : () => string - -=== c:/root/folder1/file1.ts === -import {x} from "./file2" // should be resolved to 'generated/folder1/file2.ts' ->x : number - -export var z = x.toExponential(); ->z : string ->x.toExponential() : string ->x.toExponential : (fractionDigits?: number) => string ->x : number ->toExponential : (fractionDigits?: number) => string - diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution10_2.js b/tests/baselines/reference/pathMappingBasedModuleResolution10_2.js deleted file mode 100644 index e4a83c186a1..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution10_2.js +++ /dev/null @@ -1,38 +0,0 @@ -//// [tests/cases/compiler/pathMappingBasedModuleResolution10_2.ts] //// - -//// [file2.ts] -export {x} from "folder1/file3" // should be resolved to 'folder1/file3.ts' - -//// [file3.ts] -export var x = 1; - -//// [file3.ts] -import {z as y} from "../folder1/file1" // should be resolved to 'folder1/file1.ts' -let z = y.toLowerCase(); - -//// [file1.ts] -import {x} from "./file2" // should be resolved to 'generated/folder1/file2.ts' - -export var z = x.toExponential(); - - -//// [file3.js] -define(["require", "exports"], function (require, exports) { - "use strict"; - exports.x = 1; -}); -//// [file2.js] -define(["require", "exports", "folder1/file3"], function (require, exports, file3_1) { - "use strict"; - exports.x = file3_1.x; // should be resolved to 'folder1/file3.ts' -}); -//// [file1.js] -define(["require", "exports", "./file2"], function (require, exports, file2_1) { - "use strict"; - exports.z = file2_1.x.toExponential(); -}); -//// [file3.js] -define(["require", "exports", "../folder1/file1"], function (require, exports, file1_1) { - "use strict"; - var z = file1_1.z.toLowerCase(); -}); diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution10_2.symbols b/tests/baselines/reference/pathMappingBasedModuleResolution10_2.symbols deleted file mode 100644 index 64a308338c9..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution10_2.symbols +++ /dev/null @@ -1,29 +0,0 @@ -=== c:/root/src/generated/folder1/file2.ts === -export {x} from "folder1/file3" // should be resolved to 'folder1/file3.ts' ->x : Symbol(x, Decl(file2.ts, 0, 8)) - -=== c:/root/src/folder1/file3.ts === -export var x = 1; ->x : Symbol(x, Decl(file3.ts, 0, 10)) - -=== c:/root/src/generated/folder2/file3.ts === -import {z as y} from "../folder1/file1" // should be resolved to 'folder1/file1.ts' ->z : Symbol(y, Decl(file3.ts, 0, 8)) ->y : Symbol(y, Decl(file3.ts, 0, 8)) - -let z = y.toLowerCase(); ->z : Symbol(z, Decl(file3.ts, 1, 3)) ->y.toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --)) ->y : Symbol(y, Decl(file3.ts, 0, 8)) ->toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --)) - -=== c:/root/src/folder1/file1.ts === -import {x} from "./file2" // should be resolved to 'generated/folder1/file2.ts' ->x : Symbol(x, Decl(file1.ts, 0, 8)) - -export var z = x.toExponential(); ->z : Symbol(z, Decl(file1.ts, 2, 10)) ->x.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) ->x : Symbol(x, Decl(file1.ts, 0, 8)) ->toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) - diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution10_2.types b/tests/baselines/reference/pathMappingBasedModuleResolution10_2.types deleted file mode 100644 index 0fc9270c667..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution10_2.types +++ /dev/null @@ -1,32 +0,0 @@ -=== c:/root/src/generated/folder1/file2.ts === -export {x} from "folder1/file3" // should be resolved to 'folder1/file3.ts' ->x : number - -=== c:/root/src/folder1/file3.ts === -export var x = 1; ->x : number ->1 : number - -=== c:/root/src/generated/folder2/file3.ts === -import {z as y} from "../folder1/file1" // should be resolved to 'folder1/file1.ts' ->z : string ->y : string - -let z = y.toLowerCase(); ->z : string ->y.toLowerCase() : string ->y.toLowerCase : () => string ->y : string ->toLowerCase : () => string - -=== c:/root/src/folder1/file1.ts === -import {x} from "./file2" // should be resolved to 'generated/folder1/file2.ts' ->x : number - -export var z = x.toExponential(); ->z : string ->x.toExponential() : string ->x.toExponential : (fractionDigits?: number) => string ->x : number ->toExponential : (fractionDigits?: number) => string - diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution11.js b/tests/baselines/reference/pathMappingBasedModuleResolution11.js deleted file mode 100644 index 614357ec53f..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution11.js +++ /dev/null @@ -1,38 +0,0 @@ -//// [tests/cases/compiler/pathMappingBasedModuleResolution11.ts] //// - -//// [file1.ts] -import {x} from "./file2" // should be resolved to 'generated/folder1/file2/file.ts' - -export var z = x.toExponential(); - -//// [file.ts] -export {x} from "folder1/file3" // should be resolved to 'folder1/file3.ts' - -//// [file3.ts] -export var x = 1; - -//// [file3.ts] -import {z as y} from "../folder1/file1" // should be resolved to 'folder1/file1.ts' -let z = y.toLowerCase(); - - -//// [file3.js] -define(["require", "exports"], function (require, exports) { - "use strict"; - exports.x = 1; -}); -//// [file.js] -define(["require", "exports", "folder1/file3"], function (require, exports, file3_1) { - "use strict"; - exports.x = file3_1.x; // should be resolved to 'folder1/file3.ts' -}); -//// [file1.js] -define(["require", "exports", "./file2"], function (require, exports, file2_1) { - "use strict"; - exports.z = file2_1.x.toExponential(); -}); -//// [file3.js] -define(["require", "exports", "../folder1/file1"], function (require, exports, file1_1) { - "use strict"; - var z = file1_1.z.toLowerCase(); -}); diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution11.symbols b/tests/baselines/reference/pathMappingBasedModuleResolution11.symbols deleted file mode 100644 index f453dafe2a2..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution11.symbols +++ /dev/null @@ -1,29 +0,0 @@ -=== tests/cases/compiler/root/folder1/file1.ts === -import {x} from "./file2" // should be resolved to 'generated/folder1/file2/file.ts' ->x : Symbol(x, Decl(file1.ts, 0, 8)) - -export var z = x.toExponential(); ->z : Symbol(z, Decl(file1.ts, 2, 10)) ->x.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) ->x : Symbol(x, Decl(file1.ts, 0, 8)) ->toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) - -=== tests/cases/compiler/root/generated/folder1/file2/file.ts === -export {x} from "folder1/file3" // should be resolved to 'folder1/file3.ts' ->x : Symbol(x, Decl(file.ts, 0, 8)) - -=== tests/cases/compiler/root/folder1/file3.ts === -export var x = 1; ->x : Symbol(x, Decl(file3.ts, 0, 10)) - -=== tests/cases/compiler/root/generated/folder2/file3.ts === -import {z as y} from "../folder1/file1" // should be resolved to 'folder1/file1.ts' ->z : Symbol(y, Decl(file3.ts, 0, 8)) ->y : Symbol(y, Decl(file3.ts, 0, 8)) - -let z = y.toLowerCase(); ->z : Symbol(z, Decl(file3.ts, 1, 3)) ->y.toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --)) ->y : Symbol(y, Decl(file3.ts, 0, 8)) ->toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --)) - diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution11.types b/tests/baselines/reference/pathMappingBasedModuleResolution11.types deleted file mode 100644 index 45717088577..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution11.types +++ /dev/null @@ -1,32 +0,0 @@ -=== tests/cases/compiler/root/folder1/file1.ts === -import {x} from "./file2" // should be resolved to 'generated/folder1/file2/file.ts' ->x : number - -export var z = x.toExponential(); ->z : string ->x.toExponential() : string ->x.toExponential : (fractionDigits?: number) => string ->x : number ->toExponential : (fractionDigits?: number) => string - -=== tests/cases/compiler/root/generated/folder1/file2/file.ts === -export {x} from "folder1/file3" // should be resolved to 'folder1/file3.ts' ->x : number - -=== tests/cases/compiler/root/folder1/file3.ts === -export var x = 1; ->x : number ->1 : number - -=== tests/cases/compiler/root/generated/folder2/file3.ts === -import {z as y} from "../folder1/file1" // should be resolved to 'folder1/file1.ts' ->z : string ->y : string - -let z = y.toLowerCase(); ->z : string ->y.toLowerCase() : string ->y.toLowerCase : () => string ->y : string ->toLowerCase : () => string - diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution1_1.js b/tests/baselines/reference/pathMappingBasedModuleResolution1_1.js deleted file mode 100644 index 1cc12f70d5a..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution1_1.js +++ /dev/null @@ -1,30 +0,0 @@ -//// [tests/cases/compiler/pathMappingBasedModuleResolution1_1.ts] //// - -//// [file1.ts] - -// user defined base url - -import {x} from "folder2/file2" - -declare function use(a: any): void; - -use(x.toExponential()); - -//// [file2.ts] -export {x} from "./file3" - -//// [file3.ts] -export var x = 1; - -//// [file3.js] -"use strict"; -exports.x = 1; -//// [file2.js] -"use strict"; -var file3_1 = require("./file3"); -exports.x = file3_1.x; -//// [file1.js] -// user defined base url -"use strict"; -var file2_1 = require("folder2/file2"); -use(file2_1.x.toExponential()); diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution1_1.symbols b/tests/baselines/reference/pathMappingBasedModuleResolution1_1.symbols deleted file mode 100644 index 20f69963c76..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution1_1.symbols +++ /dev/null @@ -1,25 +0,0 @@ -=== c:/root/folder1/file1.ts === - -// user defined base url - -import {x} from "folder2/file2" ->x : Symbol(x, Decl(file1.ts, 3, 8)) - -declare function use(a: any): void; ->use : Symbol(use, Decl(file1.ts, 3, 31)) ->a : Symbol(a, Decl(file1.ts, 5, 21)) - -use(x.toExponential()); ->use : Symbol(use, Decl(file1.ts, 3, 31)) ->x.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) ->x : Symbol(x, Decl(file1.ts, 3, 8)) ->toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) - -=== c:/root/folder2/file2.ts === -export {x} from "./file3" ->x : Symbol(x, Decl(file2.ts, 0, 8)) - -=== c:/root/folder2/file3.ts === -export var x = 1; ->x : Symbol(x, Decl(file3.ts, 0, 10)) - diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution1_classic.errors.txt b/tests/baselines/reference/pathMappingBasedModuleResolution1_classic.errors.txt new file mode 100644 index 00000000000..85e25ec99fb --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution1_classic.errors.txt @@ -0,0 +1,7 @@ +error TS5060: Option 'paths' cannot be used without specifying '--baseUrl' option. + + +!!! error TS5060: Option 'paths' cannot be used without specifying '--baseUrl' option. +==== c:/root/f1.ts (0 errors) ==== + export var x = 1; + \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution1_classic.js b/tests/baselines/reference/pathMappingBasedModuleResolution1_classic.js new file mode 100644 index 00000000000..1a1bd387dce --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution1_classic.js @@ -0,0 +1,9 @@ +//// [f1.ts] +export var x = 1; + + +//// [f1.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + exports.x = 1; +}); diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution1_classic.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution1_classic.trace.json new file mode 100644 index 00000000000..0637a088a01 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution1_classic.trace.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution1_node.errors.txt b/tests/baselines/reference/pathMappingBasedModuleResolution1_node.errors.txt new file mode 100644 index 00000000000..85e25ec99fb --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution1_node.errors.txt @@ -0,0 +1,7 @@ +error TS5060: Option 'paths' cannot be used without specifying '--baseUrl' option. + + +!!! error TS5060: Option 'paths' cannot be used without specifying '--baseUrl' option. +==== c:/root/f1.ts (0 errors) ==== + export var x = 1; + \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution1_node.js b/tests/baselines/reference/pathMappingBasedModuleResolution1_node.js new file mode 100644 index 00000000000..5fcaa23b976 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution1_node.js @@ -0,0 +1,7 @@ +//// [f1.ts] +export var x = 1; + + +//// [f1.js] +"use strict"; +exports.x = 1; diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution1_node.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution1_node.trace.json new file mode 100644 index 00000000000..0637a088a01 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution1_node.trace.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution2.js b/tests/baselines/reference/pathMappingBasedModuleResolution2.js deleted file mode 100644 index 40cdd1fdfd4..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution2.js +++ /dev/null @@ -1,26 +0,0 @@ -//// [tests/cases/compiler/pathMappingBasedModuleResolution2.ts] //// - -//// [file1.ts] -import {x} from "folder2/file2" - -declare function use(a: any): void; - -use(x.toExponential()); - -//// [file2.ts] -export {x} from "./file3" - -//// [file3.ts] -export var x = 1; - -//// [file3.js] -"use strict"; -exports.x = 1; -//// [file2.js] -"use strict"; -var file3_1 = require("./file3"); -exports.x = file3_1.x; -//// [file1.js] -"use strict"; -var file2_1 = require("folder2/file2"); -use(file2_1.x.toExponential()); diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution2.symbols b/tests/baselines/reference/pathMappingBasedModuleResolution2.symbols deleted file mode 100644 index 94f458ff1d3..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution2.symbols +++ /dev/null @@ -1,22 +0,0 @@ -=== tests/cases/compiler/root/folder1/file1.ts === -import {x} from "folder2/file2" ->x : Symbol(x, Decl(file1.ts, 0, 8)) - -declare function use(a: any): void; ->use : Symbol(use, Decl(file1.ts, 0, 31)) ->a : Symbol(a, Decl(file1.ts, 2, 21)) - -use(x.toExponential()); ->use : Symbol(use, Decl(file1.ts, 0, 31)) ->x.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) ->x : Symbol(x, Decl(file1.ts, 0, 8)) ->toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) - -=== tests/cases/compiler/root/folder2/file2.ts === -export {x} from "./file3" ->x : Symbol(x, Decl(file2.ts, 0, 8)) - -=== tests/cases/compiler/root/folder2/file3.ts === -export var x = 1; ->x : Symbol(x, Decl(file3.ts, 0, 10)) - diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution2.types b/tests/baselines/reference/pathMappingBasedModuleResolution2.types deleted file mode 100644 index ff6ef52f321..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution2.types +++ /dev/null @@ -1,25 +0,0 @@ -=== tests/cases/compiler/root/folder1/file1.ts === -import {x} from "folder2/file2" ->x : number - -declare function use(a: any): void; ->use : (a: any) => void ->a : any - -use(x.toExponential()); ->use(x.toExponential()) : void ->use : (a: any) => void ->x.toExponential() : string ->x.toExponential : (fractionDigits?: number) => string ->x : number ->toExponential : (fractionDigits?: number) => string - -=== tests/cases/compiler/root/folder2/file2.ts === -export {x} from "./file3" ->x : number - -=== tests/cases/compiler/root/folder2/file3.ts === -export var x = 1; ->x : number ->1 : number - diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution2_1.js b/tests/baselines/reference/pathMappingBasedModuleResolution2_1.js deleted file mode 100644 index 115315fec11..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution2_1.js +++ /dev/null @@ -1,26 +0,0 @@ -//// [tests/cases/compiler/pathMappingBasedModuleResolution2_1.ts] //// - -//// [file1.ts] -import {x} from "folder2/file2" - -declare function use(a: any): void; - -use(x.toExponential()); - -//// [file2.ts] -export {x} from "./file3" - -//// [file3.ts] -export var x = 1; - -//// [file3.js] -"use strict"; -exports.x = 1; -//// [file2.js] -"use strict"; -var file3_1 = require("./file3"); -exports.x = file3_1.x; -//// [file1.js] -"use strict"; -var file2_1 = require("folder2/file2"); -use(file2_1.x.toExponential()); diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution6.errors.txt b/tests/baselines/reference/pathMappingBasedModuleResolution2_classic.errors.txt similarity index 100% rename from tests/baselines/reference/pathMappingBasedModuleResolution6.errors.txt rename to tests/baselines/reference/pathMappingBasedModuleResolution2_classic.errors.txt diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution6.js b/tests/baselines/reference/pathMappingBasedModuleResolution2_classic.js similarity index 100% rename from tests/baselines/reference/pathMappingBasedModuleResolution6.js rename to tests/baselines/reference/pathMappingBasedModuleResolution2_classic.js diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution2_classic.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution2_classic.trace.json new file mode 100644 index 00000000000..0637a088a01 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution2_classic.trace.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution2_node.errors.txt b/tests/baselines/reference/pathMappingBasedModuleResolution2_node.errors.txt new file mode 100644 index 00000000000..ad954bd142b --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution2_node.errors.txt @@ -0,0 +1,8 @@ +error TS5061: Pattern '*1*' can have at most one '*' character +error TS5062: Substitution '*2*' in pattern '*1*' in can have at most one '*' character + + +!!! error TS5061: Pattern '*1*' can have at most one '*' character +!!! error TS5062: Substitution '*2*' in pattern '*1*' in can have at most one '*' character +==== tests/cases/compiler/root/src/folder1/file1.ts (0 errors) ==== + export var x = 1; \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution5.js b/tests/baselines/reference/pathMappingBasedModuleResolution2_node.js similarity index 100% rename from tests/baselines/reference/pathMappingBasedModuleResolution5.js rename to tests/baselines/reference/pathMappingBasedModuleResolution2_node.js diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution2_node.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution2_node.trace.json new file mode 100644 index 00000000000..0637a088a01 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution2_node.trace.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution3.js b/tests/baselines/reference/pathMappingBasedModuleResolution3.js deleted file mode 100644 index b7d1256da43..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution3.js +++ /dev/null @@ -1,26 +0,0 @@ -//// [tests/cases/compiler/pathMappingBasedModuleResolution3.ts] //// - -//// [file1.ts] -import {x} from "folder2/file2" - -declare function use(a: any): void; - -use(x.toExponential()); - -//// [file2.ts] -export {x} from "./file3" - -//// [file3.ts] -export var x = 1; - -//// [file3.js] -"use strict"; -exports.x = 1; -//// [file2.js] -"use strict"; -var file3_1 = require("./file3"); -exports.x = file3_1.x; -//// [file1.js] -"use strict"; -var file2_1 = require("folder2/file2"); -use(file2_1.x.toExponential()); diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution3.symbols b/tests/baselines/reference/pathMappingBasedModuleResolution3.symbols deleted file mode 100644 index b071ecec087..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution3.symbols +++ /dev/null @@ -1,22 +0,0 @@ -=== tests/cases/compiler/root/src/folder1/file1.ts === -import {x} from "folder2/file2" ->x : Symbol(x, Decl(file1.ts, 0, 8)) - -declare function use(a: any): void; ->use : Symbol(use, Decl(file1.ts, 0, 31)) ->a : Symbol(a, Decl(file1.ts, 2, 21)) - -use(x.toExponential()); ->use : Symbol(use, Decl(file1.ts, 0, 31)) ->x.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) ->x : Symbol(x, Decl(file1.ts, 0, 8)) ->toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) - -=== tests/cases/compiler/root/src/folder2/file2.ts === -export {x} from "./file3" ->x : Symbol(x, Decl(file2.ts, 0, 8)) - -=== tests/cases/compiler/root/src/folder2/file3.ts === -export var x = 1; ->x : Symbol(x, Decl(file3.ts, 0, 10)) - diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution3.types b/tests/baselines/reference/pathMappingBasedModuleResolution3.types deleted file mode 100644 index 15428de5560..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution3.types +++ /dev/null @@ -1,25 +0,0 @@ -=== tests/cases/compiler/root/src/folder1/file1.ts === -import {x} from "folder2/file2" ->x : number - -declare function use(a: any): void; ->use : (a: any) => void ->a : any - -use(x.toExponential()); ->use(x.toExponential()) : void ->use : (a: any) => void ->x.toExponential() : string ->x.toExponential : (fractionDigits?: number) => string ->x : number ->toExponential : (fractionDigits?: number) => string - -=== tests/cases/compiler/root/src/folder2/file2.ts === -export {x} from "./file3" ->x : number - -=== tests/cases/compiler/root/src/folder2/file3.ts === -export var x = 1; ->x : number ->1 : number - diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution3_1.js b/tests/baselines/reference/pathMappingBasedModuleResolution3_1.js deleted file mode 100644 index 72fe7d61726..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution3_1.js +++ /dev/null @@ -1,26 +0,0 @@ -//// [tests/cases/compiler/pathMappingBasedModuleResolution3_1.ts] //// - -//// [file1.ts] -import {x} from "folder2/file2" - -declare function use(a: any): void; - -use(x.toExponential()); - -//// [file2.ts] -export {x} from "./file3" - -//// [file3.ts] -export var x = 1; - -//// [file3.js] -"use strict"; -exports.x = 1; -//// [file2.js] -"use strict"; -var file3_1 = require("./file3"); -exports.x = file3_1.x; -//// [file1.js] -"use strict"; -var file2_1 = require("folder2/file2"); -use(file2_1.x.toExponential()); diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution3_1.symbols b/tests/baselines/reference/pathMappingBasedModuleResolution3_1.symbols deleted file mode 100644 index 835d16d46f4..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution3_1.symbols +++ /dev/null @@ -1,22 +0,0 @@ -=== c:/root/src/folder1/file1.ts === -import {x} from "folder2/file2" ->x : Symbol(x, Decl(file1.ts, 0, 8)) - -declare function use(a: any): void; ->use : Symbol(use, Decl(file1.ts, 0, 31)) ->a : Symbol(a, Decl(file1.ts, 2, 21)) - -use(x.toExponential()); ->use : Symbol(use, Decl(file1.ts, 0, 31)) ->x.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) ->x : Symbol(x, Decl(file1.ts, 0, 8)) ->toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) - -=== c:/root/src/folder2/file2.ts === -export {x} from "./file3" ->x : Symbol(x, Decl(file2.ts, 0, 8)) - -=== c:/root/src/folder2/file3.ts === -export var x = 1; ->x : Symbol(x, Decl(file3.ts, 0, 10)) - diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution3_1.types b/tests/baselines/reference/pathMappingBasedModuleResolution3_1.types deleted file mode 100644 index 8db89ab12b7..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution3_1.types +++ /dev/null @@ -1,25 +0,0 @@ -=== c:/root/src/folder1/file1.ts === -import {x} from "folder2/file2" ->x : number - -declare function use(a: any): void; ->use : (a: any) => void ->a : any - -use(x.toExponential()); ->use(x.toExponential()) : void ->use : (a: any) => void ->x.toExponential() : string ->x.toExponential : (fractionDigits?: number) => string ->x : number ->toExponential : (fractionDigits?: number) => string - -=== c:/root/src/folder2/file2.ts === -export {x} from "./file3" ->x : number - -=== c:/root/src/folder2/file3.ts === -export var x = 1; ->x : number ->1 : number - diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution3_classic.js b/tests/baselines/reference/pathMappingBasedModuleResolution3_classic.js new file mode 100644 index 00000000000..15867b085ea --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution3_classic.js @@ -0,0 +1,42 @@ +//// [tests/cases/compiler/pathMappingBasedModuleResolution3_classic.ts] //// + +//// [file1.ts] + +// baseUrl set via command line + +import {x} from "folder2/file2" +declare function use(a: any): void; +use(x.toExponential()); + +//// [file2.ts] +import {x as a} from "./file3" // found with baseurl +import {y as b} from "file4" // found with fallback +export var x = a + b; + +//// [file3.ts] +export var x = 1; + +//// [file4.ts] +export var y = 100; + +//// [file3.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + exports.x = 1; +}); +//// [file4.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + exports.y = 100; +}); +//// [file2.js] +define(["require", "exports", "./file3", "file4"], function (require, exports, file3_1, file4_1) { + "use strict"; + exports.x = file3_1.x + file4_1.y; +}); +//// [file1.js] +// baseUrl set via command line +define(["require", "exports", "folder2/file2"], function (require, exports, file2_1) { + "use strict"; + use(file2_1.x.toExponential()); +}); diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution3_classic.symbols b/tests/baselines/reference/pathMappingBasedModuleResolution3_classic.symbols new file mode 100644 index 00000000000..97ec40d4cb4 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution3_classic.symbols @@ -0,0 +1,39 @@ +=== c:/root/folder1/file1.ts === + +// baseUrl set via command line + +import {x} from "folder2/file2" +>x : Symbol(x, Decl(file1.ts, 3, 8)) + +declare function use(a: any): void; +>use : Symbol(use, Decl(file1.ts, 3, 31)) +>a : Symbol(a, Decl(file1.ts, 4, 21)) + +use(x.toExponential()); +>use : Symbol(use, Decl(file1.ts, 3, 31)) +>x.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(file1.ts, 3, 8)) +>toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) + +=== c:/root/folder2/file2.ts === +import {x as a} from "./file3" // found with baseurl +>x : Symbol(a, Decl(file2.ts, 0, 8)) +>a : Symbol(a, Decl(file2.ts, 0, 8)) + +import {y as b} from "file4" // found with fallback +>y : Symbol(b, Decl(file2.ts, 1, 8)) +>b : Symbol(b, Decl(file2.ts, 1, 8)) + +export var x = a + b; +>x : Symbol(x, Decl(file2.ts, 2, 10)) +>a : Symbol(a, Decl(file2.ts, 0, 8)) +>b : Symbol(b, Decl(file2.ts, 1, 8)) + +=== c:/root/folder2/file3.ts === +export var x = 1; +>x : Symbol(x, Decl(file3.ts, 0, 10)) + +=== c:/file4.ts === +export var y = 100; +>y : Symbol(y, Decl(file4.ts, 0, 10)) + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution3_classic.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution3_classic.trace.json new file mode 100644 index 00000000000..ac82f87bcee --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution3_classic.trace.json @@ -0,0 +1,27 @@ +[ + "======== Resolving module 'folder2/file2' from 'c:/root/folder1/file1.ts'. ========", + "Explicitly specified module resolution kind: 'Classic'.", + "'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name 'folder2/file2'", + "Resolving module name 'folder2/file2' relative to base url 'c:/root' - 'c:/root/folder2/file2'.", + "File 'c:/root/folder2/file2.ts' exist - use it as a module resolution result.", + "======== Module name 'folder2/file2' was successfully resolved to 'c:/root/folder2/file2.ts'. ========", + "======== Resolving module './file3' from 'c:/root/folder2/file2.ts'. ========", + "Explicitly specified module resolution kind: 'Classic'.", + "File 'c:/root/folder2/file3.ts' exist - use it as a module resolution result.", + "======== Module name './file3' was successfully resolved to 'c:/root/folder2/file3.ts'. ========", + "======== Resolving module 'file4' from 'c:/root/folder2/file2.ts'. ========", + "Explicitly specified module resolution kind: 'Classic'.", + "'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'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution3_classic.types b/tests/baselines/reference/pathMappingBasedModuleResolution3_classic.types new file mode 100644 index 00000000000..359811ff3b2 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution3_classic.types @@ -0,0 +1,44 @@ +=== c:/root/folder1/file1.ts === + +// baseUrl set via command line + +import {x} from "folder2/file2" +>x : number + +declare function use(a: any): void; +>use : (a: any) => void +>a : any + +use(x.toExponential()); +>use(x.toExponential()) : void +>use : (a: any) => void +>x.toExponential() : string +>x.toExponential : (fractionDigits?: number) => string +>x : number +>toExponential : (fractionDigits?: number) => string + +=== c:/root/folder2/file2.ts === +import {x as a} from "./file3" // found with baseurl +>x : number +>a : number + +import {y as b} from "file4" // found with fallback +>y : number +>b : number + +export var x = a + b; +>x : number +>a + b : number +>a : number +>b : number + +=== c:/root/folder2/file3.ts === +export var x = 1; +>x : number +>1 : number + +=== c:/file4.ts === +export var y = 100; +>y : number +>100 : number + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution3_node.js b/tests/baselines/reference/pathMappingBasedModuleResolution3_node.js new file mode 100644 index 00000000000..cbff6087530 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution3_node.js @@ -0,0 +1,34 @@ +//// [tests/cases/compiler/pathMappingBasedModuleResolution3_node.ts] //// + +//// [file1.ts] + +// baseUrl set via command line + +import {x} from "folder2/file2" +declare function use(a: any): void; +use(x.toExponential()); + +//// [file2.ts] +import {x as a} from "./file3" // found with baseurl +import {y as b} from "file4" // found with fallback +export var x = a + b; + +//// [file3.ts] +export var x = 1; + +//// [index.d.ts] +export var y: number; + +//// [file3.js] +"use strict"; +exports.x = 1; +//// [file2.js] +"use strict"; +var file3_1 = require("./file3"); // found with baseurl +var file4_1 = require("file4"); // found with fallback +exports.x = file3_1.x + file4_1.y; +//// [file1.js] +// baseUrl set via command line +"use strict"; +var file2_1 = require("folder2/file2"); +use(file2_1.x.toExponential()); diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution3_node.symbols b/tests/baselines/reference/pathMappingBasedModuleResolution3_node.symbols new file mode 100644 index 00000000000..487dea2fb89 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution3_node.symbols @@ -0,0 +1,39 @@ +=== c:/root/folder1/file1.ts === + +// baseUrl set via command line + +import {x} from "folder2/file2" +>x : Symbol(x, Decl(file1.ts, 3, 8)) + +declare function use(a: any): void; +>use : Symbol(use, Decl(file1.ts, 3, 31)) +>a : Symbol(a, Decl(file1.ts, 4, 21)) + +use(x.toExponential()); +>use : Symbol(use, Decl(file1.ts, 3, 31)) +>x.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(file1.ts, 3, 8)) +>toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) + +=== c:/root/folder2/file2.ts === +import {x as a} from "./file3" // found with baseurl +>x : Symbol(a, Decl(file2.ts, 0, 8)) +>a : Symbol(a, Decl(file2.ts, 0, 8)) + +import {y as b} from "file4" // found with fallback +>y : Symbol(b, Decl(file2.ts, 1, 8)) +>b : Symbol(b, Decl(file2.ts, 1, 8)) + +export var x = a + b; +>x : Symbol(x, Decl(file2.ts, 2, 10)) +>a : Symbol(a, Decl(file2.ts, 0, 8)) +>b : Symbol(b, Decl(file2.ts, 1, 8)) + +=== c:/root/folder2/file3.ts === +export var x = 1; +>x : Symbol(x, Decl(file3.ts, 0, 10)) + +=== c:/node_modules/file4/index.d.ts === +export var y: number; +>y : Symbol(y, Decl(index.d.ts, 0, 10)) + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution3_node.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution3_node.trace.json new file mode 100644 index 00000000000..6d0de807bc0 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution3_node.trace.json @@ -0,0 +1,49 @@ +[ + "======== Resolving module 'folder2/file2' from 'c:/root/folder1/file1.ts'. ========", + "Explicitly specified module resolution kind: 'NodeJs'.", + "'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name 'folder2/file2'", + "Resolving module name 'folder2/file2' relative to base url 'c:/root' - 'c:/root/folder2/file2'.", + "Loading module as file / folder, candidate module location 'c:/root/folder2/file2'.", + "File 'c:/root/folder2/file2.ts' exist - use it as a module resolution result.", + "======== Module name 'folder2/file2' was successfully resolved to 'c:/root/folder2/file2.ts'. ========", + "======== Resolving module './file3' from 'c:/root/folder2/file2.ts'. ========", + "Explicitly specified module resolution kind: 'NodeJs'.", + "Loading module as file / folder, candidate module location 'c:/root/folder2/file3'.", + "File 'c:/root/folder2/file3.ts' exist - use it as a module resolution result.", + "======== Module name './file3' was successfully resolved to 'c:/root/folder2/file3.ts'. ========", + "======== Resolving module 'file4' from 'c:/root/folder2/file2.ts'. ========", + "Explicitly specified module resolution kind: 'NodeJs'.", + "'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'.", + "Loading module as file / folder, candidate module location '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/file4/package.json' does not exist.", + "File 'c:/root/file4/index.ts' does not exist.", + "File 'c:/root/file4/index.tsx' does not exist.", + "File 'c:/root/file4/index.d.ts' does not exist.", + "Loading module 'file4' from 'node_modules' folder.", + "File 'c:/root/folder2/node_modules/file4.ts' does not exist.", + "File 'c:/root/folder2/node_modules/file4.tsx' does not exist.", + "File 'c:/root/folder2/node_modules/file4.d.ts' does not exist.", + "File 'c:/root/folder2/node_modules/file4/package.json' does not exist.", + "File 'c:/root/folder2/node_modules/file4/index.ts' does not exist.", + "File 'c:/root/folder2/node_modules/file4/index.tsx' does not exist.", + "File 'c:/root/folder2/node_modules/file4/index.d.ts' does not exist.", + "File 'c:/root/node_modules/file4.ts' does not exist.", + "File 'c:/root/node_modules/file4.tsx' does not exist.", + "File 'c:/root/node_modules/file4.d.ts' does not exist.", + "File 'c:/root/node_modules/file4/package.json' does not exist.", + "File 'c:/root/node_modules/file4/index.ts' does not exist.", + "File 'c:/root/node_modules/file4/index.tsx' does not exist.", + "File 'c:/root/node_modules/file4/index.d.ts' does not exist.", + "File 'c:/node_modules/file4.ts' does not exist.", + "File 'c:/node_modules/file4.tsx' does not exist.", + "File 'c:/node_modules/file4.d.ts' does not exist.", + "File 'c:/node_modules/file4/package.json' does not exist.", + "File 'c:/node_modules/file4/index.ts' does not exist.", + "File 'c:/node_modules/file4/index.tsx' does not exist.", + "File 'c:/node_modules/file4/index.d.ts' exist - use it as a module resolution result.", + "======== Module name 'file4' was successfully resolved to 'c:/node_modules/file4/index.d.ts'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution3_node.types b/tests/baselines/reference/pathMappingBasedModuleResolution3_node.types new file mode 100644 index 00000000000..78597cf50ef --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution3_node.types @@ -0,0 +1,43 @@ +=== c:/root/folder1/file1.ts === + +// baseUrl set via command line + +import {x} from "folder2/file2" +>x : number + +declare function use(a: any): void; +>use : (a: any) => void +>a : any + +use(x.toExponential()); +>use(x.toExponential()) : void +>use : (a: any) => void +>x.toExponential() : string +>x.toExponential : (fractionDigits?: number) => string +>x : number +>toExponential : (fractionDigits?: number) => string + +=== c:/root/folder2/file2.ts === +import {x as a} from "./file3" // found with baseurl +>x : number +>a : number + +import {y as b} from "file4" // found with fallback +>y : number +>b : number + +export var x = a + b; +>x : number +>a + b : number +>a : number +>b : number + +=== c:/root/folder2/file3.ts === +export var x = 1; +>x : number +>1 : number + +=== c:/node_modules/file4/index.d.ts === +export var y: number; +>y : number + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution4.js b/tests/baselines/reference/pathMappingBasedModuleResolution4.js deleted file mode 100644 index 4e76e43bb7d..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution4.js +++ /dev/null @@ -1,30 +0,0 @@ -//// [tests/cases/compiler/pathMappingBasedModuleResolution4.ts] //// - -//// [file1.ts] -import {x} from "folder2/file2" - -declare function use(a: any): void; - -use(x.toExponential()); - -//// [file2.ts] -export {x} from "./file3" - -//// [file3.ts] -export var x = 1; - -//// [file3.js] -define(["require", "exports"], function (require, exports) { - "use strict"; - exports.x = 1; -}); -//// [file2.js] -define(["require", "exports", "./file3"], function (require, exports, file3_1) { - "use strict"; - exports.x = file3_1.x; -}); -//// [file1.js] -define(["require", "exports", "folder2/file2"], function (require, exports, file2_1) { - "use strict"; - use(file2_1.x.toExponential()); -}); diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution4.symbols b/tests/baselines/reference/pathMappingBasedModuleResolution4.symbols deleted file mode 100644 index b071ecec087..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution4.symbols +++ /dev/null @@ -1,22 +0,0 @@ -=== tests/cases/compiler/root/src/folder1/file1.ts === -import {x} from "folder2/file2" ->x : Symbol(x, Decl(file1.ts, 0, 8)) - -declare function use(a: any): void; ->use : Symbol(use, Decl(file1.ts, 0, 31)) ->a : Symbol(a, Decl(file1.ts, 2, 21)) - -use(x.toExponential()); ->use : Symbol(use, Decl(file1.ts, 0, 31)) ->x.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) ->x : Symbol(x, Decl(file1.ts, 0, 8)) ->toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) - -=== tests/cases/compiler/root/src/folder2/file2.ts === -export {x} from "./file3" ->x : Symbol(x, Decl(file2.ts, 0, 8)) - -=== tests/cases/compiler/root/src/folder2/file3.ts === -export var x = 1; ->x : Symbol(x, Decl(file3.ts, 0, 10)) - diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution4.types b/tests/baselines/reference/pathMappingBasedModuleResolution4.types deleted file mode 100644 index 15428de5560..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution4.types +++ /dev/null @@ -1,25 +0,0 @@ -=== tests/cases/compiler/root/src/folder1/file1.ts === -import {x} from "folder2/file2" ->x : number - -declare function use(a: any): void; ->use : (a: any) => void ->a : any - -use(x.toExponential()); ->use(x.toExponential()) : void ->use : (a: any) => void ->x.toExponential() : string ->x.toExponential : (fractionDigits?: number) => string ->x : number ->toExponential : (fractionDigits?: number) => string - -=== tests/cases/compiler/root/src/folder2/file2.ts === -export {x} from "./file3" ->x : number - -=== tests/cases/compiler/root/src/folder2/file3.ts === -export var x = 1; ->x : number ->1 : number - diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution4_1.js b/tests/baselines/reference/pathMappingBasedModuleResolution4_1.js deleted file mode 100644 index 56b271ec8d9..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution4_1.js +++ /dev/null @@ -1,30 +0,0 @@ -//// [tests/cases/compiler/pathMappingBasedModuleResolution4_1.ts] //// - -//// [file1.ts] -import {x} from "folder2/file2" - -declare function use(a: any): void; - -use(x.toExponential()); - -//// [file2.ts] -export {x} from "./file3" - -//// [file3.ts] -export var x = 1; - -//// [file3.js] -define(["require", "exports"], function (require, exports) { - "use strict"; - exports.x = 1; -}); -//// [file2.js] -define(["require", "exports", "./file3"], function (require, exports, file3_1) { - "use strict"; - exports.x = file3_1.x; -}); -//// [file1.js] -define(["require", "exports", "folder2/file2"], function (require, exports, file2_1) { - "use strict"; - use(file2_1.x.toExponential()); -}); diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution4_1.symbols b/tests/baselines/reference/pathMappingBasedModuleResolution4_1.symbols deleted file mode 100644 index 835d16d46f4..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution4_1.symbols +++ /dev/null @@ -1,22 +0,0 @@ -=== c:/root/src/folder1/file1.ts === -import {x} from "folder2/file2" ->x : Symbol(x, Decl(file1.ts, 0, 8)) - -declare function use(a: any): void; ->use : Symbol(use, Decl(file1.ts, 0, 31)) ->a : Symbol(a, Decl(file1.ts, 2, 21)) - -use(x.toExponential()); ->use : Symbol(use, Decl(file1.ts, 0, 31)) ->x.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) ->x : Symbol(x, Decl(file1.ts, 0, 8)) ->toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) - -=== c:/root/src/folder2/file2.ts === -export {x} from "./file3" ->x : Symbol(x, Decl(file2.ts, 0, 8)) - -=== c:/root/src/folder2/file3.ts === -export var x = 1; ->x : Symbol(x, Decl(file3.ts, 0, 10)) - diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution4_1.types b/tests/baselines/reference/pathMappingBasedModuleResolution4_1.types deleted file mode 100644 index 8db89ab12b7..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution4_1.types +++ /dev/null @@ -1,25 +0,0 @@ -=== c:/root/src/folder1/file1.ts === -import {x} from "folder2/file2" ->x : number - -declare function use(a: any): void; ->use : (a: any) => void ->a : any - -use(x.toExponential()); ->use(x.toExponential()) : void ->use : (a: any) => void ->x.toExponential() : string ->x.toExponential : (fractionDigits?: number) => string ->x : number ->toExponential : (fractionDigits?: number) => string - -=== c:/root/src/folder2/file2.ts === -export {x} from "./file3" ->x : number - -=== c:/root/src/folder2/file3.ts === -export var x = 1; ->x : number ->1 : number - diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution4_classic.js b/tests/baselines/reference/pathMappingBasedModuleResolution4_classic.js new file mode 100644 index 00000000000..c1de8cea6c9 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution4_classic.js @@ -0,0 +1,38 @@ +//// [tests/cases/compiler/pathMappingBasedModuleResolution4_classic.ts] //// + +//// [file1.ts] +import {x} from "folder2/file2" +declare function use(a: any): void; +use(x.toExponential()); + +//// [file2.ts] +import {x as a} from "./file3" // found with baseurl +import {y as b} from "file4" // found with fallback +export var x = a + b; + +//// [file3.ts] +export var x = 1; + +//// [file4.ts] +export var y = 100; + +//// [file3.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + exports.x = 1; +}); +//// [file4.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + exports.y = 100; +}); +//// [file2.js] +define(["require", "exports", "./file3", "file4"], function (require, exports, file3_1, file4_1) { + "use strict"; + exports.x = file3_1.x + file4_1.y; +}); +//// [file1.js] +define(["require", "exports", "folder2/file2"], function (require, exports, file2_1) { + "use strict"; + use(file2_1.x.toExponential()); +}); diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution2_1.symbols b/tests/baselines/reference/pathMappingBasedModuleResolution4_classic.symbols similarity index 50% rename from tests/baselines/reference/pathMappingBasedModuleResolution2_1.symbols rename to tests/baselines/reference/pathMappingBasedModuleResolution4_classic.symbols index aa84fbf8cf9..7c1943dae46 100644 --- a/tests/baselines/reference/pathMappingBasedModuleResolution2_1.symbols +++ b/tests/baselines/reference/pathMappingBasedModuleResolution4_classic.symbols @@ -4,7 +4,7 @@ import {x} from "folder2/file2" declare function use(a: any): void; >use : Symbol(use, Decl(file1.ts, 0, 31)) ->a : Symbol(a, Decl(file1.ts, 2, 21)) +>a : Symbol(a, Decl(file1.ts, 1, 21)) use(x.toExponential()); >use : Symbol(use, Decl(file1.ts, 0, 31)) @@ -13,10 +13,24 @@ use(x.toExponential()); >toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) === c:/root/folder2/file2.ts === -export {x} from "./file3" ->x : Symbol(x, Decl(file2.ts, 0, 8)) +import {x as a} from "./file3" // found with baseurl +>x : Symbol(a, Decl(file2.ts, 0, 8)) +>a : Symbol(a, Decl(file2.ts, 0, 8)) + +import {y as b} from "file4" // found with fallback +>y : Symbol(b, Decl(file2.ts, 1, 8)) +>b : Symbol(b, Decl(file2.ts, 1, 8)) + +export var x = a + b; +>x : Symbol(x, Decl(file2.ts, 2, 10)) +>a : Symbol(a, Decl(file2.ts, 0, 8)) +>b : Symbol(b, Decl(file2.ts, 1, 8)) === c:/root/folder2/file3.ts === export var x = 1; >x : Symbol(x, Decl(file3.ts, 0, 10)) +=== c:/file4.ts === +export var y = 100; +>y : Symbol(y, Decl(file4.ts, 0, 10)) + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution4_classic.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution4_classic.trace.json new file mode 100644 index 00000000000..ac82f87bcee --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution4_classic.trace.json @@ -0,0 +1,27 @@ +[ + "======== Resolving module 'folder2/file2' from 'c:/root/folder1/file1.ts'. ========", + "Explicitly specified module resolution kind: 'Classic'.", + "'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name 'folder2/file2'", + "Resolving module name 'folder2/file2' relative to base url 'c:/root' - 'c:/root/folder2/file2'.", + "File 'c:/root/folder2/file2.ts' exist - use it as a module resolution result.", + "======== Module name 'folder2/file2' was successfully resolved to 'c:/root/folder2/file2.ts'. ========", + "======== Resolving module './file3' from 'c:/root/folder2/file2.ts'. ========", + "Explicitly specified module resolution kind: 'Classic'.", + "File 'c:/root/folder2/file3.ts' exist - use it as a module resolution result.", + "======== Module name './file3' was successfully resolved to 'c:/root/folder2/file3.ts'. ========", + "======== Resolving module 'file4' from 'c:/root/folder2/file2.ts'. ========", + "Explicitly specified module resolution kind: 'Classic'.", + "'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'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution1_1.types b/tests/baselines/reference/pathMappingBasedModuleResolution4_classic.types similarity index 60% rename from tests/baselines/reference/pathMappingBasedModuleResolution1_1.types rename to tests/baselines/reference/pathMappingBasedModuleResolution4_classic.types index 5b0727157ac..d225246e2f9 100644 --- a/tests/baselines/reference/pathMappingBasedModuleResolution1_1.types +++ b/tests/baselines/reference/pathMappingBasedModuleResolution4_classic.types @@ -1,7 +1,4 @@ === c:/root/folder1/file1.ts === - -// user defined base url - import {x} from "folder2/file2" >x : number @@ -18,11 +15,27 @@ use(x.toExponential()); >toExponential : (fractionDigits?: number) => string === c:/root/folder2/file2.ts === -export {x} from "./file3" +import {x as a} from "./file3" // found with baseurl >x : number +>a : number + +import {y as b} from "file4" // found with fallback +>y : number +>b : number + +export var x = a + b; +>x : number +>a + b : number +>a : number +>b : number === c:/root/folder2/file3.ts === export var x = 1; >x : number >1 : number +=== c:/file4.ts === +export var y = 100; +>y : number +>100 : number + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution4_node.js b/tests/baselines/reference/pathMappingBasedModuleResolution4_node.js new file mode 100644 index 00000000000..c5a08d55d8b --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution4_node.js @@ -0,0 +1,30 @@ +//// [tests/cases/compiler/pathMappingBasedModuleResolution4_node.ts] //// + +//// [file1.ts] +import {x} from "folder2/file2" +declare function use(a: any): void; +use(x.toExponential()); + +//// [file2.ts] +import {x as a} from "./file3" // found with baseurl +import {y as b} from "file4" // found with fallback +export var x = a + b; + +//// [file3.ts] +export var x = 1; + +//// [index.d.ts] +export var y: number; + +//// [file3.js] +"use strict"; +exports.x = 1; +//// [file2.js] +"use strict"; +var file3_1 = require("./file3"); // found with baseurl +var file4_1 = require("file4"); // found with fallback +exports.x = file3_1.x + file4_1.y; +//// [file1.js] +"use strict"; +var file2_1 = require("folder2/file2"); +use(file2_1.x.toExponential()); diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution4_node.symbols b/tests/baselines/reference/pathMappingBasedModuleResolution4_node.symbols new file mode 100644 index 00000000000..fb1c5be9de6 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution4_node.symbols @@ -0,0 +1,36 @@ +=== c:/root/folder1/file1.ts === +import {x} from "folder2/file2" +>x : Symbol(x, Decl(file1.ts, 0, 8)) + +declare function use(a: any): void; +>use : Symbol(use, Decl(file1.ts, 0, 31)) +>a : Symbol(a, Decl(file1.ts, 1, 21)) + +use(x.toExponential()); +>use : Symbol(use, Decl(file1.ts, 0, 31)) +>x.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(file1.ts, 0, 8)) +>toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) + +=== c:/root/folder2/file2.ts === +import {x as a} from "./file3" // found with baseurl +>x : Symbol(a, Decl(file2.ts, 0, 8)) +>a : Symbol(a, Decl(file2.ts, 0, 8)) + +import {y as b} from "file4" // found with fallback +>y : Symbol(b, Decl(file2.ts, 1, 8)) +>b : Symbol(b, Decl(file2.ts, 1, 8)) + +export var x = a + b; +>x : Symbol(x, Decl(file2.ts, 2, 10)) +>a : Symbol(a, Decl(file2.ts, 0, 8)) +>b : Symbol(b, Decl(file2.ts, 1, 8)) + +=== c:/root/folder2/file3.ts === +export var x = 1; +>x : Symbol(x, Decl(file3.ts, 0, 10)) + +=== c:/node_modules/file4/index.d.ts === +export var y: number; +>y : Symbol(y, Decl(index.d.ts, 0, 10)) + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution4_node.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution4_node.trace.json new file mode 100644 index 00000000000..6d0de807bc0 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution4_node.trace.json @@ -0,0 +1,49 @@ +[ + "======== Resolving module 'folder2/file2' from 'c:/root/folder1/file1.ts'. ========", + "Explicitly specified module resolution kind: 'NodeJs'.", + "'baseUrl' option is set to 'c:/root', using this value to resolve non-relative module name 'folder2/file2'", + "Resolving module name 'folder2/file2' relative to base url 'c:/root' - 'c:/root/folder2/file2'.", + "Loading module as file / folder, candidate module location 'c:/root/folder2/file2'.", + "File 'c:/root/folder2/file2.ts' exist - use it as a module resolution result.", + "======== Module name 'folder2/file2' was successfully resolved to 'c:/root/folder2/file2.ts'. ========", + "======== Resolving module './file3' from 'c:/root/folder2/file2.ts'. ========", + "Explicitly specified module resolution kind: 'NodeJs'.", + "Loading module as file / folder, candidate module location 'c:/root/folder2/file3'.", + "File 'c:/root/folder2/file3.ts' exist - use it as a module resolution result.", + "======== Module name './file3' was successfully resolved to 'c:/root/folder2/file3.ts'. ========", + "======== Resolving module 'file4' from 'c:/root/folder2/file2.ts'. ========", + "Explicitly specified module resolution kind: 'NodeJs'.", + "'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'.", + "Loading module as file / folder, candidate module location '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/file4/package.json' does not exist.", + "File 'c:/root/file4/index.ts' does not exist.", + "File 'c:/root/file4/index.tsx' does not exist.", + "File 'c:/root/file4/index.d.ts' does not exist.", + "Loading module 'file4' from 'node_modules' folder.", + "File 'c:/root/folder2/node_modules/file4.ts' does not exist.", + "File 'c:/root/folder2/node_modules/file4.tsx' does not exist.", + "File 'c:/root/folder2/node_modules/file4.d.ts' does not exist.", + "File 'c:/root/folder2/node_modules/file4/package.json' does not exist.", + "File 'c:/root/folder2/node_modules/file4/index.ts' does not exist.", + "File 'c:/root/folder2/node_modules/file4/index.tsx' does not exist.", + "File 'c:/root/folder2/node_modules/file4/index.d.ts' does not exist.", + "File 'c:/root/node_modules/file4.ts' does not exist.", + "File 'c:/root/node_modules/file4.tsx' does not exist.", + "File 'c:/root/node_modules/file4.d.ts' does not exist.", + "File 'c:/root/node_modules/file4/package.json' does not exist.", + "File 'c:/root/node_modules/file4/index.ts' does not exist.", + "File 'c:/root/node_modules/file4/index.tsx' does not exist.", + "File 'c:/root/node_modules/file4/index.d.ts' does not exist.", + "File 'c:/node_modules/file4.ts' does not exist.", + "File 'c:/node_modules/file4.tsx' does not exist.", + "File 'c:/node_modules/file4.d.ts' does not exist.", + "File 'c:/node_modules/file4/package.json' does not exist.", + "File 'c:/node_modules/file4/index.ts' does not exist.", + "File 'c:/node_modules/file4/index.tsx' does not exist.", + "File 'c:/node_modules/file4/index.d.ts' exist - use it as a module resolution result.", + "======== Module name 'file4' was successfully resolved to 'c:/node_modules/file4/index.d.ts'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution2_1.types b/tests/baselines/reference/pathMappingBasedModuleResolution4_node.types similarity index 59% rename from tests/baselines/reference/pathMappingBasedModuleResolution2_1.types rename to tests/baselines/reference/pathMappingBasedModuleResolution4_node.types index de76a17e406..5478a601f02 100644 --- a/tests/baselines/reference/pathMappingBasedModuleResolution2_1.types +++ b/tests/baselines/reference/pathMappingBasedModuleResolution4_node.types @@ -15,11 +15,26 @@ use(x.toExponential()); >toExponential : (fractionDigits?: number) => string === c:/root/folder2/file2.ts === -export {x} from "./file3" +import {x as a} from "./file3" // found with baseurl >x : number +>a : number + +import {y as b} from "file4" // found with fallback +>y : number +>b : number + +export var x = a + b; +>x : number +>a + b : number +>a : number +>b : number === c:/root/folder2/file3.ts === export var x = 1; >x : number >1 : number +=== c:/node_modules/file4/index.d.ts === +export var y: number; +>y : number + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution5.errors.txt b/tests/baselines/reference/pathMappingBasedModuleResolution5.errors.txt deleted file mode 100644 index bcf7ced9509..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution5.errors.txt +++ /dev/null @@ -1,6 +0,0 @@ -error TS5064: Module resolution kind cannot be determined automatically. Please specify module resolution explicitly via 'moduleResolution' option. - - -!!! error TS5064: Module resolution kind cannot be determined automatically. Please specify module resolution explicitly via 'moduleResolution' option. -==== tests/cases/compiler/root/src/folder1/file1.ts (0 errors) ==== - export var x = 1; \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution7_2.js b/tests/baselines/reference/pathMappingBasedModuleResolution5_classic.js similarity index 91% rename from tests/baselines/reference/pathMappingBasedModuleResolution7_2.js rename to tests/baselines/reference/pathMappingBasedModuleResolution5_classic.js index 7c66828054e..24297f85e35 100644 --- a/tests/baselines/reference/pathMappingBasedModuleResolution7_2.js +++ b/tests/baselines/reference/pathMappingBasedModuleResolution5_classic.js @@ -1,4 +1,4 @@ -//// [tests/cases/compiler/pathMappingBasedModuleResolution7_2.ts] //// +//// [tests/cases/compiler/pathMappingBasedModuleResolution5_classic.ts] //// //// [file1.ts] import {x} from "folder2/file1" diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution7_2.symbols b/tests/baselines/reference/pathMappingBasedModuleResolution5_classic.symbols similarity index 95% rename from tests/baselines/reference/pathMappingBasedModuleResolution7_2.symbols rename to tests/baselines/reference/pathMappingBasedModuleResolution5_classic.symbols index a974a238200..057b5a622a1 100644 --- a/tests/baselines/reference/pathMappingBasedModuleResolution7_2.symbols +++ b/tests/baselines/reference/pathMappingBasedModuleResolution5_classic.symbols @@ -51,7 +51,7 @@ export var y = 1; export var z = 1; >z : Symbol(z, Decl(file3.ts, 0, 10)) -=== c:/sharedrepo/file4.ts === +=== c:/file4.ts === export var z1 = 1; >z1 : Symbol(z1, Decl(file4.ts, 0, 10)) diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution5_classic.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution5_classic.trace.json new file mode 100644 index 00000000000..293291e4acf --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution5_classic.trace.json @@ -0,0 +1,51 @@ +[ + "======== 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'.", + "File 'c:/root/folder2/file1.ts' exist - use it as a module resolution result.", + "======== 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'.", + "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.", + "======== 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'.", + "File 'c:/root/shared/components/file3.ts' exist - use it as a module resolution result.", + "======== 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'.", + "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'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution7_2.types b/tests/baselines/reference/pathMappingBasedModuleResolution5_classic.types similarity index 93% rename from tests/baselines/reference/pathMappingBasedModuleResolution7_2.types rename to tests/baselines/reference/pathMappingBasedModuleResolution5_classic.types index 9a88412b623..32a1f42bc0f 100644 --- a/tests/baselines/reference/pathMappingBasedModuleResolution7_2.types +++ b/tests/baselines/reference/pathMappingBasedModuleResolution5_classic.types @@ -62,7 +62,7 @@ export var z = 1; >z : number >1 : number -=== c:/sharedrepo/file4.ts === +=== c:/file4.ts === export var z1 = 1; >z1 : number >1 : number diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution5_node.js b/tests/baselines/reference/pathMappingBasedModuleResolution5_node.js new file mode 100644 index 00000000000..1958800f918 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution5_node.js @@ -0,0 +1,46 @@ +//// [tests/cases/compiler/pathMappingBasedModuleResolution5_node.ts] //// + +//// [file1.ts] +import {x} from "folder2/file1" +import {y} from "folder3/file2" +import {z} from "components/file3" +import {z1} from "file4" + +declare function use(a: any): void; + +use(x.toExponential()); +use(y.toExponential()); +use(z.toExponential()); +use(z1.toExponential()); + +//// [file1.ts] +export var x = 1; + +//// [file2.ts] +export var y = 1; + +//// [index.d.ts] +export var z: number; + +//// [file4.ts] +export var z1 = 1; + +//// [file1.js] +"use strict"; +exports.x = 1; +//// [file2.js] +"use strict"; +exports.y = 1; +//// [file4.js] +"use strict"; +exports.z1 = 1; +//// [file1.js] +"use strict"; +var file1_1 = require("folder2/file1"); +var file2_1 = require("folder3/file2"); +var file3_1 = require("components/file3"); +var file4_1 = require("file4"); +use(file1_1.x.toExponential()); +use(file2_1.y.toExponential()); +use(file3_1.z.toExponential()); +use(file4_1.z1.toExponential()); diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution8_1.symbols b/tests/baselines/reference/pathMappingBasedModuleResolution5_node.symbols similarity index 85% rename from tests/baselines/reference/pathMappingBasedModuleResolution8_1.symbols rename to tests/baselines/reference/pathMappingBasedModuleResolution5_node.symbols index 553112dde95..67bf14607dd 100644 --- a/tests/baselines/reference/pathMappingBasedModuleResolution8_1.symbols +++ b/tests/baselines/reference/pathMappingBasedModuleResolution5_node.symbols @@ -39,19 +39,19 @@ use(z1.toExponential()); >z1 : Symbol(z1, Decl(file1.ts, 3, 8)) >toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) -=== c:/root/src/folder2/file1.ts === +=== c:/root/folder2/file1.ts === export var x = 1; >x : Symbol(x, Decl(file1.ts, 0, 10)) -=== c:/root/src/generated/folder3/file2.ts === +=== c:/root/generated/folder3/file2.ts === export var y = 1; >y : Symbol(y, Decl(file2.ts, 0, 10)) -=== c:/root/src/shared/components/file3.ts === -export var z = 1; ->z : Symbol(z, Decl(file3.ts, 0, 10)) +=== c:/root/shared/components/file3/index.d.ts === +export var z: number; +>z : Symbol(z, Decl(index.d.ts, 0, 10)) -=== c:/sharedrepo/file4.ts === +=== c:/node_modules/file4.ts === export var z1 = 1; >z1 : Symbol(z1, Decl(file4.ts, 0, 10)) diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution5_node.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution5_node.trace.json new file mode 100644 index 00000000000..398d15839de --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution5_node.trace.json @@ -0,0 +1,84 @@ +[ + "======== 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'.", + "Loading module as file / folder, candidate module location 'c:/root/folder2/file1'.", + "File 'c:/root/folder2/file1.ts' exist - use it as a module resolution result.", + "======== 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'.", + "Loading module as file / folder, candidate module location 'c:/root/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.", + "File 'c:/root/folder3/file2/package.json' does not exist.", + "File 'c:/root/folder3/file2/index.ts' does not exist.", + "File 'c:/root/folder3/file2/index.tsx' does not exist.", + "File 'c:/root/folder3/file2/index.d.ts' does not exist.", + "Trying substitution 'generated/*', candidate module location: 'generated/folder3/file2'.", + "Loading module as file / folder, candidate module location 'c:/root/generated/folder3/file2'.", + "File 'c:/root/generated/folder3/file2.ts' exist - use it as a module resolution result.", + "======== 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'.", + "Loading module as file / folder, candidate module location 'c:/root/shared/components/file3'.", + "File 'c:/root/shared/components/file3.ts' does not exist.", + "File 'c:/root/shared/components/file3.tsx' does not exist.", + "File 'c:/root/shared/components/file3.d.ts' does not exist.", + "File 'c:/root/shared/components/file3/package.json' does not exist.", + "File 'c:/root/shared/components/file3/index.ts' does not exist.", + "File 'c:/root/shared/components/file3/index.tsx' does not exist.", + "File 'c:/root/shared/components/file3/index.d.ts' exist - use it as a module resolution result.", + "======== 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'.", + "Loading module as file / folder, candidate module location '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/file4/package.json' does not exist.", + "File 'c:/root/file4/index.ts' does not exist.", + "File 'c:/root/file4/index.tsx' does not exist.", + "File 'c:/root/file4/index.d.ts' does not exist.", + "Trying substitution 'generated/*', candidate module location: 'generated/file4'.", + "Loading module as file / folder, candidate module location 'c:/root/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/generated/file4/package.json' does not exist.", + "File 'c:/root/generated/file4/index.ts' does not exist.", + "File 'c:/root/generated/file4/index.tsx' does not exist.", + "File 'c:/root/generated/file4/index.d.ts' does not exist.", + "Loading module 'file4' from 'node_modules' folder.", + "File 'c:/root/folder1/node_modules/file4.ts' does not exist.", + "File 'c:/root/folder1/node_modules/file4.tsx' does not exist.", + "File 'c:/root/folder1/node_modules/file4.d.ts' does not exist.", + "File 'c:/root/folder1/node_modules/file4/package.json' does not exist.", + "File 'c:/root/folder1/node_modules/file4/index.ts' does not exist.", + "File 'c:/root/folder1/node_modules/file4/index.tsx' does not exist.", + "File 'c:/root/folder1/node_modules/file4/index.d.ts' does not exist.", + "File 'c:/root/node_modules/file4.ts' does not exist.", + "File 'c:/root/node_modules/file4.tsx' does not exist.", + "File 'c:/root/node_modules/file4.d.ts' does not exist.", + "File 'c:/root/node_modules/file4/package.json' does not exist.", + "File 'c:/root/node_modules/file4/index.ts' does not exist.", + "File 'c:/root/node_modules/file4/index.tsx' does not exist.", + "File 'c:/root/node_modules/file4/index.d.ts' does not exist.", + "File 'c:/node_modules/file4.ts' exist - use it as a module resolution result.", + "======== Module name 'file4' was successfully resolved to 'c:/node_modules/file4.ts'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution8_1.types b/tests/baselines/reference/pathMappingBasedModuleResolution5_node.types similarity index 83% rename from tests/baselines/reference/pathMappingBasedModuleResolution8_1.types rename to tests/baselines/reference/pathMappingBasedModuleResolution5_node.types index 61da62d4ee6..1b96e3f4f22 100644 --- a/tests/baselines/reference/pathMappingBasedModuleResolution8_1.types +++ b/tests/baselines/reference/pathMappingBasedModuleResolution5_node.types @@ -47,22 +47,21 @@ use(z1.toExponential()); >z1 : number >toExponential : (fractionDigits?: number) => string -=== c:/root/src/folder2/file1.ts === +=== c:/root/folder2/file1.ts === export var x = 1; >x : number >1 : number -=== c:/root/src/generated/folder3/file2.ts === +=== c:/root/generated/folder3/file2.ts === export var y = 1; >y : number >1 : number -=== c:/root/src/shared/components/file3.ts === -export var z = 1; +=== c:/root/shared/components/file3/index.d.ts === +export var z: number; >z : number ->1 : number -=== c:/sharedrepo/file4.ts === +=== c:/node_modules/file4.ts === export var z1 = 1; >z1 : number >1 : number diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution6_classic.js b/tests/baselines/reference/pathMappingBasedModuleResolution6_classic.js new file mode 100644 index 00000000000..1e8f8807e2c --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution6_classic.js @@ -0,0 +1,23 @@ +//// [tests/cases/compiler/pathMappingBasedModuleResolution6_classic.ts] //// + +//// [file1.ts] +import {x} from "./project/file3"; +declare function use(x: string); +use(x.toExponential()); + +//// [file2.d.ts] +export let x: number; + +//// [file3.ts] +export {x} from "../file2"; + +//// [file3.js] +define(["require", "exports", "../file2"], function (require, exports, file2_1) { + "use strict"; + exports.x = file2_1.x; +}); +//// [file1.js] +define(["require", "exports", "./project/file3"], function (require, exports, file3_1) { + "use strict"; + use(file3_1.x.toExponential()); +}); diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution6_classic.symbols b/tests/baselines/reference/pathMappingBasedModuleResolution6_classic.symbols new file mode 100644 index 00000000000..a451ffb2584 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution6_classic.symbols @@ -0,0 +1,22 @@ +=== c:/root/src/file1.ts === +import {x} from "./project/file3"; +>x : Symbol(x, Decl(file1.ts, 0, 8)) + +declare function use(x: string); +>use : Symbol(use, Decl(file1.ts, 0, 34)) +>x : Symbol(x, Decl(file1.ts, 1, 21)) + +use(x.toExponential()); +>use : Symbol(use, Decl(file1.ts, 0, 34)) +>x.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(file1.ts, 0, 8)) +>toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) + +=== c:/root/src/file2.d.ts === +export let x: number; +>x : Symbol(x, Decl(file2.d.ts, 0, 10)) + +=== c:/root/generated/src/project/file3.ts === +export {x} from "../file2"; +>x : Symbol(x, Decl(file3.ts, 0, 8)) + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution6_classic.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution6_classic.trace.json new file mode 100644 index 00000000000..229ef51a924 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution6_classic.trace.json @@ -0,0 +1,32 @@ +[ + "======== Resolving module './project/file3' from 'c:/root/src/file1.ts'. ========", + "Module resolution kind is not specified, using 'Classic'.", + "'rootDirs' option is set, using it to resolve relative module name './project/file3'", + "Checking if 'c:/root/src/' is the longest matching prefix for 'c:/root/src/project/file3' - 'true'.", + "Checking if 'c:/root/generated/src/' is the longest matching prefix for 'c:/root/src/project/file3' - 'false'.", + "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'", + "File 'c:/root/generated/src/project/file3.ts' exist - use it as a module resolution result.", + "======== Module name './project/file3' was successfully resolved to 'c:/root/generated/src/project/file3.ts'. ========", + "======== Resolving module '../file2' from 'c:/root/generated/src/project/file3.ts'. ========", + "Module resolution kind is not specified, using 'Classic'.", + "'rootDirs' option is set, using it to resolve relative module name '../file2'", + "Checking if 'c:/root/src/' is the longest matching prefix for 'c:/root/generated/src/file2' - 'false'.", + "Checking if 'c:/root/generated/src/' is the longest matching prefix for 'c:/root/generated/src/file2' - 'true'.", + "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'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution6_classic.types b/tests/baselines/reference/pathMappingBasedModuleResolution6_classic.types new file mode 100644 index 00000000000..06d2cbdce34 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution6_classic.types @@ -0,0 +1,24 @@ +=== c:/root/src/file1.ts === +import {x} from "./project/file3"; +>x : number + +declare function use(x: string); +>use : (x: string) => any +>x : string + +use(x.toExponential()); +>use(x.toExponential()) : any +>use : (x: string) => any +>x.toExponential() : string +>x.toExponential : (fractionDigits?: number) => string +>x : number +>toExponential : (fractionDigits?: number) => string + +=== c:/root/src/file2.d.ts === +export let x: number; +>x : number + +=== c:/root/generated/src/project/file3.ts === +export {x} from "../file2"; +>x : number + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution6_node.js b/tests/baselines/reference/pathMappingBasedModuleResolution6_node.js new file mode 100644 index 00000000000..6db3fecf83f --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution6_node.js @@ -0,0 +1,21 @@ +//// [tests/cases/compiler/pathMappingBasedModuleResolution6_node.ts] //// + +//// [file1.ts] +import {x} from "./project/file3"; +declare function use(x: string); +use(x.toFixed()); + +//// [index.d.ts] +export let x: number; + +//// [file3.ts] +export {x} from "../file2"; + +//// [file3.js] +"use strict"; +var file2_1 = require("../file2"); +exports.x = file2_1.x; +//// [file1.js] +"use strict"; +var file3_1 = require("./project/file3"); +use(file3_1.x.toFixed()); diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution6_node.symbols b/tests/baselines/reference/pathMappingBasedModuleResolution6_node.symbols new file mode 100644 index 00000000000..06554bae039 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution6_node.symbols @@ -0,0 +1,22 @@ +=== c:/root/src/file1.ts === +import {x} from "./project/file3"; +>x : Symbol(x, Decl(file1.ts, 0, 8)) + +declare function use(x: string); +>use : Symbol(use, Decl(file1.ts, 0, 34)) +>x : Symbol(x, Decl(file1.ts, 1, 21)) + +use(x.toFixed()); +>use : Symbol(use, Decl(file1.ts, 0, 34)) +>x.toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(file1.ts, 0, 8)) +>toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --)) + +=== c:/root/src/file2/index.d.ts === +export let x: number; +>x : Symbol(x, Decl(index.d.ts, 0, 10)) + +=== c:/root/generated/src/project/file3.ts === +export {x} from "../file2"; +>x : Symbol(x, Decl(file3.ts, 0, 8)) + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution6_node.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution6_node.trace.json new file mode 100644 index 00000000000..4ea2f12a63c --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution6_node.trace.json @@ -0,0 +1,48 @@ +[ + "======== Resolving module './project/file3' from 'c:/root/src/file1.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "'rootDirs' option is set, using it to resolve relative module name './project/file3'", + "Checking if 'c:/root/src/' is the longest matching prefix for 'c:/root/src/project/file3' - 'true'.", + "Checking if 'c:/root/generated/src/' is the longest matching prefix for 'c:/root/src/project/file3' - 'false'.", + "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'", + "Loading module as file / folder, candidate module 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.", + "File 'c:/root/src/project/file3/package.json' does not exist.", + "File 'c:/root/src/project/file3/index.ts' does not exist.", + "File 'c:/root/src/project/file3/index.tsx' does not exist.", + "File 'c:/root/src/project/file3/index.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'", + "Loading module as file / folder, candidate module location 'c:/root/generated/src/project/file3'.", + "File 'c:/root/generated/src/project/file3.ts' exist - use it as a module resolution result.", + "======== Module name './project/file3' was successfully resolved to 'c:/root/generated/src/project/file3.ts'. ========", + "======== Resolving module '../file2' from 'c:/root/generated/src/project/file3.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "'rootDirs' option is set, using it to resolve relative module name '../file2'", + "Checking if 'c:/root/src/' is the longest matching prefix for 'c:/root/generated/src/file2' - 'false'.", + "Checking if 'c:/root/generated/src/' is the longest matching prefix for 'c:/root/generated/src/file2' - 'true'.", + "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'", + "Loading module as file / folder, candidate module 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.", + "File 'c:/root/generated/src/file2/package.json' does not exist.", + "File 'c:/root/generated/src/file2/index.ts' does not exist.", + "File 'c:/root/generated/src/file2/index.tsx' does not exist.", + "File 'c:/root/generated/src/file2/index.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'", + "Loading module as file / folder, candidate module 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' does not exist.", + "File 'c:/root/src/file2/package.json' does not exist.", + "File 'c:/root/src/file2/index.ts' does not exist.", + "File 'c:/root/src/file2/index.tsx' does not exist.", + "File 'c:/root/src/file2/index.d.ts' exist - use it as a module resolution result.", + "======== Module name '../file2' was successfully resolved to 'c:/root/src/file2/index.d.ts'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution6_node.types b/tests/baselines/reference/pathMappingBasedModuleResolution6_node.types new file mode 100644 index 00000000000..2fd10e8e133 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution6_node.types @@ -0,0 +1,24 @@ +=== c:/root/src/file1.ts === +import {x} from "./project/file3"; +>x : number + +declare function use(x: string); +>use : (x: string) => any +>x : string + +use(x.toFixed()); +>use(x.toFixed()) : any +>use : (x: string) => any +>x.toFixed() : string +>x.toFixed : (fractionDigits?: number) => string +>x : number +>toFixed : (fractionDigits?: number) => string + +=== c:/root/src/file2/index.d.ts === +export let x: number; +>x : number + +=== c:/root/generated/src/project/file3.ts === +export {x} from "../file2"; +>x : number + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution7.js b/tests/baselines/reference/pathMappingBasedModuleResolution7.js deleted file mode 100644 index ef79caaabc0..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution7.js +++ /dev/null @@ -1,44 +0,0 @@ -//// [tests/cases/compiler/pathMappingBasedModuleResolution7.ts] //// - -//// [file1.ts] -import {x} from "folder2/file1" -import {y} from "folder3/file2" -import {z} from "components/file3" - -declare function use(a: any): void; - -use(x.toExponential()); -use(y.toExponential()); -use(z.toExponential()); - -//// [file1.ts] -export var x = 1; - -//// [file2.ts] -export var y = 1; - -//// [file3.ts] -export var z = 1; - -//// [file1.js] -define(["require", "exports"], function (require, exports) { - "use strict"; - exports.x = 1; -}); -//// [file2.js] -define(["require", "exports"], function (require, exports) { - "use strict"; - exports.y = 1; -}); -//// [file3.js] -define(["require", "exports"], function (require, exports) { - "use strict"; - exports.z = 1; -}); -//// [file1.js] -define(["require", "exports", "folder2/file1", "folder3/file2", "components/file3"], function (require, exports, file1_1, file2_1, file3_1) { - "use strict"; - use(file1_1.x.toExponential()); - use(file2_1.y.toExponential()); - use(file3_1.z.toExponential()); -}); diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution7.symbols b/tests/baselines/reference/pathMappingBasedModuleResolution7.symbols deleted file mode 100644 index 4b7b9c15739..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution7.symbols +++ /dev/null @@ -1,44 +0,0 @@ -=== tests/cases/compiler/root/folder1/file1.ts === -import {x} from "folder2/file1" ->x : Symbol(x, Decl(file1.ts, 0, 8)) - -import {y} from "folder3/file2" ->y : Symbol(y, Decl(file1.ts, 1, 8)) - -import {z} from "components/file3" ->z : Symbol(z, Decl(file1.ts, 2, 8)) - -declare function use(a: any): void; ->use : Symbol(use, Decl(file1.ts, 2, 34)) ->a : Symbol(a, Decl(file1.ts, 4, 21)) - -use(x.toExponential()); ->use : Symbol(use, Decl(file1.ts, 2, 34)) ->x.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) ->x : Symbol(x, Decl(file1.ts, 0, 8)) ->toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) - -use(y.toExponential()); ->use : Symbol(use, Decl(file1.ts, 2, 34)) ->y.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) ->y : Symbol(y, Decl(file1.ts, 1, 8)) ->toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) - -use(z.toExponential()); ->use : Symbol(use, Decl(file1.ts, 2, 34)) ->z.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) ->z : Symbol(z, Decl(file1.ts, 2, 8)) ->toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) - -=== tests/cases/compiler/root/folder2/file1.ts === -export var x = 1; ->x : Symbol(x, Decl(file1.ts, 0, 10)) - -=== tests/cases/compiler/root/generated/folder3/file2.ts === -export var y = 1; ->y : Symbol(y, Decl(file2.ts, 0, 10)) - -=== tests/cases/compiler/root/shared/components/file3.ts === -export var z = 1; ->z : Symbol(z, Decl(file3.ts, 0, 10)) - diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution7.types b/tests/baselines/reference/pathMappingBasedModuleResolution7.types deleted file mode 100644 index 1bc1622b19f..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution7.types +++ /dev/null @@ -1,53 +0,0 @@ -=== tests/cases/compiler/root/folder1/file1.ts === -import {x} from "folder2/file1" ->x : number - -import {y} from "folder3/file2" ->y : number - -import {z} from "components/file3" ->z : number - -declare function use(a: any): void; ->use : (a: any) => void ->a : any - -use(x.toExponential()); ->use(x.toExponential()) : void ->use : (a: any) => void ->x.toExponential() : string ->x.toExponential : (fractionDigits?: number) => string ->x : number ->toExponential : (fractionDigits?: number) => string - -use(y.toExponential()); ->use(y.toExponential()) : void ->use : (a: any) => void ->y.toExponential() : string ->y.toExponential : (fractionDigits?: number) => string ->y : number ->toExponential : (fractionDigits?: number) => string - -use(z.toExponential()); ->use(z.toExponential()) : void ->use : (a: any) => void ->z.toExponential() : string ->z.toExponential : (fractionDigits?: number) => string ->z : number ->toExponential : (fractionDigits?: number) => string - -=== tests/cases/compiler/root/folder2/file1.ts === -export var x = 1; ->x : number ->1 : number - -=== tests/cases/compiler/root/generated/folder3/file2.ts === -export var y = 1; ->y : number ->1 : number - -=== tests/cases/compiler/root/shared/components/file3.ts === -export var z = 1; ->z : number ->1 : number - diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution7_1.js b/tests/baselines/reference/pathMappingBasedModuleResolution7_1.js deleted file mode 100644 index ad2b8ef2a90..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution7_1.js +++ /dev/null @@ -1,44 +0,0 @@ -//// [tests/cases/compiler/pathMappingBasedModuleResolution7_1.ts] //// - -//// [file1.ts] -import {x} from "folder2/file1" -import {y} from "folder3/file2" -import {z} from "components/file3" - -declare function use(a: any): void; - -use(x.toExponential()); -use(y.toExponential()); -use(z.toExponential()); - -//// [file1.ts] -export var x = 1; - -//// [file2.ts] -export var y = 1; - -//// [file3.ts] -export var z = 1; - -//// [file1.js] -define(["require", "exports"], function (require, exports) { - "use strict"; - exports.x = 1; -}); -//// [file2.js] -define(["require", "exports"], function (require, exports) { - "use strict"; - exports.y = 1; -}); -//// [file3.js] -define(["require", "exports"], function (require, exports) { - "use strict"; - exports.z = 1; -}); -//// [file1.js] -define(["require", "exports", "folder2/file1", "folder3/file2", "components/file3"], function (require, exports, file1_1, file2_1, file3_1) { - "use strict"; - use(file1_1.x.toExponential()); - use(file2_1.y.toExponential()); - use(file3_1.z.toExponential()); -}); diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution7_1.symbols b/tests/baselines/reference/pathMappingBasedModuleResolution7_1.symbols deleted file mode 100644 index 097f0747b47..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution7_1.symbols +++ /dev/null @@ -1,44 +0,0 @@ -=== c:/root/folder1/file1.ts === -import {x} from "folder2/file1" ->x : Symbol(x, Decl(file1.ts, 0, 8)) - -import {y} from "folder3/file2" ->y : Symbol(y, Decl(file1.ts, 1, 8)) - -import {z} from "components/file3" ->z : Symbol(z, Decl(file1.ts, 2, 8)) - -declare function use(a: any): void; ->use : Symbol(use, Decl(file1.ts, 2, 34)) ->a : Symbol(a, Decl(file1.ts, 4, 21)) - -use(x.toExponential()); ->use : Symbol(use, Decl(file1.ts, 2, 34)) ->x.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) ->x : Symbol(x, Decl(file1.ts, 0, 8)) ->toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) - -use(y.toExponential()); ->use : Symbol(use, Decl(file1.ts, 2, 34)) ->y.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) ->y : Symbol(y, Decl(file1.ts, 1, 8)) ->toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) - -use(z.toExponential()); ->use : Symbol(use, Decl(file1.ts, 2, 34)) ->z.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) ->z : Symbol(z, Decl(file1.ts, 2, 8)) ->toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) - -=== c:/root/folder2/file1.ts === -export var x = 1; ->x : Symbol(x, Decl(file1.ts, 0, 10)) - -=== c:/root/generated/folder3/file2.ts === -export var y = 1; ->y : Symbol(y, Decl(file2.ts, 0, 10)) - -=== c:/root/shared/components/file3.ts === -export var z = 1; ->z : Symbol(z, Decl(file3.ts, 0, 10)) - diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution7_1.types b/tests/baselines/reference/pathMappingBasedModuleResolution7_1.types deleted file mode 100644 index 9cc451eaa3b..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution7_1.types +++ /dev/null @@ -1,53 +0,0 @@ -=== c:/root/folder1/file1.ts === -import {x} from "folder2/file1" ->x : number - -import {y} from "folder3/file2" ->y : number - -import {z} from "components/file3" ->z : number - -declare function use(a: any): void; ->use : (a: any) => void ->a : any - -use(x.toExponential()); ->use(x.toExponential()) : void ->use : (a: any) => void ->x.toExponential() : string ->x.toExponential : (fractionDigits?: number) => string ->x : number ->toExponential : (fractionDigits?: number) => string - -use(y.toExponential()); ->use(y.toExponential()) : void ->use : (a: any) => void ->y.toExponential() : string ->y.toExponential : (fractionDigits?: number) => string ->y : number ->toExponential : (fractionDigits?: number) => string - -use(z.toExponential()); ->use(z.toExponential()) : void ->use : (a: any) => void ->z.toExponential() : string ->z.toExponential : (fractionDigits?: number) => string ->z : number ->toExponential : (fractionDigits?: number) => string - -=== c:/root/folder2/file1.ts === -export var x = 1; ->x : number ->1 : number - -=== c:/root/generated/folder3/file2.ts === -export var y = 1; ->y : number ->1 : number - -=== c:/root/shared/components/file3.ts === -export var z = 1; ->z : number ->1 : number - diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution7_classic.js b/tests/baselines/reference/pathMappingBasedModuleResolution7_classic.js new file mode 100644 index 00000000000..5670f41be0f --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution7_classic.js @@ -0,0 +1,45 @@ +//// [tests/cases/compiler/pathMappingBasedModuleResolution7_classic.ts] //// + +//// [file1.ts] +import {x} from "./project/file2"; +import {y} from "module3"; + +declare function use(x: string); +use(x.toFixed()); +use(y.toFixed()); + +//// [file2.ts] +import {a} from "module1"; +import {b} from "templates/module2"; +import {x as c} from "../file3"; +export let x = a + b + c; + +//// [module1.d.ts] +export let a: number + +//// [module2.ts] +export let b: number; + +//// [file3.d.ts] +export let x: number; + +//// [module3.d.ts] +export let y: number; + + + +//// [module2.js] +define(["require", "exports"], function (require, exports) { + "use strict"; +}); +//// [file2.js] +define(["require", "exports", "module1", "templates/module2", "../file3"], function (require, exports, module1_1, module2_1, file3_1) { + "use strict"; + exports.x = module1_1.a + module2_1.b + file3_1.x; +}); +//// [file1.js] +define(["require", "exports", "./project/file2", "module3"], function (require, exports, file2_1, module3_1) { + "use strict"; + use(file2_1.x.toFixed()); + use(module3_1.y.toFixed()); +}); diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution7_classic.symbols b/tests/baselines/reference/pathMappingBasedModuleResolution7_classic.symbols new file mode 100644 index 00000000000..b1e4751c495 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution7_classic.symbols @@ -0,0 +1,57 @@ +=== c:/root/src/file1.ts === +import {x} from "./project/file2"; +>x : Symbol(x, Decl(file1.ts, 0, 8)) + +import {y} from "module3"; +>y : Symbol(y, Decl(file1.ts, 1, 8)) + +declare function use(x: string); +>use : Symbol(use, Decl(file1.ts, 1, 26)) +>x : Symbol(x, Decl(file1.ts, 3, 21)) + +use(x.toFixed()); +>use : Symbol(use, Decl(file1.ts, 1, 26)) +>x.toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(file1.ts, 0, 8)) +>toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --)) + +use(y.toFixed()); +>use : Symbol(use, Decl(file1.ts, 1, 26)) +>y.toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --)) +>y : Symbol(y, Decl(file1.ts, 1, 8)) +>toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --)) + +=== c:/root/generated/src/project/file2.ts === +import {a} from "module1"; +>a : Symbol(a, Decl(file2.ts, 0, 8)) + +import {b} from "templates/module2"; +>b : Symbol(b, Decl(file2.ts, 1, 8)) + +import {x as c} from "../file3"; +>x : Symbol(c, Decl(file2.ts, 2, 8)) +>c : Symbol(c, Decl(file2.ts, 2, 8)) + +export let x = a + b + c; +>x : Symbol(x, Decl(file2.ts, 3, 10)) +>a : Symbol(a, Decl(file2.ts, 0, 8)) +>b : Symbol(b, Decl(file2.ts, 1, 8)) +>c : Symbol(c, Decl(file2.ts, 2, 8)) + +=== c:/shared/module1.d.ts === +export let a: number +>a : Symbol(a, Decl(module1.d.ts, 0, 10)) + +=== c:/root/generated/src/templates/module2.ts === +export let b: number; +>b : Symbol(b, Decl(module2.ts, 0, 10)) + +=== c:/root/src/file3.d.ts === +export let x: number; +>x : Symbol(x, Decl(file3.d.ts, 0, 10)) + +=== c:/module3.d.ts === +export let y: number; +>y : Symbol(y, Decl(module3.d.ts, 0, 10)) + + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution7_classic.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution7_classic.trace.json new file mode 100644 index 00000000000..8242f8fb442 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution7_classic.trace.json @@ -0,0 +1,77 @@ +[ + "======== Resolving module './project/file2' from 'c:/root/src/file1.ts'. ========", + "Module resolution kind is not specified, using 'Classic'.", + "'rootDirs' option is set, using it to resolve relative module name './project/file2'", + "Checking if 'c:/root/src/' is the longest matching prefix for 'c:/root/src/project/file2' - 'true'.", + "Checking if 'c:/root/generated/src/' is the longest matching prefix for 'c:/root/src/project/file2' - 'false'.", + "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'", + "File 'c:/root/generated/src/project/file2.ts' exist - use it as a module resolution result.", + "======== 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'.", + "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'. ========", + "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'.", + "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'. ========", + "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'.", + "File 'c:/root/generated/src/templates/module2.ts' exist - use it as a module resolution result.", + "======== Module name 'templates/module2' was successfully resolved to 'c:/root/generated/src/templates/module2.ts'. ========", + "======== Resolving module '../file3' from 'c:/root/generated/src/project/file2.ts'. ========", + "Module resolution kind is not specified, using 'Classic'.", + "'rootDirs' option is set, using it to resolve relative module name '../file3'", + "Checking if 'c:/root/src/' is the longest matching prefix for 'c:/root/generated/src/file3' - 'false'.", + "Checking if 'c:/root/generated/src/' is the longest matching prefix for 'c:/root/generated/src/file3' - 'true'.", + "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'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution7_classic.types b/tests/baselines/reference/pathMappingBasedModuleResolution7_classic.types new file mode 100644 index 00000000000..26c4b425c88 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution7_classic.types @@ -0,0 +1,63 @@ +=== c:/root/src/file1.ts === +import {x} from "./project/file2"; +>x : number + +import {y} from "module3"; +>y : number + +declare function use(x: string); +>use : (x: string) => any +>x : string + +use(x.toFixed()); +>use(x.toFixed()) : any +>use : (x: string) => any +>x.toFixed() : string +>x.toFixed : (fractionDigits?: number) => string +>x : number +>toFixed : (fractionDigits?: number) => string + +use(y.toFixed()); +>use(y.toFixed()) : any +>use : (x: string) => any +>y.toFixed() : string +>y.toFixed : (fractionDigits?: number) => string +>y : number +>toFixed : (fractionDigits?: number) => string + +=== c:/root/generated/src/project/file2.ts === +import {a} from "module1"; +>a : number + +import {b} from "templates/module2"; +>b : number + +import {x as c} from "../file3"; +>x : number +>c : number + +export let x = a + b + c; +>x : number +>a + b + c : number +>a + b : number +>a : number +>b : number +>c : number + +=== c:/shared/module1.d.ts === +export let a: number +>a : number + +=== c:/root/generated/src/templates/module2.ts === +export let b: number; +>b : number + +=== c:/root/src/file3.d.ts === +export let x: number; +>x : number + +=== c:/module3.d.ts === +export let y: number; +>y : number + + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution7_node.js b/tests/baselines/reference/pathMappingBasedModuleResolution7_node.js new file mode 100644 index 00000000000..3be48cfc85c --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution7_node.js @@ -0,0 +1,44 @@ +//// [tests/cases/compiler/pathMappingBasedModuleResolution7_node.ts] //// + +//// [file1.ts] +import {x} from "./project/file2"; +import {y} from "module3"; + +declare function use(x: string); +use(x.toFixed()); +use(y.toFixed()); + +//// [file2.ts] +import {a} from "module1"; +import {b} from "templates/module2"; +import {x as c} from "../file3"; +export let x = a + b + c; + +//// [index.d.ts] +export let a: number + +//// [module2.ts] +export let b: number; + +//// [index.d.ts] +export let x: number; + +//// [module3.d.ts] +export let y: number; + + + +//// [module2.js] +"use strict"; +//// [file2.js] +"use strict"; +var module1_1 = require("module1"); +var module2_1 = require("templates/module2"); +var file3_1 = require("../file3"); +exports.x = module1_1.a + module2_1.b + file3_1.x; +//// [file1.js] +"use strict"; +var file2_1 = require("./project/file2"); +var module3_1 = require("module3"); +use(file2_1.x.toFixed()); +use(module3_1.y.toFixed()); diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution7_node.symbols b/tests/baselines/reference/pathMappingBasedModuleResolution7_node.symbols new file mode 100644 index 00000000000..9cda76790ea --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution7_node.symbols @@ -0,0 +1,57 @@ +=== c:/root/src/file1.ts === +import {x} from "./project/file2"; +>x : Symbol(x, Decl(file1.ts, 0, 8)) + +import {y} from "module3"; +>y : Symbol(y, Decl(file1.ts, 1, 8)) + +declare function use(x: string); +>use : Symbol(use, Decl(file1.ts, 1, 26)) +>x : Symbol(x, Decl(file1.ts, 3, 21)) + +use(x.toFixed()); +>use : Symbol(use, Decl(file1.ts, 1, 26)) +>x.toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(file1.ts, 0, 8)) +>toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --)) + +use(y.toFixed()); +>use : Symbol(use, Decl(file1.ts, 1, 26)) +>y.toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --)) +>y : Symbol(y, Decl(file1.ts, 1, 8)) +>toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --)) + +=== c:/root/generated/src/project/file2.ts === +import {a} from "module1"; +>a : Symbol(a, Decl(file2.ts, 0, 8)) + +import {b} from "templates/module2"; +>b : Symbol(b, Decl(file2.ts, 1, 8)) + +import {x as c} from "../file3"; +>x : Symbol(c, Decl(file2.ts, 2, 8)) +>c : Symbol(c, Decl(file2.ts, 2, 8)) + +export let x = a + b + c; +>x : Symbol(x, Decl(file2.ts, 3, 10)) +>a : Symbol(a, Decl(file2.ts, 0, 8)) +>b : Symbol(b, Decl(file2.ts, 1, 8)) +>c : Symbol(c, Decl(file2.ts, 2, 8)) + +=== c:/shared/module1/index.d.ts === +export let a: number +>a : Symbol(a, Decl(index.d.ts, 0, 10)) + +=== c:/root/generated/src/templates/module2.ts === +export let b: number; +>b : Symbol(b, Decl(module2.ts, 0, 10)) + +=== c:/root/src/file3/index.d.ts === +export let x: number; +>x : Symbol(x, Decl(index.d.ts, 0, 10)) + +=== c:/node_modules/module3.d.ts === +export let y: number; +>y : Symbol(y, Decl(module3.d.ts, 0, 10)) + + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution7_node.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution7_node.trace.json new file mode 100644 index 00000000000..39d5c25c92a --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution7_node.trace.json @@ -0,0 +1,123 @@ +[ + "======== Resolving module './project/file2' from 'c:/root/src/file1.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "'rootDirs' option is set, using it to resolve relative module name './project/file2'", + "Checking if 'c:/root/src/' is the longest matching prefix for 'c:/root/src/project/file2' - 'true'.", + "Checking if 'c:/root/generated/src/' is the longest matching prefix for 'c:/root/src/project/file2' - 'false'.", + "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'", + "Loading module as file / folder, candidate module 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.", + "File 'c:/root/src/project/file2/package.json' does not exist.", + "File 'c:/root/src/project/file2/index.ts' does not exist.", + "File 'c:/root/src/project/file2/index.tsx' does not exist.", + "File 'c:/root/src/project/file2/index.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'", + "Loading module as file / folder, candidate module location 'c:/root/generated/src/project/file2'.", + "File 'c:/root/generated/src/project/file2.ts' exist - use it as a module resolution result.", + "======== 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'.", + "Loading module as file / folder, candidate module location 'c:/root/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.", + "File 'c:/root/module3/package.json' does not exist.", + "File 'c:/root/module3/index.ts' does not exist.", + "File 'c:/root/module3/index.tsx' does not exist.", + "File 'c:/root/module3/index.d.ts' does not exist.", + "Trying substitution 'c:/shared/*', candidate module location: 'c:/shared/module3'.", + "Loading module as file / folder, 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:/shared/module3/package.json' does not exist.", + "File 'c:/shared/module3/index.ts' does not exist.", + "File 'c:/shared/module3/index.tsx' does not exist.", + "File 'c:/shared/module3/index.d.ts' does not exist.", + "Loading module 'module3' from 'node_modules' folder.", + "File 'c:/root/src/node_modules/module3.ts' does not exist.", + "File 'c:/root/src/node_modules/module3.tsx' does not exist.", + "File 'c:/root/src/node_modules/module3.d.ts' does not exist.", + "File 'c:/root/src/node_modules/module3/package.json' does not exist.", + "File 'c:/root/src/node_modules/module3/index.ts' does not exist.", + "File 'c:/root/src/node_modules/module3/index.tsx' does not exist.", + "File 'c:/root/src/node_modules/module3/index.d.ts' does not exist.", + "File 'c:/root/node_modules/module3.ts' does not exist.", + "File 'c:/root/node_modules/module3.tsx' does not exist.", + "File 'c:/root/node_modules/module3.d.ts' does not exist.", + "File 'c:/root/node_modules/module3/package.json' does not exist.", + "File 'c:/root/node_modules/module3/index.ts' does not exist.", + "File 'c:/root/node_modules/module3/index.tsx' does not exist.", + "File 'c:/root/node_modules/module3/index.d.ts' does not exist.", + "File 'c:/node_modules/module3.ts' does not exist.", + "File 'c:/node_modules/module3.tsx' does not exist.", + "File 'c:/node_modules/module3.d.ts' exist - use it as a module resolution result.", + "======== 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'.", + "Loading module as file / folder, candidate module location 'c:/root/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.", + "File 'c:/root/module1/package.json' does not exist.", + "File 'c:/root/module1/index.ts' does not exist.", + "File 'c:/root/module1/index.tsx' does not exist.", + "File 'c:/root/module1/index.d.ts' does not exist.", + "Trying substitution 'c:/shared/*', candidate module location: 'c:/shared/module1'.", + "Loading module as file / folder, 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' does not exist.", + "File 'c:/shared/module1/package.json' does not exist.", + "File 'c:/shared/module1/index.ts' does not exist.", + "File 'c:/shared/module1/index.tsx' does not exist.", + "File 'c:/shared/module1/index.d.ts' exist - use it as a module resolution result.", + "======== 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'.", + "Loading module as file / folder, candidate module location 'c:/root/generated/src/templates/module2'.", + "File 'c:/root/generated/src/templates/module2.ts' exist - use it as a module resolution result.", + "======== Module name 'templates/module2' was successfully resolved to 'c:/root/generated/src/templates/module2.ts'. ========", + "======== Resolving module '../file3' from 'c:/root/generated/src/project/file2.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "'rootDirs' option is set, using it to resolve relative module name '../file3'", + "Checking if 'c:/root/src/' is the longest matching prefix for 'c:/root/generated/src/file3' - 'false'.", + "Checking if 'c:/root/generated/src/' is the longest matching prefix for 'c:/root/generated/src/file3' - 'true'.", + "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'", + "Loading module as file / folder, candidate module 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.", + "File 'c:/root/generated/src/file3/package.json' does not exist.", + "File 'c:/root/generated/src/file3/index.ts' does not exist.", + "File 'c:/root/generated/src/file3/index.tsx' does not exist.", + "File 'c:/root/generated/src/file3/index.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'", + "Loading module as file / folder, candidate module 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' does not exist.", + "File 'c:/root/src/file3/package.json' does not exist.", + "File 'c:/root/src/file3/index.ts' does not exist.", + "File 'c:/root/src/file3/index.tsx' does not exist.", + "File 'c:/root/src/file3/index.d.ts' exist - use it as a module resolution result.", + "======== Module name '../file3' was successfully resolved to 'c:/root/src/file3/index.d.ts'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution7_node.types b/tests/baselines/reference/pathMappingBasedModuleResolution7_node.types new file mode 100644 index 00000000000..974f710b4c2 --- /dev/null +++ b/tests/baselines/reference/pathMappingBasedModuleResolution7_node.types @@ -0,0 +1,63 @@ +=== c:/root/src/file1.ts === +import {x} from "./project/file2"; +>x : number + +import {y} from "module3"; +>y : number + +declare function use(x: string); +>use : (x: string) => any +>x : string + +use(x.toFixed()); +>use(x.toFixed()) : any +>use : (x: string) => any +>x.toFixed() : string +>x.toFixed : (fractionDigits?: number) => string +>x : number +>toFixed : (fractionDigits?: number) => string + +use(y.toFixed()); +>use(y.toFixed()) : any +>use : (x: string) => any +>y.toFixed() : string +>y.toFixed : (fractionDigits?: number) => string +>y : number +>toFixed : (fractionDigits?: number) => string + +=== c:/root/generated/src/project/file2.ts === +import {a} from "module1"; +>a : number + +import {b} from "templates/module2"; +>b : number + +import {x as c} from "../file3"; +>x : number +>c : number + +export let x = a + b + c; +>x : number +>a + b + c : number +>a + b : number +>a : number +>b : number +>c : number + +=== c:/shared/module1/index.d.ts === +export let a: number +>a : number + +=== c:/root/generated/src/templates/module2.ts === +export let b: number; +>b : number + +=== c:/root/src/file3/index.d.ts === +export let x: number; +>x : number + +=== c:/node_modules/module3.d.ts === +export let y: number; +>y : number + + diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution8.js b/tests/baselines/reference/pathMappingBasedModuleResolution8.js deleted file mode 100644 index ba2f37bdc71..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution8.js +++ /dev/null @@ -1,44 +0,0 @@ -//// [tests/cases/compiler/pathMappingBasedModuleResolution8.ts] //// - -//// [file1.ts] -import {x} from "folder2/file1" -import {y} from "folder3/file2" -import {z} from "components/file3" - -declare function use(a: any): void; - -use(x.toExponential()); -use(y.toExponential()); -use(z.toExponential()); - -//// [file1.ts] -export var x = 1; - -//// [file2.ts] -export var y = 1; - -//// [file3.ts] -export var z = 1; - -//// [file1.js] -define(["require", "exports"], function (require, exports) { - "use strict"; - exports.x = 1; -}); -//// [file2.js] -define(["require", "exports"], function (require, exports) { - "use strict"; - exports.y = 1; -}); -//// [file3.js] -define(["require", "exports"], function (require, exports) { - "use strict"; - exports.z = 1; -}); -//// [file1.js] -define(["require", "exports", "folder2/file1", "folder3/file2", "components/file3"], function (require, exports, file1_1, file2_1, file3_1) { - "use strict"; - use(file1_1.x.toExponential()); - use(file2_1.y.toExponential()); - use(file3_1.z.toExponential()); -}); diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution8.symbols b/tests/baselines/reference/pathMappingBasedModuleResolution8.symbols deleted file mode 100644 index 214b1d30ba8..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution8.symbols +++ /dev/null @@ -1,44 +0,0 @@ -=== tests/cases/compiler/root/folder1/file1.ts === -import {x} from "folder2/file1" ->x : Symbol(x, Decl(file1.ts, 0, 8)) - -import {y} from "folder3/file2" ->y : Symbol(y, Decl(file1.ts, 1, 8)) - -import {z} from "components/file3" ->z : Symbol(z, Decl(file1.ts, 2, 8)) - -declare function use(a: any): void; ->use : Symbol(use, Decl(file1.ts, 2, 34)) ->a : Symbol(a, Decl(file1.ts, 4, 21)) - -use(x.toExponential()); ->use : Symbol(use, Decl(file1.ts, 2, 34)) ->x.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) ->x : Symbol(x, Decl(file1.ts, 0, 8)) ->toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) - -use(y.toExponential()); ->use : Symbol(use, Decl(file1.ts, 2, 34)) ->y.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) ->y : Symbol(y, Decl(file1.ts, 1, 8)) ->toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) - -use(z.toExponential()); ->use : Symbol(use, Decl(file1.ts, 2, 34)) ->z.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) ->z : Symbol(z, Decl(file1.ts, 2, 8)) ->toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) - -=== tests/cases/compiler/root/src/folder2/file1.ts === -export var x = 1; ->x : Symbol(x, Decl(file1.ts, 0, 10)) - -=== tests/cases/compiler/root/src/generated/folder3/file2.ts === -export var y = 1; ->y : Symbol(y, Decl(file2.ts, 0, 10)) - -=== tests/cases/compiler/root/src/shared/components/file3.ts === -export var z = 1; ->z : Symbol(z, Decl(file3.ts, 0, 10)) - diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution8.types b/tests/baselines/reference/pathMappingBasedModuleResolution8.types deleted file mode 100644 index 5938d95ee03..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution8.types +++ /dev/null @@ -1,53 +0,0 @@ -=== tests/cases/compiler/root/folder1/file1.ts === -import {x} from "folder2/file1" ->x : number - -import {y} from "folder3/file2" ->y : number - -import {z} from "components/file3" ->z : number - -declare function use(a: any): void; ->use : (a: any) => void ->a : any - -use(x.toExponential()); ->use(x.toExponential()) : void ->use : (a: any) => void ->x.toExponential() : string ->x.toExponential : (fractionDigits?: number) => string ->x : number ->toExponential : (fractionDigits?: number) => string - -use(y.toExponential()); ->use(y.toExponential()) : void ->use : (a: any) => void ->y.toExponential() : string ->y.toExponential : (fractionDigits?: number) => string ->y : number ->toExponential : (fractionDigits?: number) => string - -use(z.toExponential()); ->use(z.toExponential()) : void ->use : (a: any) => void ->z.toExponential() : string ->z.toExponential : (fractionDigits?: number) => string ->z : number ->toExponential : (fractionDigits?: number) => string - -=== tests/cases/compiler/root/src/folder2/file1.ts === -export var x = 1; ->x : number ->1 : number - -=== tests/cases/compiler/root/src/generated/folder3/file2.ts === -export var y = 1; ->y : number ->1 : number - -=== tests/cases/compiler/root/src/shared/components/file3.ts === -export var z = 1; ->z : number ->1 : number - diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution8_1.js b/tests/baselines/reference/pathMappingBasedModuleResolution8_1.js deleted file mode 100644 index 1aa0d19a29d..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution8_1.js +++ /dev/null @@ -1,55 +0,0 @@ -//// [tests/cases/compiler/pathMappingBasedModuleResolution8_1.ts] //// - -//// [file1.ts] -import {x} from "folder2/file1" -import {y} from "folder3/file2" -import {z} from "components/file3" -import {z1} from "file4" - -declare function use(a: any): void; - -use(x.toExponential()); -use(y.toExponential()); -use(z.toExponential()); -use(z1.toExponential()); - -//// [file1.ts] -export var x = 1; - -//// [file2.ts] -export var y = 1; - -//// [file3.ts] -export var z = 1; - -//// [file4.ts] -export var z1 = 1; - -//// [file1.js] -define(["require", "exports"], function (require, exports) { - "use strict"; - exports.x = 1; -}); -//// [file2.js] -define(["require", "exports"], function (require, exports) { - "use strict"; - exports.y = 1; -}); -//// [file3.js] -define(["require", "exports"], function (require, exports) { - "use strict"; - exports.z = 1; -}); -//// [file4.js] -define(["require", "exports"], function (require, exports) { - "use strict"; - exports.z1 = 1; -}); -//// [file1.js] -define(["require", "exports", "folder2/file1", "folder3/file2", "components/file3", "file4"], function (require, exports, file1_1, file2_1, file3_1, file4_1) { - "use strict"; - use(file1_1.x.toExponential()); - use(file2_1.y.toExponential()); - use(file3_1.z.toExponential()); - use(file4_1.z1.toExponential()); -}); diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution9.js b/tests/baselines/reference/pathMappingBasedModuleResolution9.js deleted file mode 100644 index 57e53934eed..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution9.js +++ /dev/null @@ -1,52 +0,0 @@ -//// [tests/cases/compiler/pathMappingBasedModuleResolution9.ts] //// - -//// [file1.ts] -import {x} from "folder2/file1" -import {y} from "folder3/file2" -import {z} from "components/file3" - -declare function use(a: any): void; - -use(x.toExponential()); -use(y.toExponential()); -use(z.toExponential()); - -//// [file1.ts] -export var x = 1; - -//// [file2.ts] -export var y = 1; - -//// [file3.ts] -export {z} from "./file4" - -//// [file4.ts] -export var z = 1; - -//// [file1.js] -define(["require", "exports"], function (require, exports) { - "use strict"; - exports.x = 1; -}); -//// [file2.js] -define(["require", "exports"], function (require, exports) { - "use strict"; - exports.y = 1; -}); -//// [file4.js] -define(["require", "exports"], function (require, exports) { - "use strict"; - exports.z = 1; -}); -//// [file3.js] -define(["require", "exports", "./file4"], function (require, exports, file4_1) { - "use strict"; - exports.z = file4_1.z; -}); -//// [file1.js] -define(["require", "exports", "folder2/file1", "folder3/file2", "components/file3"], function (require, exports, file1_1, file2_1, file3_1) { - "use strict"; - use(file1_1.x.toExponential()); - use(file2_1.y.toExponential()); - use(file3_1.z.toExponential()); -}); diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution9.symbols b/tests/baselines/reference/pathMappingBasedModuleResolution9.symbols deleted file mode 100644 index 764f878b293..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution9.symbols +++ /dev/null @@ -1,48 +0,0 @@ -=== tests/cases/compiler/root/folder1/file1.ts === -import {x} from "folder2/file1" ->x : Symbol(x, Decl(file1.ts, 0, 8)) - -import {y} from "folder3/file2" ->y : Symbol(y, Decl(file1.ts, 1, 8)) - -import {z} from "components/file3" ->z : Symbol(z, Decl(file1.ts, 2, 8)) - -declare function use(a: any): void; ->use : Symbol(use, Decl(file1.ts, 2, 34)) ->a : Symbol(a, Decl(file1.ts, 4, 21)) - -use(x.toExponential()); ->use : Symbol(use, Decl(file1.ts, 2, 34)) ->x.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) ->x : Symbol(x, Decl(file1.ts, 0, 8)) ->toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) - -use(y.toExponential()); ->use : Symbol(use, Decl(file1.ts, 2, 34)) ->y.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) ->y : Symbol(y, Decl(file1.ts, 1, 8)) ->toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) - -use(z.toExponential()); ->use : Symbol(use, Decl(file1.ts, 2, 34)) ->z.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) ->z : Symbol(z, Decl(file1.ts, 2, 8)) ->toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) - -=== tests/cases/compiler/root/src/folder2/file1.ts === -export var x = 1; ->x : Symbol(x, Decl(file1.ts, 0, 10)) - -=== tests/cases/compiler/root/src/generated/folder3/file2.ts === -export var y = 1; ->y : Symbol(y, Decl(file2.ts, 0, 10)) - -=== tests/cases/compiler/root/src/shared/components/file3.ts === -export {z} from "./file4" ->z : Symbol(z, Decl(file3.ts, 0, 8)) - -=== tests/cases/compiler/root/src/shared/components/file4.ts === -export var z = 1; ->z : Symbol(z, Decl(file4.ts, 0, 10)) - diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution9.types b/tests/baselines/reference/pathMappingBasedModuleResolution9.types deleted file mode 100644 index 789e8d050b1..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution9.types +++ /dev/null @@ -1,57 +0,0 @@ -=== tests/cases/compiler/root/folder1/file1.ts === -import {x} from "folder2/file1" ->x : number - -import {y} from "folder3/file2" ->y : number - -import {z} from "components/file3" ->z : number - -declare function use(a: any): void; ->use : (a: any) => void ->a : any - -use(x.toExponential()); ->use(x.toExponential()) : void ->use : (a: any) => void ->x.toExponential() : string ->x.toExponential : (fractionDigits?: number) => string ->x : number ->toExponential : (fractionDigits?: number) => string - -use(y.toExponential()); ->use(y.toExponential()) : void ->use : (a: any) => void ->y.toExponential() : string ->y.toExponential : (fractionDigits?: number) => string ->y : number ->toExponential : (fractionDigits?: number) => string - -use(z.toExponential()); ->use(z.toExponential()) : void ->use : (a: any) => void ->z.toExponential() : string ->z.toExponential : (fractionDigits?: number) => string ->z : number ->toExponential : (fractionDigits?: number) => string - -=== tests/cases/compiler/root/src/folder2/file1.ts === -export var x = 1; ->x : number ->1 : number - -=== tests/cases/compiler/root/src/generated/folder3/file2.ts === -export var y = 1; ->y : number ->1 : number - -=== tests/cases/compiler/root/src/shared/components/file3.ts === -export {z} from "./file4" ->z : number - -=== tests/cases/compiler/root/src/shared/components/file4.ts === -export var z = 1; ->z : number ->1 : number - diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution9_1.js b/tests/baselines/reference/pathMappingBasedModuleResolution9_1.js deleted file mode 100644 index ff719ebc2be..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution9_1.js +++ /dev/null @@ -1,63 +0,0 @@ -//// [tests/cases/compiler/pathMappingBasedModuleResolution9_1.ts] //// - -//// [file1.ts] -import {x} from "folder2/file1" -import {y} from "folder3/file2" -import {z} from "components/file3" -import {z1} from "my/file4" - -declare function use(a: any): void; - -use(x.toExponential()); -use(y.toExponential()); -use(z.toExponential()); -use(z1.toExponential()); - -//// [file1.ts] -export var x = 1; - -//// [file2.ts] -export var y = 1; - -//// [file3.ts] -export {z} from "./file4" - -//// [file4.ts] -export var z = 1; - -//// [file4.ts] -export var z1 = 1; - -//// [file1.js] -define(["require", "exports"], function (require, exports) { - "use strict"; - exports.x = 1; -}); -//// [file2.js] -define(["require", "exports"], function (require, exports) { - "use strict"; - exports.y = 1; -}); -//// [file4.js] -define(["require", "exports"], function (require, exports) { - "use strict"; - exports.z = 1; -}); -//// [file3.js] -define(["require", "exports", "./file4"], function (require, exports, file4_1) { - "use strict"; - exports.z = file4_1.z; -}); -//// [file4.js] -define(["require", "exports"], function (require, exports) { - "use strict"; - exports.z1 = 1; -}); -//// [file1.js] -define(["require", "exports", "folder2/file1", "folder3/file2", "components/file3", "my/file4"], function (require, exports, file1_1, file2_1, file3_1, file4_1) { - "use strict"; - use(file1_1.x.toExponential()); - use(file2_1.y.toExponential()); - use(file3_1.z.toExponential()); - use(file4_1.z1.toExponential()); -}); diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution9_1.symbols b/tests/baselines/reference/pathMappingBasedModuleResolution9_1.symbols deleted file mode 100644 index 6f244cf026e..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution9_1.symbols +++ /dev/null @@ -1,61 +0,0 @@ -=== c:/root/folder1/file1.ts === -import {x} from "folder2/file1" ->x : Symbol(x, Decl(file1.ts, 0, 8)) - -import {y} from "folder3/file2" ->y : Symbol(y, Decl(file1.ts, 1, 8)) - -import {z} from "components/file3" ->z : Symbol(z, Decl(file1.ts, 2, 8)) - -import {z1} from "my/file4" ->z1 : Symbol(z1, Decl(file1.ts, 3, 8)) - -declare function use(a: any): void; ->use : Symbol(use, Decl(file1.ts, 3, 27)) ->a : Symbol(a, Decl(file1.ts, 5, 21)) - -use(x.toExponential()); ->use : Symbol(use, Decl(file1.ts, 3, 27)) ->x.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) ->x : Symbol(x, Decl(file1.ts, 0, 8)) ->toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) - -use(y.toExponential()); ->use : Symbol(use, Decl(file1.ts, 3, 27)) ->y.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) ->y : Symbol(y, Decl(file1.ts, 1, 8)) ->toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) - -use(z.toExponential()); ->use : Symbol(use, Decl(file1.ts, 3, 27)) ->z.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) ->z : Symbol(z, Decl(file1.ts, 2, 8)) ->toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) - -use(z1.toExponential()); ->use : Symbol(use, Decl(file1.ts, 3, 27)) ->z1.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) ->z1 : Symbol(z1, Decl(file1.ts, 3, 8)) ->toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) - -=== c:/root/src/folder2/file1.ts === -export var x = 1; ->x : Symbol(x, Decl(file1.ts, 0, 10)) - -=== c:/root/src/generated/folder3/file2.ts === -export var y = 1; ->y : Symbol(y, Decl(file2.ts, 0, 10)) - -=== c:/root/src/shared/components/file3.ts === -export {z} from "./file4" ->z : Symbol(z, Decl(file3.ts, 0, 8)) - -=== c:/root/src/shared/components/file4.ts === -export var z = 1; ->z : Symbol(z, Decl(file4.ts, 0, 10)) - -=== c:/sharedrepo/my/file4.ts === -export var z1 = 1; ->z1 : Symbol(z1, Decl(file4.ts, 0, 10)) - diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution9_1.types b/tests/baselines/reference/pathMappingBasedModuleResolution9_1.types deleted file mode 100644 index 24e70346d2a..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution9_1.types +++ /dev/null @@ -1,73 +0,0 @@ -=== c:/root/folder1/file1.ts === -import {x} from "folder2/file1" ->x : number - -import {y} from "folder3/file2" ->y : number - -import {z} from "components/file3" ->z : number - -import {z1} from "my/file4" ->z1 : number - -declare function use(a: any): void; ->use : (a: any) => void ->a : any - -use(x.toExponential()); ->use(x.toExponential()) : void ->use : (a: any) => void ->x.toExponential() : string ->x.toExponential : (fractionDigits?: number) => string ->x : number ->toExponential : (fractionDigits?: number) => string - -use(y.toExponential()); ->use(y.toExponential()) : void ->use : (a: any) => void ->y.toExponential() : string ->y.toExponential : (fractionDigits?: number) => string ->y : number ->toExponential : (fractionDigits?: number) => string - -use(z.toExponential()); ->use(z.toExponential()) : void ->use : (a: any) => void ->z.toExponential() : string ->z.toExponential : (fractionDigits?: number) => string ->z : number ->toExponential : (fractionDigits?: number) => string - -use(z1.toExponential()); ->use(z1.toExponential()) : void ->use : (a: any) => void ->z1.toExponential() : string ->z1.toExponential : (fractionDigits?: number) => string ->z1 : number ->toExponential : (fractionDigits?: number) => string - -=== c:/root/src/folder2/file1.ts === -export var x = 1; ->x : number ->1 : number - -=== c:/root/src/generated/folder3/file2.ts === -export var y = 1; ->y : number ->1 : number - -=== c:/root/src/shared/components/file3.ts === -export {z} from "./file4" ->z : number - -=== c:/root/src/shared/components/file4.ts === -export var z = 1; ->z : number ->1 : number - -=== c:/sharedrepo/my/file4.ts === -export var z1 = 1; ->z1 : number ->1 : number - diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution9_2.js b/tests/baselines/reference/pathMappingBasedModuleResolution9_2.js deleted file mode 100644 index 8fb164e1d54..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution9_2.js +++ /dev/null @@ -1,63 +0,0 @@ -//// [tests/cases/compiler/pathMappingBasedModuleResolution9_2.ts] //// - -//// [file1.ts] -import {x} from "folder2/file1" -import {y} from "folder3/file2" -import {z} from "components/file3" -import {z1} from "my/file4" - -declare function use(a: any): void; - -use(x.toExponential()); -use(y.toExponential()); -use(z.toExponential()); -use(z1.toExponential()); - -//// [file1.ts] -export var x = 1; - -//// [file2.ts] -export var y = 1; - -//// [file3.ts] -export {z} from "./file4" - -//// [file4.ts] -export var z = 1; - -//// [file4.ts] -export var z1 = 1; - -//// [file1.js] -define(["require", "exports"], function (require, exports) { - "use strict"; - exports.x = 1; -}); -//// [file2.js] -define(["require", "exports"], function (require, exports) { - "use strict"; - exports.y = 1; -}); -//// [file4.js] -define(["require", "exports"], function (require, exports) { - "use strict"; - exports.z = 1; -}); -//// [file3.js] -define(["require", "exports", "./file4"], function (require, exports, file4_1) { - "use strict"; - exports.z = file4_1.z; -}); -//// [file4.js] -define(["require", "exports"], function (require, exports) { - "use strict"; - exports.z1 = 1; -}); -//// [file1.js] -define(["require", "exports", "folder2/file1", "folder3/file2", "components/file3", "my/file4"], function (require, exports, file1_1, file2_1, file3_1, file4_1) { - "use strict"; - use(file1_1.x.toExponential()); - use(file2_1.y.toExponential()); - use(file3_1.z.toExponential()); - use(file4_1.z1.toExponential()); -}); diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution9_2.symbols b/tests/baselines/reference/pathMappingBasedModuleResolution9_2.symbols deleted file mode 100644 index f9f5bc671ab..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution9_2.symbols +++ /dev/null @@ -1,61 +0,0 @@ -=== c:/root/folder1/file1.ts === -import {x} from "folder2/file1" ->x : Symbol(x, Decl(file1.ts, 0, 8)) - -import {y} from "folder3/file2" ->y : Symbol(y, Decl(file1.ts, 1, 8)) - -import {z} from "components/file3" ->z : Symbol(z, Decl(file1.ts, 2, 8)) - -import {z1} from "my/file4" ->z1 : Symbol(z1, Decl(file1.ts, 3, 8)) - -declare function use(a: any): void; ->use : Symbol(use, Decl(file1.ts, 3, 27)) ->a : Symbol(a, Decl(file1.ts, 5, 21)) - -use(x.toExponential()); ->use : Symbol(use, Decl(file1.ts, 3, 27)) ->x.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) ->x : Symbol(x, Decl(file1.ts, 0, 8)) ->toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) - -use(y.toExponential()); ->use : Symbol(use, Decl(file1.ts, 3, 27)) ->y.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) ->y : Symbol(y, Decl(file1.ts, 1, 8)) ->toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) - -use(z.toExponential()); ->use : Symbol(use, Decl(file1.ts, 3, 27)) ->z.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) ->z : Symbol(z, Decl(file1.ts, 2, 8)) ->toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) - -use(z1.toExponential()); ->use : Symbol(use, Decl(file1.ts, 3, 27)) ->z1.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) ->z1 : Symbol(z1, Decl(file1.ts, 3, 8)) ->toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) - -=== c:/base/folder2/file1.ts === -export var x = 1; ->x : Symbol(x, Decl(file1.ts, 0, 10)) - -=== c:/base/generated/folder3/file2.ts === -export var y = 1; ->y : Symbol(y, Decl(file2.ts, 0, 10)) - -=== c:/base/shared/components/file3.ts === -export {z} from "./file4" ->z : Symbol(z, Decl(file3.ts, 0, 8)) - -=== c:/base/shared/components/file4.ts === -export var z = 1; ->z : Symbol(z, Decl(file4.ts, 0, 10)) - -=== c:/sharedrepo/my/file4.ts === -export var z1 = 1; ->z1 : Symbol(z1, Decl(file4.ts, 0, 10)) - diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution9_2.types b/tests/baselines/reference/pathMappingBasedModuleResolution9_2.types deleted file mode 100644 index e84babf0a79..00000000000 --- a/tests/baselines/reference/pathMappingBasedModuleResolution9_2.types +++ /dev/null @@ -1,73 +0,0 @@ -=== c:/root/folder1/file1.ts === -import {x} from "folder2/file1" ->x : number - -import {y} from "folder3/file2" ->y : number - -import {z} from "components/file3" ->z : number - -import {z1} from "my/file4" ->z1 : number - -declare function use(a: any): void; ->use : (a: any) => void ->a : any - -use(x.toExponential()); ->use(x.toExponential()) : void ->use : (a: any) => void ->x.toExponential() : string ->x.toExponential : (fractionDigits?: number) => string ->x : number ->toExponential : (fractionDigits?: number) => string - -use(y.toExponential()); ->use(y.toExponential()) : void ->use : (a: any) => void ->y.toExponential() : string ->y.toExponential : (fractionDigits?: number) => string ->y : number ->toExponential : (fractionDigits?: number) => string - -use(z.toExponential()); ->use(z.toExponential()) : void ->use : (a: any) => void ->z.toExponential() : string ->z.toExponential : (fractionDigits?: number) => string ->z : number ->toExponential : (fractionDigits?: number) => string - -use(z1.toExponential()); ->use(z1.toExponential()) : void ->use : (a: any) => void ->z1.toExponential() : string ->z1.toExponential : (fractionDigits?: number) => string ->z1 : number ->toExponential : (fractionDigits?: number) => string - -=== c:/base/folder2/file1.ts === -export var x = 1; ->x : number ->1 : number - -=== c:/base/generated/folder3/file2.ts === -export var y = 1; ->y : number ->1 : number - -=== c:/base/shared/components/file3.ts === -export {z} from "./file4" ->z : number - -=== c:/base/shared/components/file4.ts === -export var z = 1; ->z : number ->1 : number - -=== c:/sharedrepo/my/file4.ts === -export var z1 = 1; ->z1 : number ->1 : number - diff --git a/tests/baselines/reference/staticInstanceResolution5.errors.txt b/tests/baselines/reference/staticInstanceResolution5.errors.txt index 3c1cee93fd5..da6f0fde143 100644 --- a/tests/baselines/reference/staticInstanceResolution5.errors.txt +++ b/tests/baselines/reference/staticInstanceResolution5.errors.txt @@ -1,15 +1,21 @@ -tests/cases/compiler/staticInstanceResolution5_1.ts(1,24): error TS2307: Cannot find module 'staticInstanceResolution5_0.ts'. +tests/cases/compiler/staticInstanceResolution5_1.ts(4,14): error TS2304: Cannot find name 'WinJS'. +tests/cases/compiler/staticInstanceResolution5_1.ts(5,23): error TS2304: Cannot find name 'WinJS'. +tests/cases/compiler/staticInstanceResolution5_1.ts(6,16): error TS2304: Cannot find name 'WinJS'. -==== tests/cases/compiler/staticInstanceResolution5_1.ts (1 errors) ==== +==== tests/cases/compiler/staticInstanceResolution5_1.ts (3 errors) ==== import WinJS = require('staticInstanceResolution5_0.ts'); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2307: Cannot find module 'staticInstanceResolution5_0.ts'. // these 3 should be errors var x = (w1: WinJS) => { }; + ~~~~~ +!!! error TS2304: Cannot find name 'WinJS'. var y = function (w2: WinJS) { } + ~~~~~ +!!! error TS2304: Cannot find name 'WinJS'. function z(w3: WinJS) { } + ~~~~~ +!!! error TS2304: Cannot find name 'WinJS'. ==== tests/cases/compiler/staticInstanceResolution5_0.ts (0 errors) ==== export class Promise { diff --git a/tests/baselines/reference/staticInstanceResolution5.js b/tests/baselines/reference/staticInstanceResolution5.js index 58def522978..0809d1af5f0 100644 --- a/tests/baselines/reference/staticInstanceResolution5.js +++ b/tests/baselines/reference/staticInstanceResolution5.js @@ -16,6 +16,19 @@ var y = function (w2: WinJS) { } function z(w3: WinJS) { } +//// [staticInstanceResolution5_0.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + var Promise = (function () { + function Promise() { + } + Promise.timeout = function (delay) { + return null; + }; + return Promise; + }()); + exports.Promise = Promise; +}); //// [staticInstanceResolution5_1.js] define(["require", "exports"], function (require, exports) { "use strict"; diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution1.ts b/tests/cases/compiler/pathMappingBasedModuleResolution1.ts deleted file mode 100644 index d6c24d75f96..00000000000 --- a/tests/cases/compiler/pathMappingBasedModuleResolution1.ts +++ /dev/null @@ -1,18 +0,0 @@ -// @moduleResolution: baseUrl -// @module: commonjs -// @baseUrl: root - -// user defined base url - -// @filename: root/folder1/file1.ts -import {x} from "folder2/file2" - -declare function use(a: any): void; - -use(x.toExponential()); - -// @filename: root/folder2/file2.ts -export {x} from "./file3" - -// @filename: root/folder2/file3.ts -export var x = 1; \ No newline at end of file diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution10.ts b/tests/cases/compiler/pathMappingBasedModuleResolution10.ts deleted file mode 100644 index 2f32cf3e7cd..00000000000 --- a/tests/cases/compiler/pathMappingBasedModuleResolution10.ts +++ /dev/null @@ -1,34 +0,0 @@ -// @module: amd - -// paths\rootDirs is defined in tsconfig.json -// baseUrl is inferred from tsconfig.json - -// @filename: root/tsconfig.json -{ - "compilerOptions": { - "paths": { - "*": [ - "*", - "generated/*" - ] - }, - "rootDirs": [ - ".", - "./generated" - ] - } -} -// @filename: root/folder1/file1.ts -import {x} from "./file2" // should be resolved to 'generated/folder1/file2.ts' - -export var z = x.toExponential(); - -// @filename: root/generated/folder1/file2.ts -export {x} from "folder1/file3" // should be resolved to 'folder1/file3.ts' - -// @filename: root/folder1/file3.ts -export var x = 1; - -// @filename: root/generated/folder2/file3.ts -import {z as y} from "../folder1/file1" // should be resolved to 'folder1/file1.ts' -let z = y.toLowerCase(); diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution10_1.ts b/tests/cases/compiler/pathMappingBasedModuleResolution10_1.ts deleted file mode 100644 index 6cc6f8e32d9..00000000000 --- a/tests/cases/compiler/pathMappingBasedModuleResolution10_1.ts +++ /dev/null @@ -1,35 +0,0 @@ -// @module: amd - -// paths\rootDirs is defined in tsconfig.json -// baseUrl is inferred from tsconfig.json - -// @filename: c:/root/tsconfig.json -{ - "compilerOptions": { - "paths": { - "*": [ - "*", - "generated/*" - ] - }, - "rootDirs": [ - ".", - "./generated" - ] - } -} - -// @filename: c:/root/generated/folder1/file2.ts -export {x} from "folder1/file3" // should be resolved to 'folder1/file3.ts' - -// @filename: c:/root/folder1/file3.ts -export var x = 1; - -// @filename: c:/root/generated/folder2/file3.ts -import {z as y} from "../folder1/file1" // should be resolved to 'folder1/file1.ts' -let z = y.toLowerCase(); - -// @filename: c:/root/folder1/file1.ts -import {x} from "./file2" // should be resolved to 'generated/folder1/file2.ts' - -export var z = x.toExponential(); diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution10_2.ts b/tests/cases/compiler/pathMappingBasedModuleResolution10_2.ts deleted file mode 100644 index 754df23f4bf..00000000000 --- a/tests/cases/compiler/pathMappingBasedModuleResolution10_2.ts +++ /dev/null @@ -1,36 +0,0 @@ -// @module: amd - -// paths\rootDirs is defined in tsconfig.json -// baseUrl is defined in tsconfig.json - -// @filename: c:/root/tsconfig.json -{ - "compilerOptions": { - "baseUrl": "./src", - "paths": { - "*": [ - "*", - "generated/*" - ] - }, - "rootDirs": [ - "./src/", - "./src/generated" - ] - } -} - -// @filename: c:/root/src/generated/folder1/file2.ts -export {x} from "folder1/file3" // should be resolved to 'folder1/file3.ts' - -// @filename: c:/root/src/folder1/file3.ts -export var x = 1; - -// @filename: c:/root/src/generated/folder2/file3.ts -import {z as y} from "../folder1/file1" // should be resolved to 'folder1/file1.ts' -let z = y.toLowerCase(); - -// @filename: c:/root/src/folder1/file1.ts -import {x} from "./file2" // should be resolved to 'generated/folder1/file2.ts' - -export var z = x.toExponential(); diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution11.ts b/tests/cases/compiler/pathMappingBasedModuleResolution11.ts deleted file mode 100644 index e0504126ca1..00000000000 --- a/tests/cases/compiler/pathMappingBasedModuleResolution11.ts +++ /dev/null @@ -1,34 +0,0 @@ -// @module: amd - -// paths\rootDirs is defined in tsconfig.json -// baseUrl is inferred from tsconfig.json - -// @filename: root/tsconfig.json -{ - "compilerOptions": { - "paths": { - "*": [ - "*", - "generated/*/file" - ] - }, - "rootDirs": [ - ".", - "./generated" - ] - } -} -// @filename: root/folder1/file1.ts -import {x} from "./file2" // should be resolved to 'generated/folder1/file2/file.ts' - -export var z = x.toExponential(); - -// @filename: root/generated/folder1/file2/file.ts -export {x} from "folder1/file3" // should be resolved to 'folder1/file3.ts' - -// @filename: root/folder1/file3.ts -export var x = 1; - -// @filename: root/generated/folder2/file3.ts -import {z as y} from "../folder1/file1" // should be resolved to 'folder1/file1.ts' -let z = y.toLowerCase(); diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution1_1.ts b/tests/cases/compiler/pathMappingBasedModuleResolution1_1.ts deleted file mode 100644 index fa987961cd2..00000000000 --- a/tests/cases/compiler/pathMappingBasedModuleResolution1_1.ts +++ /dev/null @@ -1,18 +0,0 @@ -// @moduleResolution: baseUrl -// @module: commonjs -// @baseUrl: c:/root - -// user defined base url - -// @filename: c:/root/folder1/file1.ts -import {x} from "folder2/file2" - -declare function use(a: any): void; - -use(x.toExponential()); - -// @filename: c:/root/folder2/file2.ts -export {x} from "./file3" - -// @filename: c:/root/folder2/file3.ts -export var x = 1; \ No newline at end of file diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution1_classic.ts b/tests/cases/compiler/pathMappingBasedModuleResolution1_classic.ts new file mode 100644 index 00000000000..20845a49372 --- /dev/null +++ b/tests/cases/compiler/pathMappingBasedModuleResolution1_classic.ts @@ -0,0 +1,19 @@ +// @module: amd +// @traceModuleResolution: true + +// paths should error in the absence of baseurl + +// @filename: c:/root/tsconfig.json +{ + "compilerOptions": { + "paths": { + "*": [ + "*", + "generated/*" + ] + } + } +} + +// @filename: c:/root/f1.ts +export var x = 1; diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution1_node.ts b/tests/cases/compiler/pathMappingBasedModuleResolution1_node.ts new file mode 100644 index 00000000000..392e85bd7c3 --- /dev/null +++ b/tests/cases/compiler/pathMappingBasedModuleResolution1_node.ts @@ -0,0 +1,18 @@ +// @module: commonjs +// @traceModuleResolution: true + +// paths should error in the absence of baseurl +// @filename: c:/root/tsconfig.json +{ + "compilerOptions": { + "paths": { + "*": [ + "*", + "generated/*" + ] + } + } +} + +// @filename: c:/root/f1.ts +export var x = 1; diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution2.ts b/tests/cases/compiler/pathMappingBasedModuleResolution2.ts deleted file mode 100644 index 84bfc36b8d1..00000000000 --- a/tests/cases/compiler/pathMappingBasedModuleResolution2.ts +++ /dev/null @@ -1,22 +0,0 @@ -// @module: commonjs - -// location of tsconfig.json as baseurl - -// @filename: root/tsconfig.json -{ - "compilerOptions": { - "moduleResolution": "baseUrl" - } -} -// @filename: root/folder1/file1.ts -import {x} from "folder2/file2" - -declare function use(a: any): void; - -use(x.toExponential()); - -// @filename: root/folder2/file2.ts -export {x} from "./file3" - -// @filename: root/folder2/file3.ts -export var x = 1; \ No newline at end of file diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution2_1.ts b/tests/cases/compiler/pathMappingBasedModuleResolution2_1.ts deleted file mode 100644 index 4b94e352879..00000000000 --- a/tests/cases/compiler/pathMappingBasedModuleResolution2_1.ts +++ /dev/null @@ -1,22 +0,0 @@ -// @module: commonjs - -// location of tsconfig.json as baseurl - -// @filename: c:/root/tsconfig.json -{ - "compilerOptions": { - "moduleResolution": "baseUrl" - } -} -// @filename: c:/root/folder1/file1.ts -import {x} from "folder2/file2" - -declare function use(a: any): void; - -use(x.toExponential()); - -// @filename: c:/root/folder2/file2.ts -export {x} from "./file3" - -// @filename: c:/root/folder2/file3.ts -export var x = 1; \ No newline at end of file diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution6.ts b/tests/cases/compiler/pathMappingBasedModuleResolution2_classic.ts similarity index 80% rename from tests/cases/compiler/pathMappingBasedModuleResolution6.ts rename to tests/cases/compiler/pathMappingBasedModuleResolution2_classic.ts index f1e51afc805..6c84a197eeb 100644 --- a/tests/cases/compiler/pathMappingBasedModuleResolution6.ts +++ b/tests/cases/compiler/pathMappingBasedModuleResolution2_classic.ts @@ -1,4 +1,5 @@ // @module: amd +// @traceModuleResolution: true // baseurl is defined in tsconfig.json // paths has errors diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution2_node.ts b/tests/cases/compiler/pathMappingBasedModuleResolution2_node.ts new file mode 100644 index 00000000000..78ef7215e73 --- /dev/null +++ b/tests/cases/compiler/pathMappingBasedModuleResolution2_node.ts @@ -0,0 +1,18 @@ +// @module: commonjs +// @traceModuleResolution: true + +// baseurl is defined in tsconfig.json +// paths has errors + +// @filename: root/tsconfig.json +{ + "compilerOptions": { + "baseUrl": "./src", + "paths": { + "*1*": [ "*2*" ] + } + } +} + +// @filename: root/src/folder1/file1.ts +export var x = 1; \ No newline at end of file diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution3.ts b/tests/cases/compiler/pathMappingBasedModuleResolution3.ts deleted file mode 100644 index 466e8c90d77..00000000000 --- a/tests/cases/compiler/pathMappingBasedModuleResolution3.ts +++ /dev/null @@ -1,23 +0,0 @@ -// @module: commonjs - -// baseurl is defined in tsconfig.json - -// @filename: root/tsconfig.json -{ - "compilerOptions": { - "moduleResolution": "baseUrl", - "baseUrl": "./src" - } -} -// @filename: root/src/folder1/file1.ts -import {x} from "folder2/file2" - -declare function use(a: any): void; - -use(x.toExponential()); - -// @filename: root/src/folder2/file2.ts -export {x} from "./file3" - -// @filename: root/src/folder2/file3.ts -export var x = 1; \ No newline at end of file diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution3_1.ts b/tests/cases/compiler/pathMappingBasedModuleResolution3_1.ts deleted file mode 100644 index f3a8ccaf0a8..00000000000 --- a/tests/cases/compiler/pathMappingBasedModuleResolution3_1.ts +++ /dev/null @@ -1,23 +0,0 @@ -// @module: commonjs - -// baseurl is defined in tsconfig.json - -// @filename: c:/root/tsconfig.json -{ - "compilerOptions": { - "moduleResolution": "baseUrl", - "baseUrl": "./src" - } -} -// @filename: c:/root/src/folder1/file1.ts -import {x} from "folder2/file2" - -declare function use(a: any): void; - -use(x.toExponential()); - -// @filename: c:/root/src/folder2/file2.ts -export {x} from "./file3" - -// @filename: c:/root/src/folder2/file3.ts -export var x = 1; \ No newline at end of file diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution3_classic.ts b/tests/cases/compiler/pathMappingBasedModuleResolution3_classic.ts new file mode 100644 index 00000000000..d46308d089f --- /dev/null +++ b/tests/cases/compiler/pathMappingBasedModuleResolution3_classic.ts @@ -0,0 +1,22 @@ +// @moduleResolution: classic +// @module: amd +// @baseUrl: c:/root +// @traceModuleResolution: true + +// baseUrl set via command line + +// @filename: c:/root/folder1/file1.ts +import {x} from "folder2/file2" +declare function use(a: any): void; +use(x.toExponential()); + +// @filename: c:/root/folder2/file2.ts +import {x as a} from "./file3" // found with baseurl +import {y as b} from "file4" // found with fallback +export var x = a + b; + +// @filename: c:/root/folder2/file3.ts +export var x = 1; + +// @filename: c:/file4.ts +export var y = 100; \ No newline at end of file diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution3_node.ts b/tests/cases/compiler/pathMappingBasedModuleResolution3_node.ts new file mode 100644 index 00000000000..30e95c9303e --- /dev/null +++ b/tests/cases/compiler/pathMappingBasedModuleResolution3_node.ts @@ -0,0 +1,22 @@ +// @moduleResolution: node +// @module: commonjs +// @baseUrl: c:/root +// @traceModuleResolution: true + +// baseUrl set via command line + +// @filename: c:/root/folder1/file1.ts +import {x} from "folder2/file2" +declare function use(a: any): void; +use(x.toExponential()); + +// @filename: c:/root/folder2/file2.ts +import {x as a} from "./file3" // found with baseurl +import {y as b} from "file4" // found with fallback +export var x = a + b; + +// @filename: c:/root/folder2/file3.ts +export var x = 1; + +// @filename: c:/node_modules/file4/index.d.ts +export var y: number; \ No newline at end of file diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution4.ts b/tests/cases/compiler/pathMappingBasedModuleResolution4.ts deleted file mode 100644 index 17f8258e763..00000000000 --- a/tests/cases/compiler/pathMappingBasedModuleResolution4.ts +++ /dev/null @@ -1,23 +0,0 @@ -// @module: amd - -// baseurl is defined in tsconfig.json -// module resolution kind is inferred from settings (baseurl is specified) - -// @filename: root/tsconfig.json -{ - "compilerOptions": { - "baseUrl": "./src" - } -} -// @filename: root/src/folder1/file1.ts -import {x} from "folder2/file2" - -declare function use(a: any): void; - -use(x.toExponential()); - -// @filename: root/src/folder2/file2.ts -export {x} from "./file3" - -// @filename: root/src/folder2/file3.ts -export var x = 1; \ No newline at end of file diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution4_1.ts b/tests/cases/compiler/pathMappingBasedModuleResolution4_1.ts deleted file mode 100644 index df6f267da65..00000000000 --- a/tests/cases/compiler/pathMappingBasedModuleResolution4_1.ts +++ /dev/null @@ -1,23 +0,0 @@ -// @module: amd - -// baseurl is defined in tsconfig.json -// module resolution kind is inferred from settings (baseurl is specified) - -// @filename: c:/root/tsconfig.json -{ - "compilerOptions": { - "baseUrl": "./src" - } -} -// @filename: c:/root/src/folder1/file1.ts -import {x} from "folder2/file2" - -declare function use(a: any): void; - -use(x.toExponential()); - -// @filename: c:/root/src/folder2/file2.ts -export {x} from "./file3" - -// @filename: c:/root/src/folder2/file3.ts -export var x = 1; \ No newline at end of file diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution4_classic.ts b/tests/cases/compiler/pathMappingBasedModuleResolution4_classic.ts new file mode 100644 index 00000000000..723de05b70c --- /dev/null +++ b/tests/cases/compiler/pathMappingBasedModuleResolution4_classic.ts @@ -0,0 +1,28 @@ +// @moduleResolution: classic +// @module: amd +// @traceModuleResolution: true + +// baseUrl set via command line + +// @filename: c:/root/tsconfig.json +{ + "compilerOptions": { + "baseUrl": "." + } +} + +// @filename: c:/root/folder1/file1.ts +import {x} from "folder2/file2" +declare function use(a: any): void; +use(x.toExponential()); + +// @filename: c:/root/folder2/file2.ts +import {x as a} from "./file3" // found with baseurl +import {y as b} from "file4" // found with fallback +export var x = a + b; + +// @filename: c:/root/folder2/file3.ts +export var x = 1; + +// @filename: c:/file4.ts +export var y = 100; \ No newline at end of file diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution4_node.ts b/tests/cases/compiler/pathMappingBasedModuleResolution4_node.ts new file mode 100644 index 00000000000..e68635e205e --- /dev/null +++ b/tests/cases/compiler/pathMappingBasedModuleResolution4_node.ts @@ -0,0 +1,28 @@ +// @moduleResolution: node +// @module: commonjs +// @traceModuleResolution: true + +// baseUrl set via command line + +// @filename: c:/root/tsconfig.json +{ + "compilerOptions": { + "baseUrl": "." + } +} + +// @filename: c:/root/folder1/file1.ts +import {x} from "folder2/file2" +declare function use(a: any): void; +use(x.toExponential()); + +// @filename: c:/root/folder2/file2.ts +import {x as a} from "./file3" // found with baseurl +import {y as b} from "file4" // found with fallback +export var x = a + b; + +// @filename: c:/root/folder2/file3.ts +export var x = 1; + +// @filename: c:/node_modules/file4/index.d.ts +export var y: number; \ No newline at end of file diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution5.ts b/tests/cases/compiler/pathMappingBasedModuleResolution5.ts deleted file mode 100644 index 305f7aa9c3f..00000000000 --- a/tests/cases/compiler/pathMappingBasedModuleResolution5.ts +++ /dev/null @@ -1,13 +0,0 @@ -// @module: commonjs - -// baseurl is defined in tsconfig.json -// module resolution kind is ambiguous - error should be reported - -// @filename: root/tsconfig.json -{ - "compilerOptions": { - "baseUrl": "./src" - } -} -// @filename: root/src/folder1/file1.ts -export var x = 1; \ No newline at end of file diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution7_2.ts b/tests/cases/compiler/pathMappingBasedModuleResolution5_classic.ts similarity index 69% rename from tests/cases/compiler/pathMappingBasedModuleResolution7_2.ts rename to tests/cases/compiler/pathMappingBasedModuleResolution5_classic.ts index 16284349643..a7662688e37 100644 --- a/tests/cases/compiler/pathMappingBasedModuleResolution7_2.ts +++ b/tests/cases/compiler/pathMappingBasedModuleResolution5_classic.ts @@ -1,20 +1,19 @@ // @module: amd +// @traceModuleResolution: true // paths is defined in tsconfig.json -// module resolution kind is inferred from the presence of 'paths' - // @filename: c:/root/tsconfig.json { "compilerOptions": { + "baseUrl": ".", "paths": { "*": [ "*", - "generated/*", - "c:/sharedrepo/*" + "generated/*" ], - "components/*": [ - "shared/components/*" - ] + "components/*": [ + "shared/components/*" + ] } } } @@ -40,5 +39,5 @@ export var y = 1; // @filename: c:/root/shared/components/file3.ts export var z = 1; -// @filename: c:/sharedrepo/file4.ts +// @filename: c:/file4.ts export var z1 = 1; \ No newline at end of file diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution7_1.ts b/tests/cases/compiler/pathMappingBasedModuleResolution5_node.ts similarity index 57% rename from tests/cases/compiler/pathMappingBasedModuleResolution7_1.ts rename to tests/cases/compiler/pathMappingBasedModuleResolution5_node.ts index c64eb687764..ef5ef0afd6a 100644 --- a/tests/cases/compiler/pathMappingBasedModuleResolution7_1.ts +++ b/tests/cases/compiler/pathMappingBasedModuleResolution5_node.ts @@ -1,19 +1,19 @@ -// @module: amd +// @module: commonjs +// @traceModuleResolution: true // paths is defined in tsconfig.json -// module resolution kind is inferred from the presence of 'paths' - // @filename: c:/root/tsconfig.json { "compilerOptions": { - "paths": { + "baseUrl": ".", + "paths": { "*": [ "*", "generated/*" ], - "components/*": [ - "shared/components/*" - ] + "components/*": [ + "shared/components/*" + ] } } } @@ -21,12 +21,14 @@ import {x} from "folder2/file1" import {y} from "folder3/file2" import {z} from "components/file3" +import {z1} from "file4" declare function use(a: any): void; use(x.toExponential()); use(y.toExponential()); use(z.toExponential()); +use(z1.toExponential()); // @filename: c:/root/folder2/file1.ts export var x = 1; @@ -34,5 +36,8 @@ export var x = 1; // @filename: c:/root/generated/folder3/file2.ts export var y = 1; -// @filename: c:/root/shared/components/file3.ts -export var z = 1; \ No newline at end of file +// @filename: c:/root/shared/components/file3/index.d.ts +export var z: number; + +// @filename: c:/node_modules/file4.ts +export var z1 = 1; \ No newline at end of file diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution6_classic.ts b/tests/cases/compiler/pathMappingBasedModuleResolution6_classic.ts new file mode 100644 index 00000000000..adaba8478c9 --- /dev/null +++ b/tests/cases/compiler/pathMappingBasedModuleResolution6_classic.ts @@ -0,0 +1,23 @@ +// @module: amd +// @traceModuleResolution: true + +// @filename: c:/root/src/tsconfig.json +{ + "compilerOptions": { + "rootDirs": [ + ".", + "../generated/src" + ] + } +} + +// @filename: c:/root/src/file1.ts +import {x} from "./project/file3"; +declare function use(x: string); +use(x.toExponential()); + +// @filename: c:/root/src/file2.d.ts +export let x: number; + +// @filename: c:/root/generated/src/project/file3.ts +export {x} from "../file2"; \ No newline at end of file diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution6_node.ts b/tests/cases/compiler/pathMappingBasedModuleResolution6_node.ts new file mode 100644 index 00000000000..a3d0feadf7c --- /dev/null +++ b/tests/cases/compiler/pathMappingBasedModuleResolution6_node.ts @@ -0,0 +1,23 @@ +// @module: commonjs +// @traceModuleResolution: true + +// @filename: c:/root/src/tsconfig.json +{ + "compilerOptions": { + "rootDirs": [ + ".", + "../generated/src" + ] + } +} + +// @filename: c:/root/src/file1.ts +import {x} from "./project/file3"; +declare function use(x: string); +use(x.toFixed()); + +// @filename: c:/root/src/file2/index.d.ts +export let x: number; + +// @filename: c:/root/generated/src/project/file3.ts +export {x} from "../file2"; \ No newline at end of file diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution7.ts b/tests/cases/compiler/pathMappingBasedModuleResolution7.ts deleted file mode 100644 index f59f0701a33..00000000000 --- a/tests/cases/compiler/pathMappingBasedModuleResolution7.ts +++ /dev/null @@ -1,38 +0,0 @@ -// @module: amd - -// paths is defined in tsconfig.json -// module resolution kind is inferred from the presence of 'paths' - -// @filename: root/tsconfig.json -{ - "compilerOptions": { - "paths": { - "*": [ - "*", - "generated/*" - ], - "components/*": [ - "shared/components/*" - ] - } - } -} -// @filename: root/folder1/file1.ts -import {x} from "folder2/file1" -import {y} from "folder3/file2" -import {z} from "components/file3" - -declare function use(a: any): void; - -use(x.toExponential()); -use(y.toExponential()); -use(z.toExponential()); - -// @filename: root/folder2/file1.ts -export var x = 1; - -// @filename: root/generated/folder3/file2.ts -export var y = 1; - -// @filename: root/shared/components/file3.ts -export var z = 1; \ No newline at end of file diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution7_classic.ts b/tests/cases/compiler/pathMappingBasedModuleResolution7_classic.ts new file mode 100644 index 00000000000..af092df5ce9 --- /dev/null +++ b/tests/cases/compiler/pathMappingBasedModuleResolution7_classic.ts @@ -0,0 +1,49 @@ +// @module: amd +// @traceModuleResolution: true + +// @filename: c:/root/src/tsconfig.json +{ + "compilerOptions": { + "baseUrl": "../", + "paths": { + "*": [ + "*", + "c:/shared/*" + ], + "templates/*": [ + "generated/src/templates/*" + ] + }, + "rootDirs": [ + ".", + "../generated/src" + ] + } +} + +// @filename: c:/root/src/file1.ts +import {x} from "./project/file2"; +import {y} from "module3"; + +declare function use(x: string); +use(x.toFixed()); +use(y.toFixed()); + +// @filename: c:/root/generated/src/project/file2.ts +import {a} from "module1"; +import {b} from "templates/module2"; +import {x as c} from "../file3"; +export let x = a + b + c; + +// @filename: c:/shared/module1.d.ts +export let a: number + +// @filename: c:/root/generated/src/templates/module2.ts +export let b: number; + +// @filename: c:/root/src/file3.d.ts +export let x: number; + +// @filename: c:/module3.d.ts +export let y: number; + diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution7_node.ts b/tests/cases/compiler/pathMappingBasedModuleResolution7_node.ts new file mode 100644 index 00000000000..faecbe4adb9 --- /dev/null +++ b/tests/cases/compiler/pathMappingBasedModuleResolution7_node.ts @@ -0,0 +1,49 @@ +// @module: commonjs +// @traceModuleResolution: true + +// @filename: c:/root/src/tsconfig.json +{ + "compilerOptions": { + "baseUrl": "../", + "paths": { + "*": [ + "*", + "c:/shared/*" + ], + "templates/*": [ + "generated/src/templates/*" + ] + }, + "rootDirs": [ + ".", + "../generated/src" + ] + } +} + +// @filename: c:/root/src/file1.ts +import {x} from "./project/file2"; +import {y} from "module3"; + +declare function use(x: string); +use(x.toFixed()); +use(y.toFixed()); + +// @filename: c:/root/generated/src/project/file2.ts +import {a} from "module1"; +import {b} from "templates/module2"; +import {x as c} from "../file3"; +export let x = a + b + c; + +// @filename: c:/shared/module1/index.d.ts +export let a: number + +// @filename: c:/root/generated/src/templates/module2.ts +export let b: number; + +// @filename: c:/root/src/file3/index.d.ts +export let x: number; + +// @filename: c:/node_modules/module3.d.ts +export let y: number; + diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution8.ts b/tests/cases/compiler/pathMappingBasedModuleResolution8.ts deleted file mode 100644 index dc2be22c4ca..00000000000 --- a/tests/cases/compiler/pathMappingBasedModuleResolution8.ts +++ /dev/null @@ -1,39 +0,0 @@ -// @module: amd - -// paths is defined in tsconfig.json -// baseUrl is specified in tsconfig.json - -// @filename: root/tsconfig.json -{ - "compilerOptions": { - "baseUrl": "./src", - "paths": { - "*": [ - "*", - "generated/*" - ], - "components/*": [ - "shared/components/*" - ] - } - } -} -// @filename: root/folder1/file1.ts -import {x} from "folder2/file1" -import {y} from "folder3/file2" -import {z} from "components/file3" - -declare function use(a: any): void; - -use(x.toExponential()); -use(y.toExponential()); -use(z.toExponential()); - -// @filename: root/src/folder2/file1.ts -export var x = 1; - -// @filename: root/src/generated/folder3/file2.ts -export var y = 1; - -// @filename: root/src/shared/components/file3.ts -export var z = 1; \ No newline at end of file diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution8_1.ts b/tests/cases/compiler/pathMappingBasedModuleResolution8_1.ts deleted file mode 100644 index b858be9455d..00000000000 --- a/tests/cases/compiler/pathMappingBasedModuleResolution8_1.ts +++ /dev/null @@ -1,45 +0,0 @@ -// @module: amd - -// paths is defined in tsconfig.json -// baseUrl is specified in tsconfig.json - -// @filename: c:/root/tsconfig.json -{ - "compilerOptions": { - "baseUrl": "./src", - "paths": { - "*": [ - "*", - "generated/*", - "c:/sharedrepo/*" - ], - "components/*": [ - "shared/components/*" - ] - } - } -} -// @filename: c:/root/folder1/file1.ts -import {x} from "folder2/file1" -import {y} from "folder3/file2" -import {z} from "components/file3" -import {z1} from "file4" - -declare function use(a: any): void; - -use(x.toExponential()); -use(y.toExponential()); -use(z.toExponential()); -use(z1.toExponential()); - -// @filename: c:/root/src/folder2/file1.ts -export var x = 1; - -// @filename: c:/root/src/generated/folder3/file2.ts -export var y = 1; - -// @filename: c:/root/src/shared/components/file3.ts -export var z = 1; - -// @filename: c:/sharedrepo/file4.ts -export var z1 = 1; \ No newline at end of file diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution9.ts b/tests/cases/compiler/pathMappingBasedModuleResolution9.ts deleted file mode 100644 index 1b104a27251..00000000000 --- a/tests/cases/compiler/pathMappingBasedModuleResolution9.ts +++ /dev/null @@ -1,42 +0,0 @@ -// @module: amd - -// paths is defined in tsconfig.json -// baseUrl is specified in tsconfig.json - -// @filename: root/tsconfig.json -{ - "compilerOptions": { - "baseUrl": "./src", - "paths": { - "*": [ - "*", - "generated/*" - ], - "components/*": [ - "shared/components/*" - ] - } - } -} -// @filename: root/folder1/file1.ts -import {x} from "folder2/file1" -import {y} from "folder3/file2" -import {z} from "components/file3" - -declare function use(a: any): void; - -use(x.toExponential()); -use(y.toExponential()); -use(z.toExponential()); - -// @filename: root/src/folder2/file1.ts -export var x = 1; - -// @filename: root/src/generated/folder3/file2.ts -export var y = 1; - -// @filename: root/src/shared/components/file3.ts -export {z} from "./file4" - -// @filename: root/src/shared/components/file4.ts -export var z = 1; \ No newline at end of file diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution9_1.ts b/tests/cases/compiler/pathMappingBasedModuleResolution9_1.ts deleted file mode 100644 index 68a0898229c..00000000000 --- a/tests/cases/compiler/pathMappingBasedModuleResolution9_1.ts +++ /dev/null @@ -1,48 +0,0 @@ -// @module: amd - -// paths is defined in tsconfig.json -// baseUrl is specified in tsconfig.json - -// @filename: c:/root/tsconfig.json -{ - "compilerOptions": { - "baseUrl": "./src", - "paths": { - "*": [ - "*", - "generated/*", - "c:/sharedrepo/*" - ], - "components/*": [ - "shared/components/*" - ] - } - } -} -// @filename: c:/root/folder1/file1.ts -import {x} from "folder2/file1" -import {y} from "folder3/file2" -import {z} from "components/file3" -import {z1} from "my/file4" - -declare function use(a: any): void; - -use(x.toExponential()); -use(y.toExponential()); -use(z.toExponential()); -use(z1.toExponential()); - -// @filename: c:/root/src/folder2/file1.ts -export var x = 1; - -// @filename: c:/root/src/generated/folder3/file2.ts -export var y = 1; - -// @filename: c:/root/src/shared/components/file3.ts -export {z} from "./file4" - -// @filename: c:/root/src/shared/components/file4.ts -export var z = 1; - -// @filename: c:/sharedrepo/my/file4.ts -export var z1 = 1; \ No newline at end of file diff --git a/tests/cases/compiler/pathMappingBasedModuleResolution9_2.ts b/tests/cases/compiler/pathMappingBasedModuleResolution9_2.ts deleted file mode 100644 index 83990d3c5ad..00000000000 --- a/tests/cases/compiler/pathMappingBasedModuleResolution9_2.ts +++ /dev/null @@ -1,48 +0,0 @@ -// @module: amd - -// paths is defined in tsconfig.json -// baseUrl is specified in tsconfig.json and it is absolute - -// @filename: c:/root/tsconfig.json -{ - "compilerOptions": { - "baseUrl": "c:/base", - "paths": { - "*": [ - "*", - "generated/*", - "c:/sharedrepo/*" - ], - "components/*": [ - "shared/components/*" - ] - } - } -} -// @filename: c:/root/folder1/file1.ts -import {x} from "folder2/file1" -import {y} from "folder3/file2" -import {z} from "components/file3" -import {z1} from "my/file4" - -declare function use(a: any): void; - -use(x.toExponential()); -use(y.toExponential()); -use(z.toExponential()); -use(z1.toExponential()); - -// @filename: c:/base/folder2/file1.ts -export var x = 1; - -// @filename: c:/base/generated/folder3/file2.ts -export var y = 1; - -// @filename: c:/base/shared/components/file3.ts -export {z} from "./file4" - -// @filename: c:/base/shared/components/file4.ts -export var z = 1; - -// @filename: c:/sharedrepo/my/file4.ts -export var z1 = 1; \ No newline at end of file diff --git a/tests/cases/unittests/cachingInServerLSHost.ts b/tests/cases/unittests/cachingInServerLSHost.ts index 88b44a693b9..59f97f434e6 100644 --- a/tests/cases/unittests/cachingInServerLSHost.ts +++ b/tests/cases/unittests/cachingInServerLSHost.ts @@ -7,6 +7,10 @@ module ts { } function createDefaultServerHost(fileMap: Map): server.ServerHost { + const directories: Map = {}; + for (const f in fileMap) { + directories[getDirectoryPath(f)] = f; + } return { args: [], newLine: "\r\n", @@ -26,7 +30,7 @@ module ts { return hasProperty(fileMap, path); }, directoryExists: (path: string): boolean => { - throw new Error("NYI"); + return hasProperty(directories, path); }, createDirectory: (path: string) => { }, diff --git a/tests/cases/unittests/moduleResolution.ts b/tests/cases/unittests/moduleResolution.ts index cc5324cb44a..6bbbdcc90b4 100644 --- a/tests/cases/unittests/moduleResolution.ts +++ b/tests/cases/unittests/moduleResolution.ts @@ -459,7 +459,8 @@ import b = require("./moduleB.ts"); }) }); - describe("baseUrl module resolution", () => { + describe("baseUrl augmented module resolution", () => { + it("module resolution without path mappings/rootDirs", () => { test(/*hasDirectoryExists*/ false); test(/*hasDirectoryExists*/ true); @@ -469,42 +470,100 @@ import b = require("./moduleB.ts"); const file2: File = { name: "/root/folder2/file2.ts" }; const file3: File = { name: "/root/folder2/file3.ts" }; const host = createModuleResolutionHost(hasDirectoryExists, file1, file2, file3); - const options: CompilerOptions = { moduleResolution: ModuleResolutionKind.BaseUrl, baseUrl: "/root" }; - { - const result = baseUrlModuleNameResolver("folder2/file2", file1.name, options, host); - assert.isTrue(result.resolvedModule !== undefined, "module should be resolved"); - assert.equal(result.resolvedModule.resolvedFileName, file2.name); - assert.deepEqual(result.failedLookupLocations, []); - } - { - const result = baseUrlModuleNameResolver("./file3", file2.name, options, host); - assert.isTrue(result.resolvedModule !== undefined, "module should be resolved"); - assert.equal(result.resolvedModule.resolvedFileName, file3.name); - assert.deepEqual(result.failedLookupLocations, []); - } - { - const result = baseUrlModuleNameResolver(file1.name, file2.name, options, host); - assert.isTrue(result.resolvedModule !== undefined, "module should be resolved"); - assert.equal(result.resolvedModule.resolvedFileName, file1.name); - assert.deepEqual(result.failedLookupLocations, []); + for (const moduleResolution of [ ModuleResolutionKind.NodeJs, ModuleResolutionKind.Classic ]) { + const options: CompilerOptions = { moduleResolution, baseUrl: "/root" }; + { + const result = resolveModuleName("folder2/file2", file1.name, options, host); + assert.isTrue(result.resolvedModule !== undefined, "module should be resolved"); + assert.equal(result.resolvedModule.resolvedFileName, file2.name); + assert.deepEqual(result.failedLookupLocations, []); + } + { + const result = resolveModuleName("./file3", file2.name, options, host); + assert.isTrue(result.resolvedModule !== undefined, "module should be resolved"); + assert.equal(result.resolvedModule.resolvedFileName, file3.name); + assert.deepEqual(result.failedLookupLocations, []); + } + { + const result = resolveModuleName("/root/folder1/file1", file2.name, options, host); + assert.isTrue(result.resolvedModule !== undefined, "module should be resolved"); + assert.equal(result.resolvedModule.resolvedFileName, file1.name); + assert.deepEqual(result.failedLookupLocations, []); + } } } // add failure tests }); - - it("module resolution with path mappings", () => { + + it("node + baseUrl", () => { test(/*hasDirectoryExists*/ false); test(/*hasDirectoryExists*/ true); function test(hasDirectoryExists: boolean) { + const main: File = { name: "/root/a/b/main.ts" }; + const m1: File = { name: "/root/m1.ts" }; // load file as module + const m2: File = { name: "/root/m2/index.d.ts" }; // load folder as module + const m3: File = { name: "/root/m3/package.json", content: JSON.stringify({ typings: "dist/typings.d.ts" }) }; + const m3Typings: File = { name: "/root/m3/dist/typings.d.ts" }; + const m4: File = { name: "/root/node_modules/m4.ts" }; // fallback to node + + const options: CompilerOptions = { moduleResolution: ModuleResolutionKind.NodeJs, baseUrl: "/root" }; + const host = createModuleResolutionHost(hasDirectoryExists, main, m1, m2, m3, m3Typings, m4); + + check("m1", main, m1); + check("m2", main, m2); + check("m3", main, m3Typings); + check("m4", main, m4); + + function check(name: string, caller: File, expected: File) { + const result = resolveModuleName(name, caller.name, options, host); + assert.isTrue(result.resolvedModule !== undefined); + assert.equal(result.resolvedModule.resolvedFileName, expected.name); + } + } + }); + + it("classic + baseUrl", () => { + test(/*hasDirectoryExists*/ false); + test(/*hasDirectoryExists*/ true); + + function test(hasDirectoryExists: boolean) { + const main: File = { name: "/root/a/b/main.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 host = createModuleResolutionHost(hasDirectoryExists, main, m1, m2); + + check("m1", main, m1); + check("m2", main, m2); + + function check(name: string, caller: File, expected: File) { + const result = resolveModuleName(name, caller.name, options, host); + assert.isTrue(result.resolvedModule !== undefined); + assert.equal(result.resolvedModule.resolvedFileName, expected.name); + } + } + }) + + it("node + baseUrl + path mappings", () => { + test(/*hasDirectoryExists*/ false); + test(/*hasDirectoryExists*/ true); + + function test(hasDirectoryExists: boolean) { + const main: File = { name: "/root/folder1/main.ts" }; + const file1: File = { name: "/root/folder1/file1.ts" }; - const file2: File = { name: "/root/folder1/file2.ts" } - const file3: File = { name: "/root/generated/folder1/file3.ts" } - const file4: File = { name: "/root/generated/folder2/file4.ts" } - const file5: File = { name: "/root/someanotherfolder/file5.ts" } - const host = createModuleResolutionHost(hasDirectoryExists, file1, file2, file3, file4, file5); + const file2: File = { name: "/root/generated/folder1/file2.ts" } // load remapped file as module + const file3: File = { name: "/root/generated/folder2/file3/index.d.ts" } // load folder a module + const file4Typings: File = { name: "/root/generated/folder2/file4/package.json", content: JSON.stringify({ typings: "dist/types.d.ts" })}; + const file4: File = { name: "/root/generated/folder2/file4/dist/types.d.ts" }; // load file pointed by typings + const file5: File = { name: "/root/someanotherfolder/file5/index.d.ts" } // load remapped module from folder + const file6: File = { name: "/root/node_modules/file6.ts" }; // fallback to node + const host = createModuleResolutionHost(hasDirectoryExists, file1, file2, file3, file4, file4Typings, file5, file6); + const options: CompilerOptions = { - moduleResolution: ModuleResolutionKind.BaseUrl, + moduleResolution: ModuleResolutionKind.NodeJs, baseUrl: "/root", paths: { "*": [ @@ -516,50 +575,242 @@ import b = require("./moduleB.ts"); ] } }; - { - const result = baseUrlModuleNameResolver("folder1/file2", file1.name, options, host); + check("folder1/file1", file1, []); + check("folder1/file2", file2, [ + // first try the '*' + "/root/folder1/file2.ts", + "/root/folder1/file2.tsx", + "/root/folder1/file2.d.ts", + "/root/folder1/file2/package.json", + "/root/folder1/file2/index.ts", + "/root/folder1/file2/index.tsx", + "/root/folder1/file2/index.d.ts" + // then first attempt on 'generated/*' was successful + ]); + check("folder2/file3", file3, [ + // first try '*' + "/root/folder2/file3.ts", + "/root/folder2/file3.tsx", + "/root/folder2/file3.d.ts", + "/root/folder2/file3/package.json", + "/root/folder2/file3/index.ts", + "/root/folder2/file3/index.tsx", + "/root/folder2/file3/index.d.ts", + // then use remapped location + "/root/generated/folder2/file3.ts", + "/root/generated/folder2/file3.tsx", + "/root/generated/folder2/file3.d.ts", + "/root/generated/folder2/file3/package.json", + "/root/generated/folder2/file3/index.ts", + "/root/generated/folder2/file3/index.tsx", + // success on index.d.ts + ]); + check("folder2/file4", file4, [ + // first try '*' + "/root/folder2/file4.ts", + "/root/folder2/file4.tsx", + "/root/folder2/file4.d.ts", + "/root/folder2/file4/package.json", + "/root/folder2/file4/index.ts", + "/root/folder2/file4/index.tsx", + "/root/folder2/file4/index.d.ts", + // try to load from file from remapped location + "/root/generated/folder2/file4.ts", + "/root/generated/folder2/file4.tsx", + "/root/generated/folder2/file4.d.ts" + // success on loading as from folder + ]); + check("somefolder/file5", file5, [ + // load from remapped location + // first load from fle + "/root/someanotherfolder/file5.ts", + "/root/someanotherfolder/file5.tsx", + "/root/someanotherfolder/file5.d.ts", + // load from folder + "/root/someanotherfolder/file5/package.json", + "/root/someanotherfolder/file5/index.ts", + "/root/someanotherfolder/file5/index.tsx", + // success on index.d.ts + ]); + check("file6", file6, [ + // first try * + // load from file + "/root/file6.ts", + "/root/file6.tsx", + "/root/file6.d.ts", + // load from folder + "/root/file6/package.json", + "/root/file6/index.ts", + "/root/file6/index.tsx", + "/root/file6/index.d.ts", + // then try 'generated/*' + // load from file + "/root/generated/file6.ts", + "/root/generated/file6.tsx", + "/root/generated/file6.d.ts", + // load from folder + "/root/generated/file6/package.json", + "/root/generated/file6/index.ts", + "/root/generated/file6/index.tsx", + "/root/generated/file6/index.d.ts", + // fallback to standard node behavior + // load from file + "/root/folder1/node_modules/file6.ts", + "/root/folder1/node_modules/file6.tsx", + "/root/folder1/node_modules/file6.d.ts", + // load from folder + "/root/folder1/node_modules/file6/package.json", + "/root/folder1/node_modules/file6/index.ts", + "/root/folder1/node_modules/file6/index.tsx", + "/root/folder1/node_modules/file6/index.d.ts", + // success on /root/node_modules/file6.ts + ]); + + function check(name: string, expected: File, expectedFailedLookups: string[]) { + const result = resolveModuleName(name, main.name, options, host); assert.isTrue(result.resolvedModule !== undefined, "module should be resolved"); - assert.equal(result.resolvedModule.resolvedFileName, file2.name); - assert.deepEqual(result.failedLookupLocations, []); + assert.equal(result.resolvedModule.resolvedFileName, expected.name); + assert.deepEqual(result.failedLookupLocations, expectedFailedLookups); } - { - const result = baseUrlModuleNameResolver("./file2", file1.name, options, host); - assert.isTrue(result.resolvedModule !== undefined, "module should be resolved"); - assert.equal(result.resolvedModule.resolvedFileName, file2.name); - assert.deepEqual(result.failedLookupLocations, []); - } - { - const result = baseUrlModuleNameResolver("folder1/file3", file1.name, options, host); - assert.isTrue(result.resolvedModule !== undefined, "module should be resolved"); - assert.equal(result.resolvedModule.resolvedFileName, file3.name); - // non-empty because it tries to use '*' match first - assert.deepEqual(result.failedLookupLocations, [ - "/root/folder1/file3.ts", - "/root/folder1/file3.tsx", - "/root/folder1/file3.d.ts", - ]); - } - { - const result = baseUrlModuleNameResolver("folder2/file4", file1.name, options, host); - assert.isTrue(result.resolvedModule !== undefined, "module should be resolved"); - assert.equal(result.resolvedModule.resolvedFileName, file4.name); - assert.deepEqual(result.failedLookupLocations, [ - "/root/folder2/file4.ts", - "/root/folder2/file4.tsx", - "/root/folder2/file4.d.ts", - ]); - } - { - const result = baseUrlModuleNameResolver("somefolder/file5", file1.name, options, host); - assert.isTrue(result.resolvedModule !== undefined, "module should be resolved"); - assert.equal(result.resolvedModule.resolvedFileName, file5.name); - assert.deepEqual(result.failedLookupLocations, []); - } - // add failure tests } }); - it("module resolution with path mappings and root dirs", () => { + it ("classic + baseUrl + path mappings", () => { + test(/*hasDirectoryExists*/ false); + test(/*hasDirectoryExists*/ true); + + function test(hasDirectoryExists: boolean) { + const main: File = { name: "/root/folder1/main.ts" }; + + const file1: File = { name: "/root/folder1/file1.ts" }; + const file2: File = { name: "/root/generated/folder1/file2.ts" }; + const file3: File = { name: "/folder1/file3.ts" }; // fallback to classic + const host = createModuleResolutionHost(hasDirectoryExists, file1, file2, file3); + + const options: CompilerOptions = { + moduleResolution: ModuleResolutionKind.Classic, + baseUrl: "/root", + paths: { + "*": [ + "*", + "generated/*" + ], + "somefolder/*": [ + "someanotherfolder/*" + ] + } + }; + check("folder1/file1", file1, []); + check("folder1/file2", file2, [ + // first try '*' + "/root/folder1/file2.ts", + "/root/folder1/file2.tsx", + "/root/folder1/file2.d.ts", + // success when using 'generated/*' + ]); + check("folder1/file3", file3, [ + // first try '*' + "/root/folder1/file3.ts", + "/root/folder1/file3.tsx", + "/root/folder1/file3.d.ts", + // then try 'generated/*' + "/root/generated/folder1/file3.ts", + "/root/generated/folder1/file3.tsx", + "/root/generated/folder1/file3.d.ts", + // fallback to classic + "/root/folder1/folder1/file3.ts", + "/root/folder1/folder1/file3.tsx", + "/root/folder1/folder1/file3.d.ts", + "/root/folder1/file3.ts", + "/root/folder1/file3.tsx", + "/root/folder1/file3.d.ts", + ]); + + function check(name: string, expected: File, expectedFailedLookups: string[]) { + const result = resolveModuleName(name, main.name, options, host); + assert.isTrue(result.resolvedModule !== undefined, "module should be resolved"); + assert.equal(result.resolvedModule.resolvedFileName, expected.name); + assert.deepEqual(result.failedLookupLocations, expectedFailedLookups); + } + } + }) + + it ("node + rootDirs", () => { + test(/*hasDirectoryExists*/ false); + test(/*hasDirectoryExists*/ true); + + function test(hasDirectoryExists: boolean) { + let file1: File = { name: "/root/folder1/file1.ts" }; + let file1_1: File = { name: "/root/folder1/file1_1/index.d.ts" }; + let file2: File = { name: "/root/generated/folder1/file2.ts" }; + let file3: File = { name: "/root/generated/folder2/file3.ts" }; + const host = createModuleResolutionHost(hasDirectoryExists, file1, file1_1, file2, file3); + const options: CompilerOptions = { + moduleResolution: ModuleResolutionKind.NodeJs, + rootDirs: [ + "/root", + "/root/generated/" + ] + }; + check("./file2", file1, file2, [ + // first try current location + // load from file + "/root/folder1/file2.ts", + "/root/folder1/file2.tsx", + "/root/folder1/file2.d.ts", + // load from folder + "/root/folder1/file2/package.json", + "/root/folder1/file2/index.ts", + "/root/folder1/file2/index.tsx", + "/root/folder1/file2/index.d.ts", + // success after using alternative rootDir entry + ]); + check("../folder1/file1", file3, file1, [ + // first try current location + // load from file + "/root/generated/folder1/file1.ts", + "/root/generated/folder1/file1.tsx", + "/root/generated/folder1/file1.d.ts", + // load from module + "/root/generated/folder1/file1/package.json", + "/root/generated/folder1/file1/index.ts", + "/root/generated/folder1/file1/index.tsx", + "/root/generated/folder1/file1/index.d.ts", + // success after using alternative rootDir entry + ]); + check("../folder1/file1_1", file3, file1_1, [ + // first try current location + // load from file + "/root/generated/folder1/file1_1.ts", + "/root/generated/folder1/file1_1.tsx", + "/root/generated/folder1/file1_1.d.ts", + // load from folder + "/root/generated/folder1/file1_1/package.json", + "/root/generated/folder1/file1_1/index.ts", + "/root/generated/folder1/file1_1/index.tsx", + "/root/generated/folder1/file1_1/index.d.ts", + // try alternative rootDir entry + // load from file + "/root/folder1/file1_1.ts", + "/root/folder1/file1_1.tsx", + "/root/folder1/file1_1.d.ts", + // load from directory + "/root/folder1/file1_1/package.json", + "/root/folder1/file1_1/index.ts", + "/root/folder1/file1_1/index.tsx", + // success on loading '/root/folder1/file1_1/index.d.ts' + ]); + + function check(name: string, container: File, expected: File, expectedFailedLookups: string[]) { + const result = resolveModuleName(name, container.name, options, host); + assert.isTrue(result.resolvedModule !== undefined, "module should be resolved"); + assert.equal(result.resolvedModule.resolvedFileName, expected.name); + assert.deepEqual(result.failedLookupLocations,expectedFailedLookups); + } + } + }); + + it ("classic + rootDirs", () => { test(/*hasDirectoryExists*/ false); test(/*hasDirectoryExists*/ true); @@ -567,39 +818,85 @@ import b = require("./moduleB.ts"); let file1: File = { name: "/root/folder1/file1.ts" }; let file2: File = { name: "/root/generated/folder1/file2.ts" }; let file3: File = { name: "/root/generated/folder2/file3.ts" }; - const host = createModuleResolutionHost(hasDirectoryExists, file1, file2, file3); + let file4: File = { name: "/folder1/file1_1.ts" }; + const host = createModuleResolutionHost(hasDirectoryExists, file1, file2, file3, file4); const options: CompilerOptions = { - moduleResolution: ModuleResolutionKind.BaseUrl, - baseUrl: "/root", - paths: { - "*": [ - "*", - "generated/*" - ] - }, + moduleResolution: ModuleResolutionKind.Classic, rootDirs: [ "/root", "/root/generated/" ] }; - { - const result = baseUrlModuleNameResolver("./file2", file1.name, options, host); + check("./file2", file1, file2, [ + // first load from current location + "/root/folder1/file2.ts", + "/root/folder1/file2.tsx", + "/root/folder1/file2.d.ts", + // then try alternative rootDir entry + ]); + check("../folder1/file1", file3, file1, [ + // first load from current location + "/root/generated/folder1/file1.ts", + "/root/generated/folder1/file1.tsx", + "/root/generated/folder1/file1.d.ts", + // then try alternative rootDir entry + ]); + check("../folder1/file1_1", file3, file4, [ + // load from initial location + "/root/generated/folder1/file1_1.ts", + "/root/generated/folder1/file1_1.tsx", + "/root/generated/folder1/file1_1.d.ts", + // load from alternative rootDir entry + "/root/folder1/file1_1.ts", + "/root/folder1/file1_1.tsx", + "/root/folder1/file1_1.d.ts", + // fallback to classic + // step1: initial location + "/root/generated/folder1/file1_1.ts", + "/root/generated/folder1/file1_1.tsx", + "/root/generated/folder1/file1_1.d.ts", + // step2: walk 1 level up + "/root/folder1/file1_1.ts", + "/root/folder1/file1_1.tsx", + "/root/folder1/file1_1.d.ts", + ]); + + function check(name: string, container: File, expected: File, expectedFailedLookups: string[]) { + const result = resolveModuleName(name, container.name, options, host); assert.isTrue(result.resolvedModule !== undefined, "module should be resolved"); - assert.equal(result.resolvedModule.resolvedFileName, file2.name); - assert.deepEqual(result.failedLookupLocations, [ - "/root/folder1/file2.ts", - "/root/folder1/file2.tsx", - "/root/folder1/file2.d.ts", - ]); - } - { - const result = baseUrlModuleNameResolver("../folder1/file1", file3.name, options, host); - assert.isTrue(result.resolvedModule !== undefined, "module should be resolved"); - assert.equal(result.resolvedModule.resolvedFileName, file1.name); - assert.deepEqual(result.failedLookupLocations, []); + assert.equal(result.resolvedModule.resolvedFileName, expected.name); + assert.deepEqual(result.failedLookupLocations,expectedFailedLookups); } } }); + + it ("nested node module", () => { + test(/*hasDirectoryExists*/ false); + test(/*hasDirectoryExists*/ true); + + function test(hasDirectoryExists: boolean) { + const app: File = { name: "/root/src/app.ts" } + const libsPackage: File = { name: "/root/src/libs/guid/package.json", content: JSON.stringify({ typings: "dist/guid.d.ts" }) }; + const libsTypings: File = { name: "/root/src/libs/guid/dist/guid.d.ts" }; + const host = createModuleResolutionHost(hasDirectoryExists, app, libsPackage, libsTypings); + const options: CompilerOptions = { + moduleResolution: ModuleResolutionKind.NodeJs, + baseUrl: "/root", + paths: { + "libs/guid": [ "src/libs/guid" ] + } + }; + const result = resolveModuleName("libs/guid", app.name, options, host); + assert.isTrue(result.resolvedModule !== undefined, "module should be resolved"); + assert.equal(result.resolvedModule.resolvedFileName, libsTypings.name); + assert.deepEqual(result.failedLookupLocations, [ + // first try to load module as file + "/root/src/libs/guid.ts", + "/root/src/libs/guid.tsx", + "/root/src/libs/guid.d.ts", + ]); + } + }) }); function notImplemented(name: string): () => any {