-
Notifications
You must be signed in to change notification settings - Fork 12.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow a path mapping to provide a file extension #12103
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
16 changes: 16 additions & 0 deletions
16
tests/baselines/reference/pathMappingBasedModuleResolution_withExtension.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,16 @@ | ||
//// [tests/cases/compiler/pathMappingBasedModuleResolution_withExtension.ts] //// | ||
|
||
//// [foo.ts] | ||
|
||
export function foo() {} | ||
|
||
//// [a.ts] | ||
import { foo } from "foo"; | ||
|
||
|
||
//// [foo.js] | ||
"use strict"; | ||
function foo() { } | ||
exports.foo = foo; | ||
//// [a.js] | ||
"use strict"; |
9 changes: 9 additions & 0 deletions
9
tests/baselines/reference/pathMappingBasedModuleResolution_withExtension.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,9 @@ | ||
=== /a.ts === | ||
import { foo } from "foo"; | ||
>foo : Symbol(foo, Decl(a.ts, 0, 8)) | ||
|
||
=== /foo/foo.ts === | ||
|
||
export function foo() {} | ||
>foo : Symbol(foo, Decl(foo.ts, 0, 0)) | ||
|
11 changes: 11 additions & 0 deletions
11
tests/baselines/reference/pathMappingBasedModuleResolution_withExtension.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,11 @@ | ||
[ | ||
"======== Resolving module 'foo' from '/a.ts'. ========", | ||
"Module resolution kind is not specified, using 'NodeJs'.", | ||
"'baseUrl' option is set to '/', using this value to resolve non-relative module name 'foo'", | ||
"'paths' option is specified, looking for a pattern to match module name 'foo'.", | ||
"Module name 'foo', matched pattern 'foo'.", | ||
"Trying substitution 'foo/foo.ts', candidate module location: 'foo/foo.ts'.", | ||
"File '/foo/foo.ts' exist - use it as a name resolution result.", | ||
"Resolving real path for '/foo/foo.ts', result '/foo/foo.ts'", | ||
"======== Module name 'foo' was successfully resolved to '/foo/foo.ts'. ========" | ||
] |
9 changes: 9 additions & 0 deletions
9
tests/baselines/reference/pathMappingBasedModuleResolution_withExtension.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,9 @@ | ||
=== /a.ts === | ||
import { foo } from "foo"; | ||
>foo : () => void | ||
|
||
=== /foo/foo.ts === | ||
|
||
export function foo() {} | ||
>foo : () => void | ||
|
9 changes: 9 additions & 0 deletions
9
...aselines/reference/pathMappingBasedModuleResolution_withExtension_failedLookup.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,9 @@ | ||
/a.ts(2,21): error TS2307: Cannot find module 'foo'. | ||
|
||
|
||
==== /a.ts (1 errors) ==== | ||
|
||
import { foo } from "foo"; | ||
~~~~~ | ||
!!! error TS2307: Cannot find module 'foo'. | ||
|
7 changes: 7 additions & 0 deletions
7
tests/baselines/reference/pathMappingBasedModuleResolution_withExtension_failedLookup.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,7 @@ | ||
//// [a.ts] | ||
|
||
import { foo } from "foo"; | ||
|
||
|
||
//// [a.js] | ||
"use strict"; |
41 changes: 41 additions & 0 deletions
41
...aselines/reference/pathMappingBasedModuleResolution_withExtension_failedLookup.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,41 @@ | ||
[ | ||
"======== Resolving module 'foo' from '/a.ts'. ========", | ||
"Module resolution kind is not specified, using 'NodeJs'.", | ||
"'baseUrl' option is set to '/', using this value to resolve non-relative module name 'foo'", | ||
"'paths' option is specified, looking for a pattern to match module name 'foo'.", | ||
"Module name 'foo', matched pattern 'foo'.", | ||
"Trying substitution 'foo/foo.ts', candidate module location: 'foo/foo.ts'.", | ||
"File '/foo/foo.ts' does not exist.", | ||
"Loading module 'foo' from 'node_modules' folder.", | ||
"File '/node_modules/foo.ts' does not exist.", | ||
"File '/node_modules/foo.tsx' does not exist.", | ||
"File '/node_modules/foo.d.ts' does not exist.", | ||
"File '/node_modules/foo/package.json' does not exist.", | ||
"File '/node_modules/foo/index.ts' does not exist.", | ||
"File '/node_modules/foo/index.tsx' does not exist.", | ||
"File '/node_modules/foo/index.d.ts' does not exist.", | ||
"File '/node_modules/@types/foo.ts' does not exist.", | ||
"File '/node_modules/@types/foo.tsx' does not exist.", | ||
"File '/node_modules/@types/foo.d.ts' does not exist.", | ||
"File '/node_modules/@types/foo/package.json' does not exist.", | ||
"File '/node_modules/@types/foo/index.ts' does not exist.", | ||
"File '/node_modules/@types/foo/index.tsx' does not exist.", | ||
"File '/node_modules/@types/foo/index.d.ts' does not exist.", | ||
"'baseUrl' option is set to '/', using this value to resolve non-relative module name 'foo'", | ||
"'paths' option is specified, looking for a pattern to match module name 'foo'.", | ||
"Module name 'foo', matched pattern 'foo'.", | ||
"Trying substitution 'foo/foo.ts', candidate module location: 'foo/foo.ts'.", | ||
"File '/foo/foo.ts' does not exist.", | ||
"Loading module 'foo' from 'node_modules' folder.", | ||
"File '/node_modules/foo.js' does not exist.", | ||
"File '/node_modules/foo.jsx' does not exist.", | ||
"File '/node_modules/foo/package.json' does not exist.", | ||
"File '/node_modules/foo/index.js' does not exist.", | ||
"File '/node_modules/foo/index.jsx' does not exist.", | ||
"File '/node_modules/@types/foo.js' does not exist.", | ||
"File '/node_modules/@types/foo.jsx' does not exist.", | ||
"File '/node_modules/@types/foo/package.json' does not exist.", | ||
"File '/node_modules/@types/foo/index.js' does not exist.", | ||
"File '/node_modules/@types/foo/index.jsx' does not exist.", | ||
"======== Module name 'foo' was not resolved. ========" | ||
] |
18 changes: 18 additions & 0 deletions
18
tests/cases/compiler/pathMappingBasedModuleResolution_withExtension.ts
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,18 @@ | ||
// @noImplicitReferences: true | ||
// @traceResolution: true | ||
|
||
// @Filename: /foo/foo.ts | ||
export function foo() {} | ||
|
||
// @Filename: /a.ts | ||
import { foo } from "foo"; | ||
|
||
// @Filename: /tsconfig.json | ||
{ | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"paths": { | ||
"foo": ["foo/foo.ts"] | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
tests/cases/compiler/pathMappingBasedModuleResolution_withExtension_failedLookup.ts
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,15 @@ | ||
// @noImplicitReferences: true | ||
// @traceResolution: true | ||
|
||
// @Filename: /a.ts | ||
import { foo } from "foo"; | ||
|
||
// @Filename: /tsconfig.json | ||
{ | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"paths": { | ||
"foo": ["foo/foo.ts"] | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that restricting extensions to only
.ts
is a right thing here i.e. if user wants to remap some import to.js
file. (cc @mhegazy for the opinion)