diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index ba798525e7d7f..0da701e44524c 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -884,6 +884,18 @@ namespace ts { description: Diagnostics.Allow_accessing_UMD_globals_from_modules, defaultValueDescription: false, }, + { + name: "moduleSuffixes", + type: "list", + element: { + name: "suffix", + type: "string", + }, + listPreserveFalsyValues: true, + affectsModuleResolution: true, + category: Diagnostics.Modules, + description: Diagnostics.List_of_file_name_suffixes_to_search_when_resolving_a_module, + }, // Source Maps { @@ -3192,7 +3204,7 @@ namespace ts { if (option.type === "list") { const listOption = option; if (listOption.element.isFilePath || !isString(listOption.element.type)) { - return filter(map(value, v => normalizeOptionValue(listOption.element, basePath, v)), v => !!v) as CompilerOptionsValue; + return filter(map(value, v => normalizeOptionValue(listOption.element, basePath, v)), v => listOption.listPreserveFalsyValues ? true : !!v) as CompilerOptionsValue; } return value; } @@ -3233,7 +3245,7 @@ namespace ts { } function convertJsonOptionOfListType(option: CommandLineOptionOfListType, values: readonly any[], basePath: string, errors: Push): any[] { - return filter(map(values, v => convertJsonOption(option.element, v, basePath, errors)), v => !!v); + return filter(map(values, v => convertJsonOption(option.element, v, basePath, errors)), v => option.listPreserveFalsyValues ? true : !!v); } /** diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index affe89f5b2cb1..358a6bc22841b 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -5862,6 +5862,10 @@ "category": "Message", "code": 6930 }, + "List of file name suffixes to search when resolving a module." : { + "category": "Error", + "code": 6931 + }, "Variable '{0}' implicitly has an '{1}' type.": { "category": "Error", diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index da2324cc74ecb..104223d1e750d 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -1576,6 +1576,16 @@ namespace ts { /** Return the file if it exists. */ function tryFile(fileName: string, onlyRecordFailures: boolean, state: ModuleResolutionState): string | undefined { + if (!state.compilerOptions.moduleSuffixes?.length) { + return tryFileLookup(fileName, onlyRecordFailures, state); + } + + const ext = tryGetExtensionFromPath(fileName) ?? ""; + const fileNameNoExtension = ext ? removeExtension(fileName, ext) : fileName; + return forEach(state.compilerOptions.moduleSuffixes, suffix => tryFileLookup(fileNameNoExtension + suffix + ext, onlyRecordFailures, state)); + } + + function tryFileLookup(fileName: string, onlyRecordFailures: boolean, state: ModuleResolutionState): string | undefined { if (!onlyRecordFailures) { if (state.host.fileExists(fileName)) { if (state.traceEnabled) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 3fee2e6eac415..8b8ababa7ab2d 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -6145,6 +6145,7 @@ namespace ts { maxNodeModuleJsDepth?: number; module?: ModuleKind; moduleResolution?: ModuleResolutionKind; + moduleSuffixes?: string[]; moduleDetection?: ModuleDetectionKind; newLine?: NewLineKind; noEmit?: boolean; @@ -6449,6 +6450,7 @@ namespace ts { export interface CommandLineOptionOfListType extends CommandLineOptionBase { type: "list"; element: CommandLineOptionOfCustomType | CommandLineOptionOfStringType | CommandLineOptionOfNumberType | CommandLineOptionOfBooleanType | TsConfigOnlyOption; + listPreserveFalsyValues?: boolean; } /* @internal */ diff --git a/src/testRunner/unittests/config/convertCompilerOptionsFromJson.ts b/src/testRunner/unittests/config/convertCompilerOptionsFromJson.ts index 96da312068abd..97ae30d24083e 100644 --- a/src/testRunner/unittests/config/convertCompilerOptionsFromJson.ts +++ b/src/testRunner/unittests/config/convertCompilerOptionsFromJson.ts @@ -420,6 +420,70 @@ namespace ts { ); }); + it("Convert empty string option of moduleSuffixes to compiler-options ", () => { + assertCompilerOptions( + { + compilerOptions: { + moduleSuffixes: [".ios", ""] + } + }, "tsconfig.json", + { + compilerOptions: { + moduleSuffixes: [".ios", ""] + }, + errors: [] + } + ); + }); + + it("Convert empty string option of moduleSuffixes to compiler-options ", () => { + assertCompilerOptions( + { + compilerOptions: { + moduleSuffixes: [""] + } + }, "tsconfig.json", + { + compilerOptions: { + moduleSuffixes: [""] + }, + errors: [] + } + ); + }); + + it("Convert trailing-whitespace string option of moduleSuffixes to compiler-options ", () => { + assertCompilerOptions( + { + compilerOptions: { + moduleSuffixes: [" "] + } + }, "tsconfig.json", + { + compilerOptions: { + moduleSuffixes: [" "] + }, + errors: [] + } + ); + }); + + it("Convert empty option of moduleSuffixes to compiler-options ", () => { + assertCompilerOptions( + { + compilerOptions: { + moduleSuffixes: [] + } + }, "tsconfig.json", + { + compilerOptions: { + moduleSuffixes: [] + }, + errors: [] + } + ); + }); + it("Convert incorrectly format tsconfig.json to compiler-options ", () => { assertCompilerOptions( { diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index fcb78f56f6cc0..4fe899b787795 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -2973,6 +2973,7 @@ declare namespace ts { maxNodeModuleJsDepth?: number; module?: ModuleKind; moduleResolution?: ModuleResolutionKind; + moduleSuffixes?: string[]; moduleDetection?: ModuleDetectionKind; newLine?: NewLineKind; noEmit?: boolean; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index e78e7d779b831..b73ea512688c4 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -2973,6 +2973,7 @@ declare namespace ts { maxNodeModuleJsDepth?: number; module?: ModuleKind; moduleResolution?: ModuleResolutionKind; + moduleSuffixes?: string[]; moduleDetection?: ModuleDetectionKind; newLine?: NewLineKind; noEmit?: boolean; diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_empty.js b/tests/baselines/reference/moduleResolutionWithSuffixes_empty.js new file mode 100644 index 0000000000000..3cbbfd72b8a51 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_empty.js @@ -0,0 +1,17 @@ +//// [tests/cases/compiler/moduleResolutionWithSuffixes_empty.ts] //// + +//// [index.ts] +import { base } from "./foo"; +//// [foo.ts] +export function base() {} + + +//// [foo.js] +"use strict"; +exports.__esModule = true; +exports.base = void 0; +function base() { } +exports.base = base; +//// [index.js] +"use strict"; +exports.__esModule = true; diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_empty.symbols b/tests/baselines/reference/moduleResolutionWithSuffixes_empty.symbols new file mode 100644 index 0000000000000..d4bcb87477b14 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_empty.symbols @@ -0,0 +1,8 @@ +=== /index.ts === +import { base } from "./foo"; +>base : Symbol(base, Decl(index.ts, 0, 8)) + +=== /foo.ts === +export function base() {} +>base : Symbol(base, Decl(foo.ts, 0, 0)) + diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_empty.trace.json b/tests/baselines/reference/moduleResolutionWithSuffixes_empty.trace.json new file mode 100644 index 0000000000000..c1e5657623ecc --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_empty.trace.json @@ -0,0 +1,7 @@ +[ + "======== Resolving module './foo' from '/index.ts'. ========", + "Explicitly specified module resolution kind: 'NodeJs'.", + "Loading module as file / folder, candidate module location '/foo', target file type 'TypeScript'.", + "File '/foo.ts' exist - use it as a name resolution result.", + "======== Module name './foo' was successfully resolved to '/foo.ts'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_empty.types b/tests/baselines/reference/moduleResolutionWithSuffixes_empty.types new file mode 100644 index 0000000000000..90f587bf346ed --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_empty.types @@ -0,0 +1,8 @@ +=== /index.ts === +import { base } from "./foo"; +>base : () => void + +=== /foo.ts === +export function base() {} +>base : () => void + diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_notSpecified.js b/tests/baselines/reference/moduleResolutionWithSuffixes_notSpecified.js new file mode 100644 index 0000000000000..13faeda2fe5a4 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_notSpecified.js @@ -0,0 +1,17 @@ +//// [tests/cases/compiler/moduleResolutionWithSuffixes_notSpecified.ts] //// + +//// [index.ts] +import { base } from "./foo"; +//// [foo.ts] +export function base() {} + + +//// [foo.js] +"use strict"; +exports.__esModule = true; +exports.base = void 0; +function base() { } +exports.base = base; +//// [index.js] +"use strict"; +exports.__esModule = true; diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_notSpecified.symbols b/tests/baselines/reference/moduleResolutionWithSuffixes_notSpecified.symbols new file mode 100644 index 0000000000000..d4bcb87477b14 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_notSpecified.symbols @@ -0,0 +1,8 @@ +=== /index.ts === +import { base } from "./foo"; +>base : Symbol(base, Decl(index.ts, 0, 8)) + +=== /foo.ts === +export function base() {} +>base : Symbol(base, Decl(foo.ts, 0, 0)) + diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_notSpecified.trace.json b/tests/baselines/reference/moduleResolutionWithSuffixes_notSpecified.trace.json new file mode 100644 index 0000000000000..c1e5657623ecc --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_notSpecified.trace.json @@ -0,0 +1,7 @@ +[ + "======== Resolving module './foo' from '/index.ts'. ========", + "Explicitly specified module resolution kind: 'NodeJs'.", + "Loading module as file / folder, candidate module location '/foo', target file type 'TypeScript'.", + "File '/foo.ts' exist - use it as a name resolution result.", + "======== Module name './foo' was successfully resolved to '/foo.ts'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_notSpecified.types b/tests/baselines/reference/moduleResolutionWithSuffixes_notSpecified.types new file mode 100644 index 0000000000000..90f587bf346ed --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_notSpecified.types @@ -0,0 +1,8 @@ +=== /index.ts === +import { base } from "./foo"; +>base : () => void + +=== /foo.ts === +export function base() {} +>base : () => void + diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_one.js b/tests/baselines/reference/moduleResolutionWithSuffixes_one.js new file mode 100644 index 0000000000000..d925ba38f0c5f --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_one.js @@ -0,0 +1,25 @@ +//// [tests/cases/compiler/moduleResolutionWithSuffixes_one.ts] //// + +//// [index.ts] +import { ios } from "./foo"; +//// [foo.ios.ts] +export function ios() {} +//// [foo.ts] +export function base() {} + + +//// [foo.ios.js] +"use strict"; +exports.__esModule = true; +exports.ios = void 0; +function ios() { } +exports.ios = ios; +//// [index.js] +"use strict"; +exports.__esModule = true; +//// [foo.js] +"use strict"; +exports.__esModule = true; +exports.base = void 0; +function base() { } +exports.base = base; diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_one.symbols b/tests/baselines/reference/moduleResolutionWithSuffixes_one.symbols new file mode 100644 index 0000000000000..a029c1194aa72 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_one.symbols @@ -0,0 +1,12 @@ +=== /index.ts === +import { ios } from "./foo"; +>ios : Symbol(ios, Decl(index.ts, 0, 8)) + +=== /foo.ios.ts === +export function ios() {} +>ios : Symbol(ios, Decl(foo.ios.ts, 0, 0)) + +=== /foo.ts === +export function base() {} +>base : Symbol(base, Decl(foo.ts, 0, 0)) + diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_one.trace.json b/tests/baselines/reference/moduleResolutionWithSuffixes_one.trace.json new file mode 100644 index 0000000000000..92259211af165 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_one.trace.json @@ -0,0 +1,7 @@ +[ + "======== Resolving module './foo' from '/index.ts'. ========", + "Explicitly specified module resolution kind: 'NodeJs'.", + "Loading module as file / folder, candidate module location '/foo', target file type 'TypeScript'.", + "File '/foo.ios.ts' exist - use it as a name resolution result.", + "======== Module name './foo' was successfully resolved to '/foo.ios.ts'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_one.types b/tests/baselines/reference/moduleResolutionWithSuffixes_one.types new file mode 100644 index 0000000000000..3fd45bed21c0a --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_one.types @@ -0,0 +1,12 @@ +=== /index.ts === +import { ios } from "./foo"; +>ios : () => void + +=== /foo.ios.ts === +export function ios() {} +>ios : () => void + +=== /foo.ts === +export function base() {} +>base : () => void + diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_oneBlank.js b/tests/baselines/reference/moduleResolutionWithSuffixes_oneBlank.js new file mode 100644 index 0000000000000..5844ef8e448b4 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_oneBlank.js @@ -0,0 +1,17 @@ +//// [tests/cases/compiler/moduleResolutionWithSuffixes_oneBlank.ts] //// + +//// [index.ts] +import { base } from "./foo"; +//// [foo.ts] +export function base() {} + + +//// [foo.js] +"use strict"; +exports.__esModule = true; +exports.base = void 0; +function base() { } +exports.base = base; +//// [index.js] +"use strict"; +exports.__esModule = true; diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_oneBlank.symbols b/tests/baselines/reference/moduleResolutionWithSuffixes_oneBlank.symbols new file mode 100644 index 0000000000000..d4bcb87477b14 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_oneBlank.symbols @@ -0,0 +1,8 @@ +=== /index.ts === +import { base } from "./foo"; +>base : Symbol(base, Decl(index.ts, 0, 8)) + +=== /foo.ts === +export function base() {} +>base : Symbol(base, Decl(foo.ts, 0, 0)) + diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_oneBlank.trace.json b/tests/baselines/reference/moduleResolutionWithSuffixes_oneBlank.trace.json new file mode 100644 index 0000000000000..c1e5657623ecc --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_oneBlank.trace.json @@ -0,0 +1,7 @@ +[ + "======== Resolving module './foo' from '/index.ts'. ========", + "Explicitly specified module resolution kind: 'NodeJs'.", + "Loading module as file / folder, candidate module location '/foo', target file type 'TypeScript'.", + "File '/foo.ts' exist - use it as a name resolution result.", + "======== Module name './foo' was successfully resolved to '/foo.ts'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_oneBlank.types b/tests/baselines/reference/moduleResolutionWithSuffixes_oneBlank.types new file mode 100644 index 0000000000000..90f587bf346ed --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_oneBlank.types @@ -0,0 +1,8 @@ +=== /index.ts === +import { base } from "./foo"; +>base : () => void + +=== /foo.ts === +export function base() {} +>base : () => void + diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_oneNotFound.errors.txt b/tests/baselines/reference/moduleResolutionWithSuffixes_oneNotFound.errors.txt new file mode 100644 index 0000000000000..c1d547209ae49 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_oneNotFound.errors.txt @@ -0,0 +1,21 @@ +/index.ts(1,21): error TS2307: Cannot find module './foo' or its corresponding type declarations. + + +==== /tsconfig.json (0 errors) ==== + // moduleSuffixes has one entry but there isn't a matching file. Module resolution should fail. + + { + "compilerOptions": { + "moduleResolution": "node", + "traceResolution": true, + "moduleSuffixes": [".ios"] + } + } + +==== /index.ts (1 errors) ==== + import { ios } from "./foo"; + ~~~~~~~ +!!! error TS2307: Cannot find module './foo' or its corresponding type declarations. +==== /foo.ts (0 errors) ==== + export function base() {} + \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_oneNotFound.js b/tests/baselines/reference/moduleResolutionWithSuffixes_oneNotFound.js new file mode 100644 index 0000000000000..39dc2d0737fc2 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_oneNotFound.js @@ -0,0 +1,17 @@ +//// [tests/cases/compiler/moduleResolutionWithSuffixes_oneNotFound.ts] //// + +//// [index.ts] +import { ios } from "./foo"; +//// [foo.ts] +export function base() {} + + +//// [index.js] +"use strict"; +exports.__esModule = true; +//// [foo.js] +"use strict"; +exports.__esModule = true; +exports.base = void 0; +function base() { } +exports.base = base; diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_oneNotFound.symbols b/tests/baselines/reference/moduleResolutionWithSuffixes_oneNotFound.symbols new file mode 100644 index 0000000000000..538ebe6e5637a --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_oneNotFound.symbols @@ -0,0 +1,8 @@ +=== /index.ts === +import { ios } from "./foo"; +>ios : Symbol(ios, Decl(index.ts, 0, 8)) + +=== /foo.ts === +export function base() {} +>base : Symbol(base, Decl(foo.ts, 0, 0)) + diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_oneNotFound.trace.json b/tests/baselines/reference/moduleResolutionWithSuffixes_oneNotFound.trace.json new file mode 100644 index 0000000000000..c0bf8c1d4367e --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_oneNotFound.trace.json @@ -0,0 +1,14 @@ +[ + "======== Resolving module './foo' from '/index.ts'. ========", + "Explicitly specified module resolution kind: 'NodeJs'.", + "Loading module as file / folder, candidate module location '/foo', target file type 'TypeScript'.", + "File '/foo.ios.ts' does not exist.", + "File '/foo.ios.tsx' does not exist.", + "File '/foo.ios.d.ts' does not exist.", + "Directory '/foo' does not exist, skipping all lookups in it.", + "Loading module as file / folder, candidate module location '/foo', target file type 'JavaScript'.", + "File '/foo.ios.js' does not exist.", + "File '/foo.ios.jsx' does not exist.", + "Directory '/foo' does not exist, skipping all lookups in it.", + "======== Module name './foo' was not resolved. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_oneNotFound.types b/tests/baselines/reference/moduleResolutionWithSuffixes_oneNotFound.types new file mode 100644 index 0000000000000..78c180ec11557 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_oneNotFound.types @@ -0,0 +1,8 @@ +=== /index.ts === +import { ios } from "./foo"; +>ios : any + +=== /foo.ts === +export function base() {} +>base : () => void + diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_one_dirModuleWithIndex.js b/tests/baselines/reference/moduleResolutionWithSuffixes_one_dirModuleWithIndex.js new file mode 100644 index 0000000000000..7c5504416056a --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_one_dirModuleWithIndex.js @@ -0,0 +1,24 @@ +//// [tests/cases/compiler/moduleResolutionWithSuffixes_one_dirModuleWithIndex.ts] //// + +//// [index.ts] +import { ios } from "./foo"; +//// [index.ios.ts] +export function ios() {} +//// [index.ts] +export function base() {} + +//// [index.ios.js] +"use strict"; +exports.__esModule = true; +exports.ios = void 0; +function ios() { } +exports.ios = ios; +//// [index.js] +"use strict"; +exports.__esModule = true; +//// [index.js] +"use strict"; +exports.__esModule = true; +exports.base = void 0; +function base() { } +exports.base = base; diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_one_dirModuleWithIndex.symbols b/tests/baselines/reference/moduleResolutionWithSuffixes_one_dirModuleWithIndex.symbols new file mode 100644 index 0000000000000..c83274be2e88c --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_one_dirModuleWithIndex.symbols @@ -0,0 +1,12 @@ +=== /index.ts === +import { ios } from "./foo"; +>ios : Symbol(ios, Decl(index.ts, 0, 8)) + +=== /foo/index.ios.ts === +export function ios() {} +>ios : Symbol(ios, Decl(index.ios.ts, 0, 0)) + +=== /foo/index.ts === +export function base() {} +>base : Symbol(base, Decl(index.ts, 0, 0)) + diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_one_dirModuleWithIndex.trace.json b/tests/baselines/reference/moduleResolutionWithSuffixes_one_dirModuleWithIndex.trace.json new file mode 100644 index 0000000000000..ec663458f8e72 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_one_dirModuleWithIndex.trace.json @@ -0,0 +1,11 @@ +[ + "======== Resolving module './foo' from '/index.ts'. ========", + "Explicitly specified module resolution kind: 'NodeJs'.", + "Loading module as file / folder, candidate module location '/foo', target file type 'TypeScript'.", + "File '/foo.ios.ts' does not exist.", + "File '/foo.ios.tsx' does not exist.", + "File '/foo.ios.d.ts' does not exist.", + "File '/foo/package.json' does not exist.", + "File '/foo/index.ios.ts' exist - use it as a name resolution result.", + "======== Module name './foo' was successfully resolved to '/foo/index.ios.ts'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_one_dirModuleWithIndex.types b/tests/baselines/reference/moduleResolutionWithSuffixes_one_dirModuleWithIndex.types new file mode 100644 index 0000000000000..2fac3e926519c --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_one_dirModuleWithIndex.types @@ -0,0 +1,12 @@ +=== /index.ts === +import { ios } from "./foo"; +>ios : () => void + +=== /foo/index.ios.ts === +export function ios() {} +>ios : () => void + +=== /foo/index.ts === +export function base() {} +>base : () => void + diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModule.js b/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModule.js new file mode 100644 index 0000000000000..f8505073a5d3c --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModule.js @@ -0,0 +1,34 @@ +//// [tests/cases/compiler/moduleResolutionWithSuffixes_one_externalModule.ts] //// + +//// [index.ios.js] +"use strict"; +exports.__esModule = true; +function ios() {} +exports.ios = ios; +//// [index.ios.d.ts] +export declare function ios(): void; +//// [index.js] +"use strict"; +exports.__esModule = true; +function base() {} +exports.base = base; +//// [index.d.ts] +export declare function base(): void; + +//// [index.ts] +import { ios } from "some-library"; + + +//// [/bin/node_modules/some-library/index.ios.js] +"use strict"; +exports.__esModule = true; +function ios() { } +exports.ios = ios; +//// [/bin/node_modules/some-library/index.js] +"use strict"; +exports.__esModule = true; +function base() { } +exports.base = base; +//// [/bin/index.js] +"use strict"; +exports.__esModule = true; diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModule.symbols b/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModule.symbols new file mode 100644 index 0000000000000..e838c8d7ee177 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModule.symbols @@ -0,0 +1,44 @@ +=== /node_modules/some-library/index.ios.js === +"use strict"; +exports.__esModule = true; +>exports.__esModule : Symbol(__esModule, Decl(index.ios.js, 0, 13)) +>exports : Symbol(__esModule, Decl(index.ios.js, 0, 13)) +>__esModule : Symbol(__esModule, Decl(index.ios.js, 0, 13)) + +function ios() {} +>ios : Symbol(ios, Decl(index.ios.js, 1, 26)) + +exports.ios = ios; +>exports.ios : Symbol(ios, Decl(index.ios.js, 2, 17)) +>exports : Symbol(ios, Decl(index.ios.js, 2, 17)) +>ios : Symbol(ios, Decl(index.ios.js, 2, 17)) +>ios : Symbol(ios, Decl(index.ios.js, 1, 26)) + +=== /node_modules/some-library/index.ios.d.ts === +export declare function ios(): void; +>ios : Symbol(ios, Decl(index.ios.d.ts, 0, 0)) + +=== /node_modules/some-library/index.js === +"use strict"; +exports.__esModule = true; +>exports.__esModule : Symbol(__esModule, Decl(index.js, 0, 13)) +>exports : Symbol(__esModule, Decl(index.js, 0, 13)) +>__esModule : Symbol(__esModule, Decl(index.js, 0, 13)) + +function base() {} +>base : Symbol(base, Decl(index.js, 1, 26)) + +exports.base = base; +>exports.base : Symbol(base, Decl(index.js, 2, 18)) +>exports : Symbol(base, Decl(index.js, 2, 18)) +>base : Symbol(base, Decl(index.js, 2, 18)) +>base : Symbol(base, Decl(index.js, 1, 26)) + +=== /node_modules/some-library/index.d.ts === +export declare function base(): void; +>base : Symbol(base, Decl(index.d.ts, 0, 0)) + +=== /index.ts === +import { ios } from "some-library"; +>ios : Symbol(ios, Decl(index.ts, 0, 8)) + diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModule.trace.json b/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModule.trace.json new file mode 100644 index 0000000000000..d79615de72961 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModule.trace.json @@ -0,0 +1,14 @@ +[ + "======== Resolving module 'some-library' from '/index.ts'. ========", + "Explicitly specified module resolution kind: 'NodeJs'.", + "Loading module 'some-library' from 'node_modules' folder, target file type 'TypeScript'.", + "File '/node_modules/some-library/package.json' does not exist.", + "File '/node_modules/some-library.ios.ts' does not exist.", + "File '/node_modules/some-library.ios.tsx' does not exist.", + "File '/node_modules/some-library.ios.d.ts' does not exist.", + "File '/node_modules/some-library/index.ios.ts' does not exist.", + "File '/node_modules/some-library/index.ios.tsx' does not exist.", + "File '/node_modules/some-library/index.ios.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/node_modules/some-library/index.ios.d.ts', result '/node_modules/some-library/index.ios.d.ts'.", + "======== Module name 'some-library' was successfully resolved to '/node_modules/some-library/index.ios.d.ts'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModule.types b/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModule.types new file mode 100644 index 0000000000000..dd19f789448b5 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModule.types @@ -0,0 +1,54 @@ +=== /node_modules/some-library/index.ios.js === +"use strict"; +>"use strict" : "use strict" + +exports.__esModule = true; +>exports.__esModule = true : true +>exports.__esModule : true +>exports : typeof import("/node_modules/some-library/index.ios") +>__esModule : true +>true : true + +function ios() {} +>ios : () => void + +exports.ios = ios; +>exports.ios = ios : () => void +>exports.ios : () => void +>exports : typeof import("/node_modules/some-library/index.ios") +>ios : () => void +>ios : () => void + +=== /node_modules/some-library/index.ios.d.ts === +export declare function ios(): void; +>ios : () => void + +=== /node_modules/some-library/index.js === +"use strict"; +>"use strict" : "use strict" + +exports.__esModule = true; +>exports.__esModule = true : true +>exports.__esModule : true +>exports : typeof import("/node_modules/some-library/index") +>__esModule : true +>true : true + +function base() {} +>base : () => void + +exports.base = base; +>exports.base = base : () => void +>exports.base : () => void +>exports : typeof import("/node_modules/some-library/index") +>base : () => void +>base : () => void + +=== /node_modules/some-library/index.d.ts === +export declare function base(): void; +>base : () => void + +=== /index.ts === +import { ios } from "some-library"; +>ios : () => void + diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModulePath.js b/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModulePath.js new file mode 100644 index 0000000000000..55d8b3681a5cb --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModulePath.js @@ -0,0 +1,34 @@ +//// [tests/cases/compiler/moduleResolutionWithSuffixes_one_externalModulePath.ts] //// + +//// [foo.ios.js] +"use strict"; +exports.__esModule = true; +function iosfoo() {} +exports.iosfoo = iosfoo; +//// [foo.ios.d.ts] +export declare function iosfoo(): void; +//// [foo.js] +"use strict"; +exports.__esModule = true; +function basefoo() {} +exports.basefoo = basefoo; +//// [foo.d.ts] +export declare function basefoo(): void; + +//// [index.ts] +import { iosfoo } from "some-library/foo"; + + +//// [/bin/node_modules/some-library/foo.ios.js] +"use strict"; +exports.__esModule = true; +function iosfoo() { } +exports.iosfoo = iosfoo; +//// [/bin/node_modules/some-library/foo.js] +"use strict"; +exports.__esModule = true; +function basefoo() { } +exports.basefoo = basefoo; +//// [/bin/index.js] +"use strict"; +exports.__esModule = true; diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModulePath.symbols b/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModulePath.symbols new file mode 100644 index 0000000000000..8048c1df6689a --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModulePath.symbols @@ -0,0 +1,44 @@ +=== /node_modules/some-library/foo.ios.js === +"use strict"; +exports.__esModule = true; +>exports.__esModule : Symbol(__esModule, Decl(foo.ios.js, 0, 13)) +>exports : Symbol(__esModule, Decl(foo.ios.js, 0, 13)) +>__esModule : Symbol(__esModule, Decl(foo.ios.js, 0, 13)) + +function iosfoo() {} +>iosfoo : Symbol(iosfoo, Decl(foo.ios.js, 1, 26)) + +exports.iosfoo = iosfoo; +>exports.iosfoo : Symbol(iosfoo, Decl(foo.ios.js, 2, 20)) +>exports : Symbol(iosfoo, Decl(foo.ios.js, 2, 20)) +>iosfoo : Symbol(iosfoo, Decl(foo.ios.js, 2, 20)) +>iosfoo : Symbol(iosfoo, Decl(foo.ios.js, 1, 26)) + +=== /node_modules/some-library/foo.ios.d.ts === +export declare function iosfoo(): void; +>iosfoo : Symbol(iosfoo, Decl(foo.ios.d.ts, 0, 0)) + +=== /node_modules/some-library/foo.js === +"use strict"; +exports.__esModule = true; +>exports.__esModule : Symbol(__esModule, Decl(foo.js, 0, 13)) +>exports : Symbol(__esModule, Decl(foo.js, 0, 13)) +>__esModule : Symbol(__esModule, Decl(foo.js, 0, 13)) + +function basefoo() {} +>basefoo : Symbol(basefoo, Decl(foo.js, 1, 26)) + +exports.basefoo = basefoo; +>exports.basefoo : Symbol(basefoo, Decl(foo.js, 2, 21)) +>exports : Symbol(basefoo, Decl(foo.js, 2, 21)) +>basefoo : Symbol(basefoo, Decl(foo.js, 2, 21)) +>basefoo : Symbol(basefoo, Decl(foo.js, 1, 26)) + +=== /node_modules/some-library/foo.d.ts === +export declare function basefoo(): void; +>basefoo : Symbol(basefoo, Decl(foo.d.ts, 0, 0)) + +=== /index.ts === +import { iosfoo } from "some-library/foo"; +>iosfoo : Symbol(iosfoo, Decl(index.ts, 0, 8)) + diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModulePath.trace.json b/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModulePath.trace.json new file mode 100644 index 0000000000000..3a7c320e60a15 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModulePath.trace.json @@ -0,0 +1,11 @@ +[ + "======== Resolving module 'some-library/foo' from '/index.ts'. ========", + "Explicitly specified module resolution kind: 'NodeJs'.", + "Loading module 'some-library/foo' from 'node_modules' folder, target file type 'TypeScript'.", + "File '/node_modules/some-library/package.json' does not exist.", + "File '/node_modules/some-library/foo.ios.ts' does not exist.", + "File '/node_modules/some-library/foo.ios.tsx' does not exist.", + "File '/node_modules/some-library/foo.ios.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/node_modules/some-library/foo.ios.d.ts', result '/node_modules/some-library/foo.ios.d.ts'.", + "======== Module name 'some-library/foo' was successfully resolved to '/node_modules/some-library/foo.ios.d.ts'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModulePath.types b/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModulePath.types new file mode 100644 index 0000000000000..686966864eb5b --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModulePath.types @@ -0,0 +1,54 @@ +=== /node_modules/some-library/foo.ios.js === +"use strict"; +>"use strict" : "use strict" + +exports.__esModule = true; +>exports.__esModule = true : true +>exports.__esModule : true +>exports : typeof import("/node_modules/some-library/foo.ios") +>__esModule : true +>true : true + +function iosfoo() {} +>iosfoo : () => void + +exports.iosfoo = iosfoo; +>exports.iosfoo = iosfoo : () => void +>exports.iosfoo : () => void +>exports : typeof import("/node_modules/some-library/foo.ios") +>iosfoo : () => void +>iosfoo : () => void + +=== /node_modules/some-library/foo.ios.d.ts === +export declare function iosfoo(): void; +>iosfoo : () => void + +=== /node_modules/some-library/foo.js === +"use strict"; +>"use strict" : "use strict" + +exports.__esModule = true; +>exports.__esModule = true : true +>exports.__esModule : true +>exports : typeof import("/node_modules/some-library/foo") +>__esModule : true +>true : true + +function basefoo() {} +>basefoo : () => void + +exports.basefoo = basefoo; +>exports.basefoo = basefoo : () => void +>exports.basefoo : () => void +>exports : typeof import("/node_modules/some-library/foo") +>basefoo : () => void +>basefoo : () => void + +=== /node_modules/some-library/foo.d.ts === +export declare function basefoo(): void; +>basefoo : () => void + +=== /index.ts === +import { iosfoo } from "some-library/foo"; +>iosfoo : () => void + diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModule_withPaths.js b/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModule_withPaths.js new file mode 100644 index 0000000000000..4672bf88ee66b --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModule_withPaths.js @@ -0,0 +1,36 @@ +//// [tests/cases/compiler/moduleResolutionWithSuffixes_one_externalModule_withPaths.ts] //// + +//// [index.ios.js] +"use strict"; +exports.__esModule = true; +function ios() {} +exports.ios = ios; +//// [index.ios.d.ts] +export declare function ios(): void; +//// [index.js] +"use strict"; +exports.__esModule = true; +function base() {} +exports.base = base; +//// [index.d.ts] +export declare function base(): void; + +//// [test.ts] +import { ios } from "some-library"; +import { ios as ios2 } from "some-library/index"; +import { ios as ios3 } from "some-library/index.js"; + + +//// [/bin/node_modules/some-library/lib/index.ios.js] +"use strict"; +exports.__esModule = true; +function ios() { } +exports.ios = ios; +//// [/bin/node_modules/some-library/lib/index.js] +"use strict"; +exports.__esModule = true; +function base() { } +exports.base = base; +//// [/bin/test.js] +"use strict"; +exports.__esModule = true; diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModule_withPaths.symbols b/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModule_withPaths.symbols new file mode 100644 index 0000000000000..131cc1ee66611 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModule_withPaths.symbols @@ -0,0 +1,52 @@ +=== /node_modules/some-library/lib/index.ios.js === +"use strict"; +exports.__esModule = true; +>exports.__esModule : Symbol(__esModule, Decl(index.ios.js, 0, 13)) +>exports : Symbol(__esModule, Decl(index.ios.js, 0, 13)) +>__esModule : Symbol(__esModule, Decl(index.ios.js, 0, 13)) + +function ios() {} +>ios : Symbol(ios, Decl(index.ios.js, 1, 26)) + +exports.ios = ios; +>exports.ios : Symbol(ios, Decl(index.ios.js, 2, 17)) +>exports : Symbol(ios, Decl(index.ios.js, 2, 17)) +>ios : Symbol(ios, Decl(index.ios.js, 2, 17)) +>ios : Symbol(ios, Decl(index.ios.js, 1, 26)) + +=== /node_modules/some-library/lib/index.ios.d.ts === +export declare function ios(): void; +>ios : Symbol(ios, Decl(index.ios.d.ts, 0, 0)) + +=== /node_modules/some-library/lib/index.js === +"use strict"; +exports.__esModule = true; +>exports.__esModule : Symbol(__esModule, Decl(index.js, 0, 13)) +>exports : Symbol(__esModule, Decl(index.js, 0, 13)) +>__esModule : Symbol(__esModule, Decl(index.js, 0, 13)) + +function base() {} +>base : Symbol(base, Decl(index.js, 1, 26)) + +exports.base = base; +>exports.base : Symbol(base, Decl(index.js, 2, 18)) +>exports : Symbol(base, Decl(index.js, 2, 18)) +>base : Symbol(base, Decl(index.js, 2, 18)) +>base : Symbol(base, Decl(index.js, 1, 26)) + +=== /node_modules/some-library/lib/index.d.ts === +export declare function base(): void; +>base : Symbol(base, Decl(index.d.ts, 0, 0)) + +=== /test.ts === +import { ios } from "some-library"; +>ios : Symbol(ios, Decl(test.ts, 0, 8)) + +import { ios as ios2 } from "some-library/index"; +>ios : Symbol(ios, Decl(index.ios.d.ts, 0, 0)) +>ios2 : Symbol(ios2, Decl(test.ts, 1, 8)) + +import { ios as ios3 } from "some-library/index.js"; +>ios : Symbol(ios, Decl(index.ios.d.ts, 0, 0)) +>ios3 : Symbol(ios3, Decl(test.ts, 2, 8)) + diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModule_withPaths.trace.json b/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModule_withPaths.trace.json new file mode 100644 index 0000000000000..bb8df8b026651 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModule_withPaths.trace.json @@ -0,0 +1,45 @@ +[ + "======== Resolving module 'some-library' from '/test.ts'. ========", + "Explicitly specified module resolution kind: 'NodeJs'.", + "'baseUrl' option is set to '/', using this value to resolve non-relative module name 'some-library'.", + "'paths' option is specified, looking for a pattern to match module name 'some-library'.", + "Module name 'some-library', matched pattern 'some-library'.", + "Trying substitution 'node_modules/some-library/lib', candidate module location: 'node_modules/some-library/lib'.", + "Loading module as file / folder, candidate module location '/node_modules/some-library/lib', target file type 'TypeScript'.", + "File '/node_modules/some-library/lib.ios.ts' does not exist.", + "File '/node_modules/some-library/lib.ios.tsx' does not exist.", + "File '/node_modules/some-library/lib.ios.d.ts' does not exist.", + "File '/node_modules/some-library/lib/package.json' does not exist.", + "File '/node_modules/some-library/lib/index.ios.ts' does not exist.", + "File '/node_modules/some-library/lib/index.ios.tsx' does not exist.", + "File '/node_modules/some-library/lib/index.ios.d.ts' exist - use it as a name resolution result.", + "======== Module name 'some-library' was successfully resolved to '/node_modules/some-library/lib/index.ios.d.ts'. ========", + "======== Resolving module 'some-library/index' from '/test.ts'. ========", + "Explicitly specified module resolution kind: 'NodeJs'.", + "'baseUrl' option is set to '/', using this value to resolve non-relative module name 'some-library/index'.", + "'paths' option is specified, looking for a pattern to match module name 'some-library/index'.", + "Module name 'some-library/index', matched pattern 'some-library/*'.", + "Trying substitution 'node_modules/some-library/lib/*', candidate module location: 'node_modules/some-library/lib/index'.", + "Loading module as file / folder, candidate module location '/node_modules/some-library/lib/index', target file type 'TypeScript'.", + "File '/node_modules/some-library/lib/index.ios.ts' does not exist.", + "File '/node_modules/some-library/lib/index.ios.tsx' does not exist.", + "File '/node_modules/some-library/lib/index.ios.d.ts' exist - use it as a name resolution result.", + "File '/node_modules/some-library/package.json' does not exist.", + "======== Module name 'some-library/index' was successfully resolved to '/node_modules/some-library/lib/index.ios.d.ts'. ========", + "======== Resolving module 'some-library/index.js' from '/test.ts'. ========", + "Explicitly specified module resolution kind: 'NodeJs'.", + "'baseUrl' option is set to '/', using this value to resolve non-relative module name 'some-library/index.js'.", + "'paths' option is specified, looking for a pattern to match module name 'some-library/index.js'.", + "Module name 'some-library/index.js', matched pattern 'some-library/*'.", + "Trying substitution 'node_modules/some-library/lib/*', candidate module location: 'node_modules/some-library/lib/index.js'.", + "Loading module as file / folder, candidate module location '/node_modules/some-library/lib/index.js', target file type 'TypeScript'.", + "File '/node_modules/some-library/lib/index.js.ios.ts' does not exist.", + "File '/node_modules/some-library/lib/index.js.ios.tsx' does not exist.", + "File '/node_modules/some-library/lib/index.js.ios.d.ts' does not exist.", + "File name '/node_modules/some-library/lib/index.js' has a '.js' extension - stripping it.", + "File '/node_modules/some-library/lib/index.ios.ts' does not exist.", + "File '/node_modules/some-library/lib/index.ios.tsx' does not exist.", + "File '/node_modules/some-library/lib/index.ios.d.ts' exist - use it as a name resolution result.", + "File '/node_modules/some-library/package.json' does not exist according to earlier cached lookups.", + "======== Module name 'some-library/index.js' was successfully resolved to '/node_modules/some-library/lib/index.ios.d.ts'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModule_withPaths.types b/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModule_withPaths.types new file mode 100644 index 0000000000000..0084ba275629f --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModule_withPaths.types @@ -0,0 +1,62 @@ +=== /node_modules/some-library/lib/index.ios.js === +"use strict"; +>"use strict" : "use strict" + +exports.__esModule = true; +>exports.__esModule = true : true +>exports.__esModule : true +>exports : typeof import("/node_modules/some-library/lib/index.ios") +>__esModule : true +>true : true + +function ios() {} +>ios : () => void + +exports.ios = ios; +>exports.ios = ios : () => void +>exports.ios : () => void +>exports : typeof import("/node_modules/some-library/lib/index.ios") +>ios : () => void +>ios : () => void + +=== /node_modules/some-library/lib/index.ios.d.ts === +export declare function ios(): void; +>ios : () => void + +=== /node_modules/some-library/lib/index.js === +"use strict"; +>"use strict" : "use strict" + +exports.__esModule = true; +>exports.__esModule = true : true +>exports.__esModule : true +>exports : typeof import("/node_modules/some-library/lib/index") +>__esModule : true +>true : true + +function base() {} +>base : () => void + +exports.base = base; +>exports.base = base : () => void +>exports.base : () => void +>exports : typeof import("/node_modules/some-library/lib/index") +>base : () => void +>base : () => void + +=== /node_modules/some-library/lib/index.d.ts === +export declare function base(): void; +>base : () => void + +=== /test.ts === +import { ios } from "some-library"; +>ios : () => void + +import { ios as ios2 } from "some-library/index"; +>ios : () => void +>ios2 : () => void + +import { ios as ios3 } from "some-library/index.js"; +>ios : () => void +>ios3 : () => void + diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalTSModule.js b/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalTSModule.js new file mode 100644 index 0000000000000..a64c88b037b7b --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalTSModule.js @@ -0,0 +1,25 @@ +//// [tests/cases/compiler/moduleResolutionWithSuffixes_one_externalTSModule.ts] //// + +//// [index.ios.ts] +export function ios() {} +//// [index.ts] +export function base() {} +//// [test.ts] +import { ios } from "some-library"; + + +//// [/bin/node_modules/some-library/index.ios.js] +"use strict"; +exports.__esModule = true; +exports.ios = void 0; +function ios() { } +exports.ios = ios; +//// [/bin/node_modules/some-library/index.js] +"use strict"; +exports.__esModule = true; +exports.base = void 0; +function base() { } +exports.base = base; +//// [/bin/test.js] +"use strict"; +exports.__esModule = true; diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalTSModule.symbols b/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalTSModule.symbols new file mode 100644 index 0000000000000..b101667d604e3 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalTSModule.symbols @@ -0,0 +1,12 @@ +=== /node_modules/some-library/index.ios.ts === +export function ios() {} +>ios : Symbol(ios, Decl(index.ios.ts, 0, 0)) + +=== /node_modules/some-library/index.ts === +export function base() {} +>base : Symbol(base, Decl(index.ts, 0, 0)) + +=== /test.ts === +import { ios } from "some-library"; +>ios : Symbol(ios, Decl(test.ts, 0, 8)) + diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalTSModule.trace.json b/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalTSModule.trace.json new file mode 100644 index 0000000000000..7224d4d6498d8 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalTSModule.trace.json @@ -0,0 +1,12 @@ +[ + "======== Resolving module 'some-library' from '/test.ts'. ========", + "Explicitly specified module resolution kind: 'NodeJs'.", + "Loading module 'some-library' from 'node_modules' folder, target file type 'TypeScript'.", + "File '/node_modules/some-library/package.json' does not exist.", + "File '/node_modules/some-library.ios.ts' does not exist.", + "File '/node_modules/some-library.ios.tsx' does not exist.", + "File '/node_modules/some-library.ios.d.ts' does not exist.", + "File '/node_modules/some-library/index.ios.ts' exist - use it as a name resolution result.", + "Resolving real path for '/node_modules/some-library/index.ios.ts', result '/node_modules/some-library/index.ios.ts'.", + "======== Module name 'some-library' was successfully resolved to '/node_modules/some-library/index.ios.ts'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalTSModule.types b/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalTSModule.types new file mode 100644 index 0000000000000..bfddc35b501d9 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_one_externalTSModule.types @@ -0,0 +1,12 @@ +=== /node_modules/some-library/index.ios.ts === +export function ios() {} +>ios : () => void + +=== /node_modules/some-library/index.ts === +export function base() {} +>base : () => void + +=== /test.ts === +import { ios } from "some-library"; +>ios : () => void + diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_one_jsModule.js b/tests/baselines/reference/moduleResolutionWithSuffixes_one_jsModule.js new file mode 100644 index 0000000000000..7f41d42befa5d --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_one_jsModule.js @@ -0,0 +1,29 @@ +//// [tests/cases/compiler/moduleResolutionWithSuffixes_one_jsModule.ts] //// + +//// [index.ts] +import { ios } from "./foo.js"; +//// [foo.ios.js] +"use strict"; +exports.__esModule = true; +function ios() {} +exports.ios = ios; +//// [foo.js] +"use strict"; +exports.__esModule = true; +function base() {} +exports.base = base; + + +//// [/bin/foo.ios.js] +"use strict"; +exports.__esModule = true; +function ios() { } +exports.ios = ios; +//// [/bin/index.js] +"use strict"; +exports.__esModule = true; +//// [/bin/foo.js] +"use strict"; +exports.__esModule = true; +function base() { } +exports.base = base; diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_one_jsModule.symbols b/tests/baselines/reference/moduleResolutionWithSuffixes_one_jsModule.symbols new file mode 100644 index 0000000000000..1666dae12a808 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_one_jsModule.symbols @@ -0,0 +1,36 @@ +=== /index.ts === +import { ios } from "./foo.js"; +>ios : Symbol(ios, Decl(index.ts, 0, 8)) + +=== /foo.ios.js === +"use strict"; +exports.__esModule = true; +>exports.__esModule : Symbol(__esModule, Decl(foo.ios.js, 0, 13)) +>exports : Symbol(__esModule, Decl(foo.ios.js, 0, 13)) +>__esModule : Symbol(__esModule, Decl(foo.ios.js, 0, 13)) + +function ios() {} +>ios : Symbol(ios, Decl(foo.ios.js, 1, 26)) + +exports.ios = ios; +>exports.ios : Symbol(ios, Decl(foo.ios.js, 2, 17)) +>exports : Symbol(ios, Decl(foo.ios.js, 2, 17)) +>ios : Symbol(ios, Decl(foo.ios.js, 2, 17)) +>ios : Symbol(ios, Decl(foo.ios.js, 1, 26)) + +=== /foo.js === +"use strict"; +exports.__esModule = true; +>exports.__esModule : Symbol(__esModule, Decl(foo.js, 0, 13)) +>exports : Symbol(__esModule, Decl(foo.js, 0, 13)) +>__esModule : Symbol(__esModule, Decl(foo.js, 0, 13)) + +function base() {} +>base : Symbol(base, Decl(foo.js, 1, 26)) + +exports.base = base; +>exports.base : Symbol(base, Decl(foo.js, 2, 18)) +>exports : Symbol(base, Decl(foo.js, 2, 18)) +>base : Symbol(base, Decl(foo.js, 2, 18)) +>base : Symbol(base, Decl(foo.js, 1, 26)) + diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_one_jsModule.trace.json b/tests/baselines/reference/moduleResolutionWithSuffixes_one_jsModule.trace.json new file mode 100644 index 0000000000000..473007233e556 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_one_jsModule.trace.json @@ -0,0 +1,19 @@ +[ + "======== Resolving module './foo.js' from '/index.ts'. ========", + "Explicitly specified module resolution kind: 'NodeJs'.", + "Loading module as file / folder, candidate module location '/foo.js', target file type 'TypeScript'.", + "File '/foo.js.ios.ts' does not exist.", + "File '/foo.js.ios.tsx' does not exist.", + "File '/foo.js.ios.d.ts' does not exist.", + "File name '/foo.js' has a '.js' extension - stripping it.", + "File '/foo.ios.ts' does not exist.", + "File '/foo.ios.tsx' does not exist.", + "File '/foo.ios.d.ts' does not exist.", + "Directory '/foo.js' does not exist, skipping all lookups in it.", + "Loading module as file / folder, candidate module location '/foo.js', target file type 'JavaScript'.", + "File '/foo.js.ios.js' does not exist.", + "File '/foo.js.ios.jsx' does not exist.", + "File name '/foo.js' has a '.js' extension - stripping it.", + "File '/foo.ios.js' exist - use it as a name resolution result.", + "======== Module name './foo.js' was successfully resolved to '/foo.ios.js'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_one_jsModule.types b/tests/baselines/reference/moduleResolutionWithSuffixes_one_jsModule.types new file mode 100644 index 0000000000000..ca54a7053dbee --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_one_jsModule.types @@ -0,0 +1,46 @@ +=== /index.ts === +import { ios } from "./foo.js"; +>ios : () => void + +=== /foo.ios.js === +"use strict"; +>"use strict" : "use strict" + +exports.__esModule = true; +>exports.__esModule = true : true +>exports.__esModule : true +>exports : typeof import("/foo.ios") +>__esModule : true +>true : true + +function ios() {} +>ios : () => void + +exports.ios = ios; +>exports.ios = ios : () => void +>exports.ios : () => void +>exports : typeof import("/foo.ios") +>ios : () => void +>ios : () => void + +=== /foo.js === +"use strict"; +>"use strict" : "use strict" + +exports.__esModule = true; +>exports.__esModule = true : true +>exports.__esModule : true +>exports : typeof import("/foo") +>__esModule : true +>true : true + +function base() {} +>base : () => void + +exports.base = base; +>exports.base = base : () => void +>exports.base : () => void +>exports : typeof import("/foo") +>base : () => void +>base : () => void + diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_one_jsonModule.js b/tests/baselines/reference/moduleResolutionWithSuffixes_one_jsonModule.js new file mode 100644 index 0000000000000..b46635b3373af --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_one_jsonModule.js @@ -0,0 +1,27 @@ +//// [tests/cases/compiler/moduleResolutionWithSuffixes_one_jsonModule.ts] //// + +//// [index.ts] +import foo from "./foo.json"; +console.log(foo.ios); +//// [foo.ios.json] +{ + "ios": "platform ios" +} +//// [foo.json] +{ + "base": "platform base" +} + + +//// [/bin/foo.ios.json] +{ + "ios": "platform ios" +} +//// [/bin/index.js] +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +exports.__esModule = true; +var foo_json_1 = __importDefault(require("./foo.json")); +console.log(foo_json_1["default"].ios); diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_one_jsonModule.symbols b/tests/baselines/reference/moduleResolutionWithSuffixes_one_jsonModule.symbols new file mode 100644 index 0000000000000..de2c6e6b24de0 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_one_jsonModule.symbols @@ -0,0 +1,17 @@ +=== /index.ts === +import foo from "./foo.json"; +>foo : Symbol(foo, Decl(index.ts, 0, 6)) + +console.log(foo.ios); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>foo.ios : Symbol("ios", Decl(foo.ios.json, 0, 1)) +>foo : Symbol(foo, Decl(index.ts, 0, 6)) +>ios : Symbol("ios", Decl(foo.ios.json, 0, 1)) + +=== /foo.ios.json === +{ + "ios": "platform ios" +>"ios" : Symbol("ios", Decl(foo.ios.json, 0, 1)) +} diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_one_jsonModule.trace.json b/tests/baselines/reference/moduleResolutionWithSuffixes_one_jsonModule.trace.json new file mode 100644 index 0000000000000..ed1b58abf25e5 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_one_jsonModule.trace.json @@ -0,0 +1,17 @@ +[ + "======== Resolving module './foo.json' from '/index.ts'. ========", + "Explicitly specified module resolution kind: 'NodeJs'.", + "Loading module as file / folder, candidate module location '/foo.json', target file type 'TypeScript'.", + "File '/foo.json.ios.ts' does not exist.", + "File '/foo.json.ios.tsx' does not exist.", + "File '/foo.json.ios.d.ts' does not exist.", + "File name '/foo.json' has a '.json' extension - stripping it.", + "File '/foo.json.ios.d.ts' does not exist.", + "Directory '/foo.json' does not exist, skipping all lookups in it.", + "Loading module as file / folder, candidate module location '/foo.json', target file type 'JavaScript'.", + "File '/foo.json.ios.js' does not exist.", + "File '/foo.json.ios.jsx' does not exist.", + "File name '/foo.json' has a '.json' extension - stripping it.", + "File '/foo.ios.json' exist - use it as a name resolution result.", + "======== Module name './foo.json' was successfully resolved to '/foo.ios.json'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_one_jsonModule.types b/tests/baselines/reference/moduleResolutionWithSuffixes_one_jsonModule.types new file mode 100644 index 0000000000000..e9bca0c3100bd --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_one_jsonModule.types @@ -0,0 +1,21 @@ +=== /index.ts === +import foo from "./foo.json"; +>foo : { ios: string; } + +console.log(foo.ios); +>console.log(foo.ios) : void +>console.log : (...data: any[]) => void +>console : Console +>log : (...data: any[]) => void +>foo.ios : string +>foo : { ios: string; } +>ios : string + +=== /foo.ios.json === +{ +>{ "ios": "platform ios"} : { ios: string; } + + "ios": "platform ios" +>"ios" : string +>"platform ios" : "platform ios" +} diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank1.js b/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank1.js new file mode 100644 index 0000000000000..ccea9f45d575a --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank1.js @@ -0,0 +1,33 @@ +//// [tests/cases/compiler/moduleResolutionWithSuffixes_threeLastIsBlank1.ts] //// + +//// [index.ts] +import { ios } from "./foo"; +//// [foo-ios.ts] +export function ios() {} +//// [foo__native.ts] +export function native() {} +//// [foo.ts] +export function base() {} + + +//// [foo-ios.js] +"use strict"; +exports.__esModule = true; +exports.ios = void 0; +function ios() { } +exports.ios = ios; +//// [index.js] +"use strict"; +exports.__esModule = true; +//// [foo__native.js] +"use strict"; +exports.__esModule = true; +exports.native = void 0; +function native() { } +exports.native = native; +//// [foo.js] +"use strict"; +exports.__esModule = true; +exports.base = void 0; +function base() { } +exports.base = base; diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank1.symbols b/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank1.symbols new file mode 100644 index 0000000000000..1c84042747439 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank1.symbols @@ -0,0 +1,16 @@ +=== /index.ts === +import { ios } from "./foo"; +>ios : Symbol(ios, Decl(index.ts, 0, 8)) + +=== /foo-ios.ts === +export function ios() {} +>ios : Symbol(ios, Decl(foo-ios.ts, 0, 0)) + +=== /foo__native.ts === +export function native() {} +>native : Symbol(native, Decl(foo__native.ts, 0, 0)) + +=== /foo.ts === +export function base() {} +>base : Symbol(base, Decl(foo.ts, 0, 0)) + diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank1.trace.json b/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank1.trace.json new file mode 100644 index 0000000000000..4a68f95ae8332 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank1.trace.json @@ -0,0 +1,7 @@ +[ + "======== Resolving module './foo' from '/index.ts'. ========", + "Explicitly specified module resolution kind: 'NodeJs'.", + "Loading module as file / folder, candidate module location '/foo', target file type 'TypeScript'.", + "File '/foo-ios.ts' exist - use it as a name resolution result.", + "======== Module name './foo' was successfully resolved to '/foo-ios.ts'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank1.types b/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank1.types new file mode 100644 index 0000000000000..e269db29bc6f5 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank1.types @@ -0,0 +1,16 @@ +=== /index.ts === +import { ios } from "./foo"; +>ios : () => void + +=== /foo-ios.ts === +export function ios() {} +>ios : () => void + +=== /foo__native.ts === +export function native() {} +>native : () => void + +=== /foo.ts === +export function base() {} +>base : () => void + diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank2.js b/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank2.js new file mode 100644 index 0000000000000..22fdb6d93bd56 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank2.js @@ -0,0 +1,25 @@ +//// [tests/cases/compiler/moduleResolutionWithSuffixes_threeLastIsBlank2.ts] //// + +//// [index.ts] +import { native } from "./foo"; +//// [foo__native.ts] +export function native() {} +//// [foo.ts] +export function base() {} + + +//// [foo__native.js] +"use strict"; +exports.__esModule = true; +exports.native = void 0; +function native() { } +exports.native = native; +//// [index.js] +"use strict"; +exports.__esModule = true; +//// [foo.js] +"use strict"; +exports.__esModule = true; +exports.base = void 0; +function base() { } +exports.base = base; diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank2.symbols b/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank2.symbols new file mode 100644 index 0000000000000..fc4a6ba0c118c --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank2.symbols @@ -0,0 +1,12 @@ +=== /index.ts === +import { native } from "./foo"; +>native : Symbol(native, Decl(index.ts, 0, 8)) + +=== /foo__native.ts === +export function native() {} +>native : Symbol(native, Decl(foo__native.ts, 0, 0)) + +=== /foo.ts === +export function base() {} +>base : Symbol(base, Decl(foo.ts, 0, 0)) + diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank2.trace.json b/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank2.trace.json new file mode 100644 index 0000000000000..57c28e81bfa10 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank2.trace.json @@ -0,0 +1,8 @@ +[ + "======== Resolving module './foo' from '/index.ts'. ========", + "Explicitly specified module resolution kind: 'NodeJs'.", + "Loading module as file / folder, candidate module location '/foo', target file type 'TypeScript'.", + "File '/foo-ios.ts' does not exist.", + "File '/foo__native.ts' exist - use it as a name resolution result.", + "======== Module name './foo' was successfully resolved to '/foo__native.ts'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank2.types b/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank2.types new file mode 100644 index 0000000000000..f85579cd0c18a --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank2.types @@ -0,0 +1,12 @@ +=== /index.ts === +import { native } from "./foo"; +>native : () => void + +=== /foo__native.ts === +export function native() {} +>native : () => void + +=== /foo.ts === +export function base() {} +>base : () => void + diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank3.js b/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank3.js new file mode 100644 index 0000000000000..b064747a2805f --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank3.js @@ -0,0 +1,17 @@ +//// [tests/cases/compiler/moduleResolutionWithSuffixes_threeLastIsBlank3.ts] //// + +//// [index.ts] +import { base } from "./foo"; +//// [foo.ts] +export function base() {} + + +//// [foo.js] +"use strict"; +exports.__esModule = true; +exports.base = void 0; +function base() { } +exports.base = base; +//// [index.js] +"use strict"; +exports.__esModule = true; diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank3.symbols b/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank3.symbols new file mode 100644 index 0000000000000..d4bcb87477b14 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank3.symbols @@ -0,0 +1,8 @@ +=== /index.ts === +import { base } from "./foo"; +>base : Symbol(base, Decl(index.ts, 0, 8)) + +=== /foo.ts === +export function base() {} +>base : Symbol(base, Decl(foo.ts, 0, 0)) + diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank3.trace.json b/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank3.trace.json new file mode 100644 index 0000000000000..693d55759f0a7 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank3.trace.json @@ -0,0 +1,9 @@ +[ + "======== Resolving module './foo' from '/index.ts'. ========", + "Explicitly specified module resolution kind: 'NodeJs'.", + "Loading module as file / folder, candidate module location '/foo', target file type 'TypeScript'.", + "File '/foo-ios.ts' does not exist.", + "File '/foo__native.ts' does not exist.", + "File '/foo.ts' exist - use it as a name resolution result.", + "======== Module name './foo' was successfully resolved to '/foo.ts'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank3.types b/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank3.types new file mode 100644 index 0000000000000..90f587bf346ed --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank3.types @@ -0,0 +1,8 @@ +=== /index.ts === +import { base } from "./foo"; +>base : () => void + +=== /foo.ts === +export function base() {} +>base : () => void + diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank4.errors.txt b/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank4.errors.txt new file mode 100644 index 0000000000000..2b049530aa427 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank4.errors.txt @@ -0,0 +1,19 @@ +/index.ts(1,22): error TS2307: Cannot find module './foo' or its corresponding type declarations. + + +==== /tsconfig.json (0 errors) ==== + // moduleSuffixes has three entries, and the last one is blank. Module resolution should fail. + + { + "compilerOptions": { + "moduleResolution": "node", + "traceResolution": true, + "moduleSuffixes": ["-ios", "__native", ""] + } + } + +==== /index.ts (1 errors) ==== + import { base } from "./foo"; + ~~~~~~~ +!!! error TS2307: Cannot find module './foo' or its corresponding type declarations. + \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank4.js b/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank4.js new file mode 100644 index 0000000000000..3d98d656097b7 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank4.js @@ -0,0 +1,7 @@ +//// [index.ts] +import { base } from "./foo"; + + +//// [index.js] +"use strict"; +exports.__esModule = true; diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank4.symbols b/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank4.symbols new file mode 100644 index 0000000000000..ce0d230ada3b8 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank4.symbols @@ -0,0 +1,4 @@ +=== /index.ts === +import { base } from "./foo"; +>base : Symbol(base, Decl(index.ts, 0, 8)) + diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank4.trace.json b/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank4.trace.json new file mode 100644 index 0000000000000..1a4b097e7fdd3 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank4.trace.json @@ -0,0 +1,24 @@ +[ + "======== Resolving module './foo' from '/index.ts'. ========", + "Explicitly specified module resolution kind: 'NodeJs'.", + "Loading module as file / folder, candidate module location '/foo', target file type 'TypeScript'.", + "File '/foo-ios.ts' does not exist.", + "File '/foo__native.ts' does not exist.", + "File '/foo.ts' does not exist.", + "File '/foo-ios.tsx' does not exist.", + "File '/foo__native.tsx' does not exist.", + "File '/foo.tsx' does not exist.", + "File '/foo-ios.d.ts' does not exist.", + "File '/foo__native.d.ts' does not exist.", + "File '/foo.d.ts' does not exist.", + "Directory '/foo' does not exist, skipping all lookups in it.", + "Loading module as file / folder, candidate module location '/foo', target file type 'JavaScript'.", + "File '/foo-ios.js' does not exist.", + "File '/foo__native.js' does not exist.", + "File '/foo.js' does not exist.", + "File '/foo-ios.jsx' does not exist.", + "File '/foo__native.jsx' does not exist.", + "File '/foo.jsx' does not exist.", + "Directory '/foo' does not exist, skipping all lookups in it.", + "======== Module name './foo' was not resolved. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank4.types b/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank4.types new file mode 100644 index 0000000000000..0744260812a20 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank4.types @@ -0,0 +1,4 @@ +=== /index.ts === +import { base } from "./foo"; +>base : any + diff --git a/tests/baselines/reference/showConfig/Shows tsconfig for single option/moduleSuffixes/tsconfig.json b/tests/baselines/reference/showConfig/Shows tsconfig for single option/moduleSuffixes/tsconfig.json new file mode 100644 index 0000000000000..0c0a76c253ece --- /dev/null +++ b/tests/baselines/reference/showConfig/Shows tsconfig for single option/moduleSuffixes/tsconfig.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + "moduleSuffixes": [] + } +} diff --git a/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json b/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json index e477a6d2d0fde..ceb322c69c81d 100644 --- a/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json @@ -34,6 +34,7 @@ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ // "types": [], /* Specify type package names to be included without being referenced in a source file. */ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ // "resolveJsonModule": true, /* Enable importing .json files. */ // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with advanced options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with advanced options/tsconfig.json index 79809e53b7f92..397b81537cf66 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with advanced options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with advanced options/tsconfig.json @@ -34,6 +34,7 @@ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ // "types": [], /* Specify type package names to be included without being referenced in a source file. */ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ // "resolveJsonModule": true, /* Enable importing .json files. */ // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json index ec639ce04b553..46e0f02109859 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json @@ -34,6 +34,7 @@ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ // "types": [], /* Specify type package names to be included without being referenced in a source file. */ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ // "resolveJsonModule": true, /* Enable importing .json files. */ // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with enum value compiler options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with enum value compiler options/tsconfig.json index 0870344d037ba..722e65ea9d90c 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with enum value compiler options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with enum value compiler options/tsconfig.json @@ -34,6 +34,7 @@ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ // "types": [], /* Specify type package names to be included without being referenced in a source file. */ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ // "resolveJsonModule": true, /* Enable importing .json files. */ // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with files options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with files options/tsconfig.json index eb7b0a8f38d5c..61d47a41cc02a 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with files options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with files options/tsconfig.json @@ -34,6 +34,7 @@ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ // "types": [], /* Specify type package names to be included without being referenced in a source file. */ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ // "resolveJsonModule": true, /* Enable importing .json files. */ // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json index 8ebd3a89cb7cc..60a9edd03542f 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json @@ -34,6 +34,7 @@ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ // "types": [], /* Specify type package names to be included without being referenced in a source file. */ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ // "resolveJsonModule": true, /* Enable importing .json files. */ // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json index e477a6d2d0fde..ceb322c69c81d 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json @@ -34,6 +34,7 @@ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ // "types": [], /* Specify type package names to be included without being referenced in a source file. */ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ // "resolveJsonModule": true, /* Enable importing .json files. */ // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json index 89fa7a41f9806..008a5ba8efb92 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json @@ -34,6 +34,7 @@ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ // "types": [], /* Specify type package names to be included without being referenced in a source file. */ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ // "resolveJsonModule": true, /* Enable importing .json files. */ // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options/tsconfig.json index 0d26d725aab75..6aac8c95127b7 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options/tsconfig.json @@ -34,6 +34,7 @@ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ "types": ["jquery","mocha"], /* Specify type package names to be included without being referenced in a source file. */ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ // "resolveJsonModule": true, /* Enable importing .json files. */ // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ diff --git a/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/declarationDir-is-specified.js b/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/declarationDir-is-specified.js index 6726890d7f245..237919e485b29 100644 --- a/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/declarationDir-is-specified.js +++ b/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/declarationDir-is-specified.js @@ -55,6 +55,7 @@ interface Array { length: number; [n: number]: T; } // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ // "types": [], /* Specify type package names to be included without being referenced in a source file. */ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ // "resolveJsonModule": true, /* Enable importing .json files. */ // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ diff --git a/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/when-outDir-and-declarationDir-is-specified.js b/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/when-outDir-and-declarationDir-is-specified.js index 4eb220350264a..76b486c1de06d 100644 --- a/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/when-outDir-and-declarationDir-is-specified.js +++ b/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/when-outDir-and-declarationDir-is-specified.js @@ -55,6 +55,7 @@ interface Array { length: number; [n: number]: T; } // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ // "types": [], /* Specify type package names to be included without being referenced in a source file. */ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ // "resolveJsonModule": true, /* Enable importing .json files. */ // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ diff --git a/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/when-outDir-is-specified.js b/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/when-outDir-is-specified.js index bb93a691e9717..abe53ffa3f586 100644 --- a/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/when-outDir-is-specified.js +++ b/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/when-outDir-is-specified.js @@ -55,6 +55,7 @@ interface Array { length: number; [n: number]: T; } // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ // "types": [], /* Specify type package names to be included without being referenced in a source file. */ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ // "resolveJsonModule": true, /* Enable importing .json files. */ // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ diff --git a/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/with-outFile.js b/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/with-outFile.js index bcfb9f12b5a10..e249fe771e3c7 100644 --- a/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/with-outFile.js +++ b/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/with-outFile.js @@ -55,6 +55,7 @@ interface Array { length: number; [n: number]: T; } // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ // "types": [], /* Specify type package names to be included without being referenced in a source file. */ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ // "resolveJsonModule": true, /* Enable importing .json files. */ // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ diff --git a/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/without-outDir-or-outFile-is-specified-with-declaration-enabled.js b/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/without-outDir-or-outFile-is-specified-with-declaration-enabled.js index c123aec942b83..c5695045354c0 100644 --- a/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/without-outDir-or-outFile-is-specified-with-declaration-enabled.js +++ b/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/without-outDir-or-outFile-is-specified-with-declaration-enabled.js @@ -55,6 +55,7 @@ interface Array { length: number; [n: number]: T; } // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ // "types": [], /* Specify type package names to be included without being referenced in a source file. */ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ // "resolveJsonModule": true, /* Enable importing .json files. */ // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ diff --git a/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/without-outDir-or-outFile-is-specified.js b/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/without-outDir-or-outFile-is-specified.js index 346ddcce15a8d..82e3ba4802ca4 100644 --- a/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/without-outDir-or-outFile-is-specified.js +++ b/tests/baselines/reference/tscWatch/programUpdates/should-not-trigger-recompilation-because-of-program-emit/without-outDir-or-outFile-is-specified.js @@ -55,6 +55,7 @@ interface Array { length: number; [n: number]: T; } // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ // "types": [], /* Specify type package names to be included without being referenced in a source file. */ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ // "resolveJsonModule": true, /* Enable importing .json files. */ // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ diff --git a/tests/cases/compiler/moduleResolutionWithSuffixes_empty.ts b/tests/cases/compiler/moduleResolutionWithSuffixes_empty.ts new file mode 100644 index 0000000000000..90425b9cd2dec --- /dev/null +++ b/tests/cases/compiler/moduleResolutionWithSuffixes_empty.ts @@ -0,0 +1,14 @@ +// moduleSuffixes is empty. Normal module resolution should occur. + +// @filename: /tsconfig.json +{ + "compilerOptions": { + "moduleResolution": "node", + "traceResolution": true, + "moduleSuffixes": [] + } +} +// @filename: /index.ts +import { base } from "./foo"; +// @filename: /foo.ts +export function base() {} diff --git a/tests/cases/compiler/moduleResolutionWithSuffixes_notSpecified.ts b/tests/cases/compiler/moduleResolutionWithSuffixes_notSpecified.ts new file mode 100644 index 0000000000000..47728ffa63bf8 --- /dev/null +++ b/tests/cases/compiler/moduleResolutionWithSuffixes_notSpecified.ts @@ -0,0 +1,12 @@ +// moduleSuffixes is not specified. Normal module resolution should occur. +// @filename: /tsconfig.json +{ + "compilerOptions": { + "moduleResolution": "node", + "traceResolution": true, + } +} +// @filename: /index.ts +import { base } from "./foo"; +// @filename: /foo.ts +export function base() {} diff --git a/tests/cases/compiler/moduleResolutionWithSuffixes_one.ts b/tests/cases/compiler/moduleResolutionWithSuffixes_one.ts new file mode 100644 index 0000000000000..3867614936ce0 --- /dev/null +++ b/tests/cases/compiler/moduleResolutionWithSuffixes_one.ts @@ -0,0 +1,17 @@ +// moduleSuffixes has one entry and there's a matching file. + +// @filename: /tsconfig.json +{ + "compilerOptions": { + "moduleResolution": "node", + "traceResolution": true, + "moduleSuffixes": [".ios"] + } +} + +// @filename: /index.ts +import { ios } from "./foo"; +// @filename: /foo.ios.ts +export function ios() {} +// @filename: /foo.ts +export function base() {} diff --git a/tests/cases/compiler/moduleResolutionWithSuffixes_oneBlank.ts b/tests/cases/compiler/moduleResolutionWithSuffixes_oneBlank.ts new file mode 100644 index 0000000000000..1ae8ba6f2f6d0 --- /dev/null +++ b/tests/cases/compiler/moduleResolutionWithSuffixes_oneBlank.ts @@ -0,0 +1,15 @@ +// moduleSuffixes has one blank entry. Normal module resolution should occur. + +// @filename: /tsconfig.json +{ + "compilerOptions": { + "moduleResolution": "node", + "traceResolution": true, + "moduleSuffixes": [""] + } +} + +// @filename: /index.ts +import { base } from "./foo"; +// @filename: /foo.ts +export function base() {} diff --git a/tests/cases/compiler/moduleResolutionWithSuffixes_oneNotFound.ts b/tests/cases/compiler/moduleResolutionWithSuffixes_oneNotFound.ts new file mode 100644 index 0000000000000..8ae5ca5ec78f6 --- /dev/null +++ b/tests/cases/compiler/moduleResolutionWithSuffixes_oneNotFound.ts @@ -0,0 +1,15 @@ +// moduleSuffixes has one entry but there isn't a matching file. Module resolution should fail. + +// @filename: /tsconfig.json +{ + "compilerOptions": { + "moduleResolution": "node", + "traceResolution": true, + "moduleSuffixes": [".ios"] + } +} + +// @filename: /index.ts +import { ios } from "./foo"; +// @filename: /foo.ts +export function base() {} diff --git a/tests/cases/compiler/moduleResolutionWithSuffixes_one_dirModuleWithIndex.ts b/tests/cases/compiler/moduleResolutionWithSuffixes_one_dirModuleWithIndex.ts new file mode 100644 index 0000000000000..a20cb3583f4c2 --- /dev/null +++ b/tests/cases/compiler/moduleResolutionWithSuffixes_one_dirModuleWithIndex.ts @@ -0,0 +1,17 @@ +// moduleSuffixes has one entry and there's a matching dir with an index file. + +// @filename: /tsconfig.json +{ + "compilerOptions": { + "moduleResolution": "node", + "traceResolution": true, + "moduleSuffixes": [".ios"] + } +} + +// @filename: /index.ts +import { ios } from "./foo"; +// @filename: /foo/index.ios.ts +export function ios() {} +// @filename: /foo/index.ts +export function base() {} \ No newline at end of file diff --git a/tests/cases/compiler/moduleResolutionWithSuffixes_one_externalModule.ts b/tests/cases/compiler/moduleResolutionWithSuffixes_one_externalModule.ts new file mode 100644 index 0000000000000..4142e716c736a --- /dev/null +++ b/tests/cases/compiler/moduleResolutionWithSuffixes_one_externalModule.ts @@ -0,0 +1,31 @@ +// moduleSuffixes has one entry and there's a matching package. +// @fullEmitPaths: true +// @filename: /tsconfig.json +{ + "compilerOptions": { + "allowJs": true, + "checkJs": false, + "outDir": "bin", + "moduleResolution": "node", + "traceResolution": true, + "moduleSuffixes": [".ios"] + } +} + +// @filename: /node_modules/some-library/index.ios.js +"use strict"; +exports.__esModule = true; +function ios() {} +exports.ios = ios; +// @filename: /node_modules/some-library/index.ios.d.ts +export declare function ios(): void; +// @filename: /node_modules/some-library/index.js +"use strict"; +exports.__esModule = true; +function base() {} +exports.base = base; +// @filename: /node_modules/some-library/index.d.ts +export declare function base(): void; + +// @filename: /index.ts +import { ios } from "some-library"; diff --git a/tests/cases/compiler/moduleResolutionWithSuffixes_one_externalModulePath.ts b/tests/cases/compiler/moduleResolutionWithSuffixes_one_externalModulePath.ts new file mode 100644 index 0000000000000..ad20b18b815ff --- /dev/null +++ b/tests/cases/compiler/moduleResolutionWithSuffixes_one_externalModulePath.ts @@ -0,0 +1,31 @@ +// moduleSuffixes has one entry and there's a matching package with a specific path. +// @fullEmitPaths: true +// @filename: /tsconfig.json +{ + "compilerOptions": { + "allowJs": true, + "checkJs": false, + "outDir": "bin", + "moduleResolution": "node", + "traceResolution": true, + "moduleSuffixes": [".ios"] + } +} + +// @filename: /node_modules/some-library/foo.ios.js +"use strict"; +exports.__esModule = true; +function iosfoo() {} +exports.iosfoo = iosfoo; +// @filename: /node_modules/some-library/foo.ios.d.ts +export declare function iosfoo(): void; +// @filename: /node_modules/some-library/foo.js +"use strict"; +exports.__esModule = true; +function basefoo() {} +exports.basefoo = basefoo; +// @filename: /node_modules/some-library/foo.d.ts +export declare function basefoo(): void; + +// @filename: /index.ts +import { iosfoo } from "some-library/foo"; diff --git a/tests/cases/compiler/moduleResolutionWithSuffixes_one_externalModule_withPaths.ts b/tests/cases/compiler/moduleResolutionWithSuffixes_one_externalModule_withPaths.ts new file mode 100644 index 0000000000000..2abb86f20eb7c --- /dev/null +++ b/tests/cases/compiler/moduleResolutionWithSuffixes_one_externalModule_withPaths.ts @@ -0,0 +1,38 @@ +// moduleSuffixes has one entry and there's a matching package. use the 'paths' option to map the package. +// @fullEmitPaths: true +// @filename: /tsconfig.json +{ + "compilerOptions": { + "allowJs": true, + "checkJs": false, + "outDir": "bin", + "moduleResolution": "node", + "traceResolution": true, + "moduleSuffixes": [".ios"], + "baseUrl": "/", + "paths": { + "some-library": ["node_modules/some-library/lib"], + "some-library/*": ["node_modules/some-library/lib/*"] + } + } +} + +// @filename: /node_modules/some-library/lib/index.ios.js +"use strict"; +exports.__esModule = true; +function ios() {} +exports.ios = ios; +// @filename: /node_modules/some-library/lib/index.ios.d.ts +export declare function ios(): void; +// @filename: /node_modules/some-library/lib/index.js +"use strict"; +exports.__esModule = true; +function base() {} +exports.base = base; +// @filename: /node_modules/some-library/lib/index.d.ts +export declare function base(): void; + +// @filename: /test.ts +import { ios } from "some-library"; +import { ios as ios2 } from "some-library/index"; +import { ios as ios3 } from "some-library/index.js"; diff --git a/tests/cases/compiler/moduleResolutionWithSuffixes_one_externalTSModule.ts b/tests/cases/compiler/moduleResolutionWithSuffixes_one_externalTSModule.ts new file mode 100644 index 0000000000000..7e5afac88ee0f --- /dev/null +++ b/tests/cases/compiler/moduleResolutionWithSuffixes_one_externalTSModule.ts @@ -0,0 +1,18 @@ +// moduleSuffixes has one entry and there's a matching package with TS files. +// @fullEmitPaths: true +// @filename: /tsconfig.json +{ + "compilerOptions": { + "outDir": "bin", + "moduleResolution": "node", + "traceResolution": true, + "moduleSuffixes": [".ios"] + } +} + +// @filename: /node_modules/some-library/index.ios.ts +export function ios() {} +// @filename: /node_modules/some-library/index.ts +export function base() {} +// @filename: /test.ts +import { ios } from "some-library"; diff --git a/tests/cases/compiler/moduleResolutionWithSuffixes_one_jsModule.ts b/tests/cases/compiler/moduleResolutionWithSuffixes_one_jsModule.ts new file mode 100644 index 0000000000000..2fdaedd2c6607 --- /dev/null +++ b/tests/cases/compiler/moduleResolutionWithSuffixes_one_jsModule.ts @@ -0,0 +1,26 @@ +// moduleSuffixes has one entry and there's a matching file. module name explicitly includes JS file extension. +// @fullEmitPaths: true +// @filename: /tsconfig.json +{ + "compilerOptions": { + "allowJs": true, + "checkJs": false, + "outDir": "bin", + "moduleResolution": "node", + "traceResolution": true, + "moduleSuffixes": [".ios"] + } +} + +// @filename: /index.ts +import { ios } from "./foo.js"; +// @filename: /foo.ios.js +"use strict"; +exports.__esModule = true; +function ios() {} +exports.ios = ios; +// @filename: /foo.js +"use strict"; +exports.__esModule = true; +function base() {} +exports.base = base; diff --git a/tests/cases/compiler/moduleResolutionWithSuffixes_one_jsonModule.ts b/tests/cases/compiler/moduleResolutionWithSuffixes_one_jsonModule.ts new file mode 100644 index 0000000000000..c41c9c9f26043 --- /dev/null +++ b/tests/cases/compiler/moduleResolutionWithSuffixes_one_jsonModule.ts @@ -0,0 +1,25 @@ +// moduleSuffixes has one entry and there's a matching file. module name explicitly includes JSON file extension. +// @fullEmitPaths: true +// @filename: /tsconfig.json +{ + "compilerOptions": { + "esModuleInterop": true, + "resolveJsonModule": true, + "outDir": "bin", + "moduleResolution": "node", + "traceResolution": true, + "moduleSuffixes": [".ios"] + } +} + +// @filename: /index.ts +import foo from "./foo.json"; +console.log(foo.ios); +// @filename: /foo.ios.json +{ + "ios": "platform ios" +} +// @filename: /foo.json +{ + "base": "platform base" +} diff --git a/tests/cases/compiler/moduleResolutionWithSuffixes_threeLastIsBlank1.ts b/tests/cases/compiler/moduleResolutionWithSuffixes_threeLastIsBlank1.ts new file mode 100644 index 0000000000000..5e327b42bd44c --- /dev/null +++ b/tests/cases/compiler/moduleResolutionWithSuffixes_threeLastIsBlank1.ts @@ -0,0 +1,19 @@ +// moduleSuffixes has three entries, and the last one is blank. Module resolution should match on the first suffix. + +// @filename: /tsconfig.json +{ + "compilerOptions": { + "moduleResolution": "node", + "traceResolution": true, + "moduleSuffixes": ["-ios", "__native", ""] + } +} + +// @filename: /index.ts +import { ios } from "./foo"; +// @filename: /foo-ios.ts +export function ios() {} +// @filename: /foo__native.ts +export function native() {} +// @filename: /foo.ts +export function base() {} diff --git a/tests/cases/compiler/moduleResolutionWithSuffixes_threeLastIsBlank2.ts b/tests/cases/compiler/moduleResolutionWithSuffixes_threeLastIsBlank2.ts new file mode 100644 index 0000000000000..dc712150493b6 --- /dev/null +++ b/tests/cases/compiler/moduleResolutionWithSuffixes_threeLastIsBlank2.ts @@ -0,0 +1,17 @@ +// moduleSuffixes has three entries, and the last one is blank. Module resolution should match on the second suffix. + +// @filename: /tsconfig.json +{ + "compilerOptions": { + "moduleResolution": "node", + "traceResolution": true, + "moduleSuffixes": ["-ios", "__native", ""] + } +} + +// @filename: /index.ts +import { native } from "./foo"; +// @filename: /foo__native.ts +export function native() {} +// @filename: /foo.ts +export function base() {} diff --git a/tests/cases/compiler/moduleResolutionWithSuffixes_threeLastIsBlank3.ts b/tests/cases/compiler/moduleResolutionWithSuffixes_threeLastIsBlank3.ts new file mode 100644 index 0000000000000..f5d199ef2e531 --- /dev/null +++ b/tests/cases/compiler/moduleResolutionWithSuffixes_threeLastIsBlank3.ts @@ -0,0 +1,15 @@ +// moduleSuffixes has three entries, and the last one is blank. Module resolution should match on the blank suffix. + +// @filename: /tsconfig.json +{ + "compilerOptions": { + "moduleResolution": "node", + "traceResolution": true, + "moduleSuffixes": ["-ios", "__native", ""] + } +} + +// @filename: /index.ts +import { base } from "./foo"; +// @filename: /foo.ts +export function base() {} diff --git a/tests/cases/compiler/moduleResolutionWithSuffixes_threeLastIsBlank4.ts b/tests/cases/compiler/moduleResolutionWithSuffixes_threeLastIsBlank4.ts new file mode 100644 index 0000000000000..cad26dba3ee89 --- /dev/null +++ b/tests/cases/compiler/moduleResolutionWithSuffixes_threeLastIsBlank4.ts @@ -0,0 +1,13 @@ +// moduleSuffixes has three entries, and the last one is blank. Module resolution should fail. + +// @filename: /tsconfig.json +{ + "compilerOptions": { + "moduleResolution": "node", + "traceResolution": true, + "moduleSuffixes": ["-ios", "__native", ""] + } +} + +// @filename: /index.ts +import { base } from "./foo";