Skip to content

Commit aa8f1e5

Browse files
committed
Test when module resolution because of path mapping takes to json file
Test for microsoft#26402
1 parent 62e6e6a commit aa8f1e5

5 files changed

+66
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//// [tests/cases/compiler/requireOfJsonFileWithoutResolveJsonModuleAndPathMapping.ts] ////
2+
3+
//// [foobar.json]
4+
{ "a": 10 }
5+
6+
//// [a.ts]
7+
import foobar from "foo/bar/foobar.json";
8+
9+
10+
//// [/bin/node_modules/foo/bar/foobar.json]
11+
{ "a": 10 }
12+
//// [/bin/a.js]
13+
"use strict";
14+
exports.__esModule = true;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== /a.ts ===
2+
import foobar from "foo/bar/foobar.json";
3+
>foobar : Symbol(foobar, Decl(a.ts, 0, 6))
4+
5+
=== /node_modules/foo/bar/foobar.json ===
6+
{ "a": 10 }
7+
>"a" : Symbol("a", Decl(foobar.json, 0, 1))
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[
2+
"======== Resolving module 'foo/bar/foobar.json' from '/a.ts'. ========",
3+
"Module resolution kind is not specified, using 'NodeJs'.",
4+
"'baseUrl' option is set to '/', using this value to resolve non-relative module name 'foo/bar/foobar.json'.",
5+
"'paths' option is specified, looking for a pattern to match module name 'foo/bar/foobar.json'.",
6+
"Module name 'foo/bar/foobar.json', matched pattern '*'.",
7+
"Trying substitution 'node_modules/*', candidate module location: 'node_modules/foo/bar/foobar.json'.",
8+
"File '/node_modules/foo/bar/foobar.json' exist - use it as a name resolution result.",
9+
"======== Module name 'foo/bar/foobar.json' was successfully resolved to '/node_modules/foo/bar/foobar.json'. ========"
10+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
=== /a.ts ===
2+
import foobar from "foo/bar/foobar.json";
3+
>foobar : { "a": number; }
4+
5+
=== /node_modules/foo/bar/foobar.json ===
6+
{ "a": 10 }
7+
>{ "a": 10 } : { "a": number; }
8+
>"a" : number
9+
>10 : 10
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// @noImplicitReferences: true
2+
// @traceResolution: true
3+
// @allowJs: true
4+
// @esModuleInterop: true
5+
// @fullEmitPaths: true
6+
// @resolveJsonModule: false
7+
8+
// @Filename: /node_modules/foo/bar/foobar.json
9+
{ "a": 10 }
10+
11+
// @Filename: /a.ts
12+
import foobar from "foo/bar/foobar.json";
13+
14+
// @Filename: /tsconfig.json
15+
{
16+
"compilerOptions": {
17+
"baseUrl": ".",
18+
"paths": {
19+
"*": ["node_modules/*", "src/types"]
20+
},
21+
"allowJs": true,
22+
"outDir": "bin"
23+
}
24+
}

0 commit comments

Comments
 (0)