-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a new compiler option
moduleSuffixes
to expand the node module …
…resolver's search algorithm (#48189) * Add moduleSuffixes compiler option and related tests. Update baselines for compiler options tests. * 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. * Add tests. Rework resolver logic to only run module-suffix code when needed. * PR feedback * Add test * Remove unnecessary conditional.
- Loading branch information
Showing
105 changed files
with
1,728 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
tests/baselines/reference/moduleResolutionWithSuffixes_empty.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
8 changes: 8 additions & 0 deletions
8
tests/baselines/reference/moduleResolutionWithSuffixes_empty.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) | ||
|
7 changes: 7 additions & 0 deletions
7
tests/baselines/reference/moduleResolutionWithSuffixes_empty.trace.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'. ========" | ||
] |
8 changes: 8 additions & 0 deletions
8
tests/baselines/reference/moduleResolutionWithSuffixes_empty.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
=== /index.ts === | ||
import { base } from "./foo"; | ||
>base : () => void | ||
|
||
=== /foo.ts === | ||
export function base() {} | ||
>base : () => void | ||
|
17 changes: 17 additions & 0 deletions
17
tests/baselines/reference/moduleResolutionWithSuffixes_notSpecified.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
8 changes: 8 additions & 0 deletions
8
tests/baselines/reference/moduleResolutionWithSuffixes_notSpecified.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) | ||
|
7 changes: 7 additions & 0 deletions
7
tests/baselines/reference/moduleResolutionWithSuffixes_notSpecified.trace.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'. ========" | ||
] |
8 changes: 8 additions & 0 deletions
8
tests/baselines/reference/moduleResolutionWithSuffixes_notSpecified.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
=== /index.ts === | ||
import { base } from "./foo"; | ||
>base : () => void | ||
|
||
=== /foo.ts === | ||
export function base() {} | ||
>base : () => void | ||
|
25 changes: 25 additions & 0 deletions
25
tests/baselines/reference/moduleResolutionWithSuffixes_one.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
12 changes: 12 additions & 0 deletions
12
tests/baselines/reference/moduleResolutionWithSuffixes_one.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) | ||
|
7 changes: 7 additions & 0 deletions
7
tests/baselines/reference/moduleResolutionWithSuffixes_one.trace.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'. ========" | ||
] |
12 changes: 12 additions & 0 deletions
12
tests/baselines/reference/moduleResolutionWithSuffixes_one.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
17 changes: 17 additions & 0 deletions
17
tests/baselines/reference/moduleResolutionWithSuffixes_oneBlank.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
8 changes: 8 additions & 0 deletions
8
tests/baselines/reference/moduleResolutionWithSuffixes_oneBlank.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) | ||
|
7 changes: 7 additions & 0 deletions
7
tests/baselines/reference/moduleResolutionWithSuffixes_oneBlank.trace.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'. ========" | ||
] |
8 changes: 8 additions & 0 deletions
8
tests/baselines/reference/moduleResolutionWithSuffixes_oneBlank.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
=== /index.ts === | ||
import { base } from "./foo"; | ||
>base : () => void | ||
|
||
=== /foo.ts === | ||
export function base() {} | ||
>base : () => void | ||
|
21 changes: 21 additions & 0 deletions
21
tests/baselines/reference/moduleResolutionWithSuffixes_oneNotFound.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} | ||
|
Oops, something went wrong.