Skip to content

Commit 8496039

Browse files
Fix JSDoc @import resolution in --moduleResolution bundler (#60011)
Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
1 parent 55886a1 commit 8496039

File tree

4 files changed

+114
-4
lines changed

4 files changed

+114
-4
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4627,12 +4627,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
46274627
? location
46284628
: (isModuleDeclaration(location) ? location : location.parent && isModuleDeclaration(location.parent) && location.parent.name === location ? location.parent : undefined)?.name ||
46294629
(isLiteralImportTypeNode(location) ? location : undefined)?.argument.literal ||
4630-
(isInJSFile(location) && isJSDocImportTag(location) ? location.moduleSpecifier : undefined) ||
46314630
(isVariableDeclaration(location) && location.initializer && isRequireCall(location.initializer, /*requireStringLiteralLikeArgument*/ true) ? location.initializer.arguments[0] : undefined) ||
46324631
findAncestor(location, isImportCall)?.arguments[0] ||
4633-
findAncestor(location, isImportDeclaration)?.moduleSpecifier ||
4634-
findAncestor(location, isExternalModuleImportEqualsDeclaration)?.moduleReference.expression ||
4635-
findAncestor(location, isExportDeclaration)?.moduleSpecifier;
4632+
findAncestor(location, or(isImportDeclaration, isJSDocImportTag, isExportDeclaration))?.moduleSpecifier ||
4633+
findAncestor(location, isExternalModuleImportEqualsDeclaration)?.moduleReference.expression;
46364634
const mode = contextSpecifier && isStringLiteralLike(contextSpecifier)
46374635
? host.getModeForUsageLocation(currentSourceFile, contextSpecifier)
46384636
: host.getDefaultResolutionModeForFile(currentSourceFile);
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
test.ts(2,17): error TS2304: Cannot find name 'tslib'.
2+
3+
4+
==== node_modules/tslib/package.json (0 errors) ====
5+
{
6+
"name": "tslib",
7+
"exports": {
8+
".": {
9+
"module": {
10+
"types": "./modules/index.d.ts",
11+
"default": "./tslib.es6.mjs"
12+
},
13+
"import": {
14+
"node": "./modules/index.js",
15+
"default": {
16+
"types": "./modules/index.d.ts",
17+
"default": "./tslib.es6.mjs"
18+
}
19+
},
20+
"default": "./tslib.js"
21+
},
22+
"./*": "./*",
23+
"./": "./"
24+
}
25+
}
26+
27+
==== node_modules/tslib/modules/index.d.ts (0 errors) ====
28+
export {};
29+
30+
==== node_modules/tslib/tslib.d.ts (0 errors) ====
31+
export {};
32+
33+
==== test.ts (1 errors) ====
34+
/** @import * as tslib from "tslib" */
35+
type T = typeof tslib
36+
~~~~~
37+
!!! error TS2304: Cannot find name 'tslib'.
38+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// @noEmit: true
2+
// @checkJs: true
3+
// @allowJs: true
4+
// @module: preserve
5+
// @noTypesAndSymbols: true
6+
7+
// @Filename: node_modules/tslib/package.json
8+
{
9+
"name": "tslib",
10+
"exports": {
11+
".": {
12+
"module": {
13+
"types": "./modules/index.d.ts",
14+
"default": "./tslib.es6.mjs"
15+
},
16+
"import": {
17+
"node": "./modules/index.js",
18+
"default": {
19+
"types": "./modules/index.d.ts",
20+
"default": "./tslib.es6.mjs"
21+
}
22+
},
23+
"default": "./tslib.js"
24+
},
25+
"./*": "./*",
26+
"./": "./"
27+
}
28+
}
29+
30+
// @Filename: node_modules/tslib/modules/index.d.ts
31+
export {};
32+
33+
// @Filename: node_modules/tslib/tslib.d.ts
34+
export {};
35+
36+
// @Filename: test.js
37+
/** @import * as tslib from "tslib" */
38+
/** @type {typeof tslib} T */
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// @noEmit: true
2+
// @module: preserve
3+
// @noTypesAndSymbols: true
4+
5+
// @Filename: node_modules/tslib/package.json
6+
{
7+
"name": "tslib",
8+
"exports": {
9+
".": {
10+
"module": {
11+
"types": "./modules/index.d.ts",
12+
"default": "./tslib.es6.mjs"
13+
},
14+
"import": {
15+
"node": "./modules/index.js",
16+
"default": {
17+
"types": "./modules/index.d.ts",
18+
"default": "./tslib.es6.mjs"
19+
}
20+
},
21+
"default": "./tslib.js"
22+
},
23+
"./*": "./*",
24+
"./": "./"
25+
}
26+
}
27+
28+
// @Filename: node_modules/tslib/modules/index.d.ts
29+
export {};
30+
31+
// @Filename: node_modules/tslib/tslib.d.ts
32+
export {};
33+
34+
// @Filename: test.ts
35+
/** @import * as tslib from "tslib" */
36+
type T = typeof tslib

0 commit comments

Comments
 (0)