From 6fc83e73e8ff2907395a63e150652c4951cbbc38 Mon Sep 17 00:00:00 2001 From: Adam Foxman Date: Tue, 8 Mar 2022 20:58:17 -0800 Subject: [PATCH 1/6] Add moduleSuffixes compiler option and related tests. Update baselines for compiler options tests. --- src/compiler/commandLineParser.ts | 11 +++++++ src/compiler/diagnosticMessages.json | 4 +++ src/compiler/moduleNameResolver.ts | 14 ++++++++ src/compiler/types.ts | 1 + .../reference/api/tsserverlibrary.d.ts | 1 + tests/baselines/reference/api/typescript.d.ts | 1 + .../moduleResolutionWithSuffixes_empty.js | 17 ++++++++++ ...moduleResolutionWithSuffixes_empty.symbols | 8 +++++ ...uleResolutionWithSuffixes_empty.trace.json | 7 ++++ .../moduleResolutionWithSuffixes_empty.types | 8 +++++ ...duleResolutionWithSuffixes_notSpecified.js | 17 ++++++++++ ...esolutionWithSuffixes_notSpecified.symbols | 8 +++++ ...lutionWithSuffixes_notSpecified.trace.json | 7 ++++ ...eResolutionWithSuffixes_notSpecified.types | 8 +++++ .../moduleResolutionWithSuffixes_one.js | 25 ++++++++++++++ .../moduleResolutionWithSuffixes_one.symbols | 12 +++++++ ...oduleResolutionWithSuffixes_one.trace.json | 7 ++++ .../moduleResolutionWithSuffixes_one.types | 12 +++++++ .../moduleResolutionWithSuffixes_oneBlank.js | 17 ++++++++++ ...uleResolutionWithSuffixes_oneBlank.symbols | 8 +++++ ...ResolutionWithSuffixes_oneBlank.trace.json | 7 ++++ ...oduleResolutionWithSuffixes_oneBlank.types | 8 +++++ ...olutionWithSuffixes_oneNotFound.errors.txt | 21 ++++++++++++ ...oduleResolutionWithSuffixes_oneNotFound.js | 17 ++++++++++ ...ResolutionWithSuffixes_oneNotFound.symbols | 8 +++++ ...olutionWithSuffixes_oneNotFound.trace.json | 14 ++++++++ ...leResolutionWithSuffixes_oneNotFound.types | 8 +++++ ...esolutionWithSuffixes_threeLastIsBlank1.js | 33 +++++++++++++++++++ ...tionWithSuffixes_threeLastIsBlank1.symbols | 16 +++++++++ ...nWithSuffixes_threeLastIsBlank1.trace.json | 7 ++++ ...lutionWithSuffixes_threeLastIsBlank1.types | 16 +++++++++ ...esolutionWithSuffixes_threeLastIsBlank2.js | 25 ++++++++++++++ ...tionWithSuffixes_threeLastIsBlank2.symbols | 12 +++++++ ...nWithSuffixes_threeLastIsBlank2.trace.json | 8 +++++ ...lutionWithSuffixes_threeLastIsBlank2.types | 12 +++++++ ...esolutionWithSuffixes_threeLastIsBlank3.js | 17 ++++++++++ ...tionWithSuffixes_threeLastIsBlank3.symbols | 8 +++++ ...nWithSuffixes_threeLastIsBlank3.trace.json | 9 +++++ ...lutionWithSuffixes_threeLastIsBlank3.types | 8 +++++ ...nWithSuffixes_threeLastIsBlank4.errors.txt | 19 +++++++++++ ...esolutionWithSuffixes_threeLastIsBlank4.js | 7 ++++ ...tionWithSuffixes_threeLastIsBlank4.symbols | 4 +++ ...nWithSuffixes_threeLastIsBlank4.trace.json | 24 ++++++++++++++ ...lutionWithSuffixes_threeLastIsBlank4.types | 4 +++ .../moduleSuffixes/tsconfig.json | 5 +++ .../tsconfig.json | 1 + .../tsconfig.json | 1 + .../tsconfig.json | 1 + .../tsconfig.json | 1 + .../tsconfig.json | 1 + .../tsconfig.json | 1 + .../tsconfig.json | 1 + .../tsconfig.json | 1 + .../tsconfig.json | 1 + .../declarationDir-is-specified.js | 1 + ...-outDir-and-declarationDir-is-specified.js | 1 + .../when-outDir-is-specified.js | 1 + .../with-outFile.js | 1 + ...e-is-specified-with-declaration-enabled.js | 1 + .../without-outDir-or-outFile-is-specified.js | 1 + .../moduleResolutionWithSuffixes_empty.ts | 14 ++++++++ ...duleResolutionWithSuffixes_notSpecified.ts | 12 +++++++ .../moduleResolutionWithSuffixes_one.ts | 17 ++++++++++ .../moduleResolutionWithSuffixes_oneBlank.ts | 15 +++++++++ ...oduleResolutionWithSuffixes_oneNotFound.ts | 15 +++++++++ ...esolutionWithSuffixes_threeLastIsBlank1.ts | 19 +++++++++++ ...esolutionWithSuffixes_threeLastIsBlank2.ts | 17 ++++++++++ ...esolutionWithSuffixes_threeLastIsBlank3.ts | 15 +++++++++ ...esolutionWithSuffixes_threeLastIsBlank4.ts | 13 ++++++++ 69 files changed, 662 insertions(+) create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_empty.js create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_empty.symbols create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_empty.trace.json create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_empty.types create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_notSpecified.js create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_notSpecified.symbols create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_notSpecified.trace.json create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_notSpecified.types create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_one.js create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_one.symbols create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_one.trace.json create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_one.types create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_oneBlank.js create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_oneBlank.symbols create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_oneBlank.trace.json create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_oneBlank.types create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_oneNotFound.errors.txt create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_oneNotFound.js create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_oneNotFound.symbols create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_oneNotFound.trace.json create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_oneNotFound.types create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank1.js create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank1.symbols create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank1.trace.json create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank1.types create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank2.js create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank2.symbols create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank2.trace.json create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank2.types create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank3.js create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank3.symbols create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank3.trace.json create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank3.types create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank4.errors.txt create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank4.js create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank4.symbols create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank4.trace.json create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_threeLastIsBlank4.types create mode 100644 tests/baselines/reference/showConfig/Shows tsconfig for single option/moduleSuffixes/tsconfig.json create mode 100644 tests/cases/compiler/moduleResolutionWithSuffixes_empty.ts create mode 100644 tests/cases/compiler/moduleResolutionWithSuffixes_notSpecified.ts create mode 100644 tests/cases/compiler/moduleResolutionWithSuffixes_one.ts create mode 100644 tests/cases/compiler/moduleResolutionWithSuffixes_oneBlank.ts create mode 100644 tests/cases/compiler/moduleResolutionWithSuffixes_oneNotFound.ts create mode 100644 tests/cases/compiler/moduleResolutionWithSuffixes_threeLastIsBlank1.ts create mode 100644 tests/cases/compiler/moduleResolutionWithSuffixes_threeLastIsBlank2.ts create mode 100644 tests/cases/compiler/moduleResolutionWithSuffixes_threeLastIsBlank3.ts create mode 100644 tests/cases/compiler/moduleResolutionWithSuffixes_threeLastIsBlank4.ts diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 792b6bf84bbaa..31e3e4d7dd4c7 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -884,6 +884,17 @@ namespace ts { description: Diagnostics.Allow_accessing_UMD_globals_from_modules, defaultValueDescription: false, }, + { + name: "moduleSuffixes", + type: "list", + element: { + name: "suffix", + type: "string" + }, + affectsModuleResolution: true, + category: Diagnostics.Modules, + description: Diagnostics.List_of_file_name_suffixes_to_search_when_resolving_a_module, + }, // Source Maps { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index dba50cfb5330a..bf61fe5fe7bb3 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -5863,6 +5863,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..ede6537196893 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -1576,6 +1576,20 @@ namespace ts { /** Return the file if it exists. */ function tryFile(fileName: string, onlyRecordFailures: boolean, state: ModuleResolutionState): string | undefined { + const ext = tryGetExtensionFromPath(fileName) ?? ""; + const fileNameNoExtension = ext ? removeExtension(fileName, ext) : fileName; + + const suffixes = isArray(state.compilerOptions.moduleSuffixes) && + state.compilerOptions.moduleSuffixes.length > 0 ? state.compilerOptions.moduleSuffixes : [""]; + for (const suffix of suffixes) { + const name = fileNameNoExtension + suffix + ext; + if (tryFileWithSuffix(name, onlyRecordFailures, state)) { + return name; + } + }; + } + + function tryFileWithSuffix(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 dc31b5c79cf2f..f79c07c0043f1 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -6120,6 +6120,7 @@ namespace ts { maxNodeModuleJsDepth?: number; module?: ModuleKind; moduleResolution?: ModuleResolutionKind; + moduleSuffixes?: string[]; newLine?: NewLineKind; noEmit?: boolean; /*@internal*/noEmitForJsFiles?: boolean; diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 2cc99e632b4b5..267a883264f55 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -2957,6 +2957,7 @@ declare namespace ts { maxNodeModuleJsDepth?: number; module?: ModuleKind; moduleResolution?: ModuleResolutionKind; + moduleSuffixes?: string[]; newLine?: NewLineKind; noEmit?: boolean; noEmitHelpers?: boolean; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 588f4a2d550f7..d081862b96853 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -2957,6 +2957,7 @@ declare namespace ts { maxNodeModuleJsDepth?: number; module?: ModuleKind; moduleResolution?: ModuleResolutionKind; + moduleSuffixes?: string[]; newLine?: NewLineKind; noEmit?: boolean; noEmitHelpers?: 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_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 57e9a2b745187..63bcd86d913b4 100644 --- a/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json @@ -33,6 +33,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 bfa516dee13cb..09a02fe76cdc7 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 @@ -33,6 +33,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 eb149f81bf6cb..fa38da69b64d9 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 @@ -33,6 +33,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 8380fa45a09d6..b2d8c07db9bd6 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 @@ -33,6 +33,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 894c1e7e6d727..bed4ad6acdacd 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 @@ -33,6 +33,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 0adbea873c55d..76dea1c236509 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 @@ -33,6 +33,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 57e9a2b745187..63bcd86d913b4 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 @@ -33,6 +33,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 6cec9bab660a8..9cf6491955b8f 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 @@ -33,6 +33,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 b26e448a84b9e..31e602e4e849b 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 @@ -33,6 +33,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 f3473b25e3743..5124d988aafc2 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 @@ -54,6 +54,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 e7d593a417cfa..47cecde3ec1c6 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 @@ -54,6 +54,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 581a85f51836f..03dd7a94cddae 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 @@ -54,6 +54,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 fd153355bec63..12561b1fa329a 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 @@ -54,6 +54,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 1f562d6203f6b..b7d36a5479fed 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 @@ -54,6 +54,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 d3c9002df9d08..bac52584257cb 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 @@ -54,6 +54,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_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"; From 866ab7b89f4301f351771aff39c17d9b6a4fa294 Mon Sep 17 00:00:00 2001 From: Adam Foxman Date: Wed, 9 Mar 2022 12:09:20 -0800 Subject: [PATCH 2/6] Add a flag to the command-line parser which allows "list" params to preserve "falsy" values such as empty strings. Falsy values are normally stripped out. --- src/compiler/commandLineParser.ts | 9 +-- src/compiler/types.ts | 1 + .../config/convertCompilerOptionsFromJson.ts | 64 +++++++++++++++++++ 3 files changed, 70 insertions(+), 4 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 31e3e4d7dd4c7..2d3fbe9d1e519 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -889,8 +889,9 @@ namespace ts { type: "list", element: { name: "suffix", - type: "string" + type: "string", }, + listPreserveFalsyValues: true, affectsModuleResolution: true, category: Diagnostics.Modules, description: Diagnostics.List_of_file_name_suffixes_to_search_when_resolving_a_module, @@ -1448,7 +1449,7 @@ namespace ts { case "number": return mapDefined(values, v => validateJsonOptionValue(opt.element, parseInt(v), errors)); case "string": - return mapDefined(values, v => validateJsonOptionValue(opt.element, v || "", errors)); + return mapDefined(values, v => validateJsonOptionValue(opt.element, opt.listPreserveFalsyValues ? v : (v || ""), errors)); default: return mapDefined(values, v => parseCustomTypeOption(opt.element as CommandLineOptionOfCustomType, v, errors)); } @@ -3188,7 +3189,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; } @@ -3229,7 +3230,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/types.ts b/src/compiler/types.ts index f79c07c0043f1..bf5373d89899e 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -6424,6 +6424,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( { From c11bea7f4a9b077177b19ee1e451245c618fca0e Mon Sep 17 00:00:00 2001 From: Adam Foxman Date: Fri, 18 Mar 2022 13:51:24 -0700 Subject: [PATCH 3/6] Add tests. Rework resolver logic to only run module-suffix code when needed. --- src/compiler/moduleNameResolver.ts | 9 ++- ...tionWithSuffixes_one_dirModuleWithIndex.js | 24 +++++++ ...ithSuffixes_one_dirModuleWithIndex.symbols | 12 ++++ ...Suffixes_one_dirModuleWithIndex.trace.json | 11 ++++ ...nWithSuffixes_one_dirModuleWithIndex.types | 12 ++++ ...solutionWithSuffixes_one_externalModule.js | 34 ++++++++++ ...ionWithSuffixes_one_externalModule.symbols | 44 +++++++++++++ ...WithSuffixes_one_externalModule.trace.json | 14 +++++ ...utionWithSuffixes_one_externalModule.types | 54 ++++++++++++++++ ...tionWithSuffixes_one_externalModulePath.js | 34 ++++++++++ ...ithSuffixes_one_externalModulePath.symbols | 44 +++++++++++++ ...Suffixes_one_externalModulePath.trace.json | 11 ++++ ...nWithSuffixes_one_externalModulePath.types | 54 ++++++++++++++++ ...thSuffixes_one_externalModule_withPaths.js | 36 +++++++++++ ...fixes_one_externalModule_withPaths.symbols | 52 ++++++++++++++++ ...es_one_externalModule_withPaths.trace.json | 45 ++++++++++++++ ...uffixes_one_externalModule_withPaths.types | 62 +++++++++++++++++++ ...duleResolutionWithSuffixes_one_jsModule.js | 29 +++++++++ ...esolutionWithSuffixes_one_jsModule.symbols | 36 +++++++++++ ...lutionWithSuffixes_one_jsModule.trace.json | 19 ++++++ ...eResolutionWithSuffixes_one_jsModule.types | 46 ++++++++++++++ ...leResolutionWithSuffixes_one_jsonModule.js | 27 ++++++++ ...olutionWithSuffixes_one_jsonModule.symbols | 17 +++++ ...tionWithSuffixes_one_jsonModule.trace.json | 17 +++++ ...esolutionWithSuffixes_one_jsonModule.types | 21 +++++++ ...tionWithSuffixes_one_dirModuleWithIndex.ts | 17 +++++ ...solutionWithSuffixes_one_externalModule.ts | 31 ++++++++++ ...tionWithSuffixes_one_externalModulePath.ts | 31 ++++++++++ ...thSuffixes_one_externalModule_withPaths.ts | 38 ++++++++++++ ...duleResolutionWithSuffixes_one_jsModule.ts | 26 ++++++++ ...leResolutionWithSuffixes_one_jsonModule.ts | 25 ++++++++ 31 files changed, 930 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_one_dirModuleWithIndex.js create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_one_dirModuleWithIndex.symbols create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_one_dirModuleWithIndex.trace.json create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_one_dirModuleWithIndex.types create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModule.js create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModule.symbols create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModule.trace.json create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModule.types create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModulePath.js create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModulePath.symbols create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModulePath.trace.json create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModulePath.types create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModule_withPaths.js create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModule_withPaths.symbols create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModule_withPaths.trace.json create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_one_externalModule_withPaths.types create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_one_jsModule.js create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_one_jsModule.symbols create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_one_jsModule.trace.json create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_one_jsModule.types create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_one_jsonModule.js create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_one_jsonModule.symbols create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_one_jsonModule.trace.json create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_one_jsonModule.types create mode 100644 tests/cases/compiler/moduleResolutionWithSuffixes_one_dirModuleWithIndex.ts create mode 100644 tests/cases/compiler/moduleResolutionWithSuffixes_one_externalModule.ts create mode 100644 tests/cases/compiler/moduleResolutionWithSuffixes_one_externalModulePath.ts create mode 100644 tests/cases/compiler/moduleResolutionWithSuffixes_one_externalModule_withPaths.ts create mode 100644 tests/cases/compiler/moduleResolutionWithSuffixes_one_jsModule.ts create mode 100644 tests/cases/compiler/moduleResolutionWithSuffixes_one_jsonModule.ts diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index ede6537196893..558824628c115 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -1576,6 +1576,10 @@ namespace ts { /** Return the file if it exists. */ function tryFile(fileName: string, onlyRecordFailures: boolean, state: ModuleResolutionState): string | undefined { + if (!state.compilerOptions.moduleSuffixes) { + return tryFileLookup(fileName, onlyRecordFailures, state); + } + const ext = tryGetExtensionFromPath(fileName) ?? ""; const fileNameNoExtension = ext ? removeExtension(fileName, ext) : fileName; @@ -1583,13 +1587,14 @@ namespace ts { state.compilerOptions.moduleSuffixes.length > 0 ? state.compilerOptions.moduleSuffixes : [""]; for (const suffix of suffixes) { const name = fileNameNoExtension + suffix + ext; - if (tryFileWithSuffix(name, onlyRecordFailures, state)) { + if (tryFileLookup(name, onlyRecordFailures, state)) { return name; } }; + return undefined; } - function tryFileWithSuffix(fileName: string, onlyRecordFailures: boolean, state: ModuleResolutionState): string | undefined { + function tryFileLookup(fileName: string, onlyRecordFailures: boolean, state: ModuleResolutionState): string | undefined { if (!onlyRecordFailures) { if (state.host.fileExists(fileName)) { if (state.traceEnabled) { 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_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/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_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" +} From 407f33fd0ff11aa44911d36f6405fd057bd2393b Mon Sep 17 00:00:00 2001 From: Adam Foxman Date: Tue, 22 Mar 2022 14:26:12 -0700 Subject: [PATCH 4/6] PR feedback --- src/compiler/moduleNameResolver.ts | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index 558824628c115..104223d1e750d 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -1576,22 +1576,13 @@ namespace ts { /** Return the file if it exists. */ function tryFile(fileName: string, onlyRecordFailures: boolean, state: ModuleResolutionState): string | undefined { - if (!state.compilerOptions.moduleSuffixes) { + if (!state.compilerOptions.moduleSuffixes?.length) { return tryFileLookup(fileName, onlyRecordFailures, state); } const ext = tryGetExtensionFromPath(fileName) ?? ""; const fileNameNoExtension = ext ? removeExtension(fileName, ext) : fileName; - - const suffixes = isArray(state.compilerOptions.moduleSuffixes) && - state.compilerOptions.moduleSuffixes.length > 0 ? state.compilerOptions.moduleSuffixes : [""]; - for (const suffix of suffixes) { - const name = fileNameNoExtension + suffix + ext; - if (tryFileLookup(name, onlyRecordFailures, state)) { - return name; - } - }; - return undefined; + return forEach(state.compilerOptions.moduleSuffixes, suffix => tryFileLookup(fileNameNoExtension + suffix + ext, onlyRecordFailures, state)); } function tryFileLookup(fileName: string, onlyRecordFailures: boolean, state: ModuleResolutionState): string | undefined { From 682b6873a80579f5f1bc48a5f8c089cc94a26790 Mon Sep 17 00:00:00 2001 From: Adam Foxman Date: Tue, 22 Mar 2022 14:31:28 -0700 Subject: [PATCH 5/6] Add test --- ...lutionWithSuffixes_one_externalTSModule.js | 25 +++++++++++++++++++ ...nWithSuffixes_one_externalTSModule.symbols | 12 +++++++++ ...thSuffixes_one_externalTSModule.trace.json | 12 +++++++++ ...ionWithSuffixes_one_externalTSModule.types | 12 +++++++++ ...lutionWithSuffixes_one_externalTSModule.ts | 18 +++++++++++++ 5 files changed, 79 insertions(+) create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_one_externalTSModule.js create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_one_externalTSModule.symbols create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_one_externalTSModule.trace.json create mode 100644 tests/baselines/reference/moduleResolutionWithSuffixes_one_externalTSModule.types create mode 100644 tests/cases/compiler/moduleResolutionWithSuffixes_one_externalTSModule.ts 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/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"; From 5a6026f4801d446a1bf281e246ec91fe2a64d417 Mon Sep 17 00:00:00 2001 From: Adam Foxman Date: Tue, 22 Mar 2022 17:05:22 -0700 Subject: [PATCH 6/6] Remove unnecessary conditional. --- src/compiler/commandLineParser.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 2b8e56d69703e..0da701e44524c 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -1461,7 +1461,7 @@ namespace ts { case "number": return mapDefined(values, v => validateJsonOptionValue(opt.element, parseInt(v), errors)); case "string": - return mapDefined(values, v => validateJsonOptionValue(opt.element, opt.listPreserveFalsyValues ? v : (v || ""), errors)); + return mapDefined(values, v => validateJsonOptionValue(opt.element, v || "", errors)); default: return mapDefined(values, v => parseCustomTypeOption(opt.element as CommandLineOptionOfCustomType, v, errors)); }