Skip to content

Commit 238ed7a

Browse files
authored
Visit EOF to collect jsdoc import types (#23521)
* Visit EOF to collect jsdoc import types * Add flag to prevent jsdoc import types from influencing compilation set
1 parent f7163a0 commit 238ed7a

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed

src/compiler/program.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1624,6 +1624,9 @@ namespace ts {
16241624
collectDynamicImportOrRequireCalls(node);
16251625
}
16261626
}
1627+
if ((file.flags & NodeFlags.PossiblyContainsDynamicImport) || isJavaScriptFile) {
1628+
collectDynamicImportOrRequireCalls(file.endOfFileToken);
1629+
}
16271630

16281631
file.imports = imports || emptyArray;
16291632
file.moduleAugmentations = moduleAugmentations || emptyArray;
@@ -2004,7 +2007,8 @@ namespace ts {
20042007
&& !options.noResolve
20052008
&& i < file.imports.length
20062009
&& !elideImport
2007-
&& !(isJsFile && !options.allowJs);
2010+
&& !(isJsFile && !options.allowJs)
2011+
&& (isInJavaScriptFile(file.imports[i]) || !(file.imports[i].flags & NodeFlags.JSDoc));
20082012

20092013
if (elideImport) {
20102014
modulesWithElidedImports.set(file.path, true);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=== tests/cases/compiler/interfaces.d.ts ===
2+
export interface Bar {
3+
>Bar : Symbol(Bar, Decl(interfaces.d.ts, 0, 0))
4+
5+
prop: string
6+
>prop : Symbol(Bar.prop, Decl(interfaces.d.ts, 0, 22))
7+
}
8+
9+
=== tests/cases/compiler/usage.js ===
10+
/** @type {Bar} */
11+
export let bar;
12+
>bar : Symbol(bar, Decl(usage.js, 1, 10))
13+
14+
/** @typedef {import('./interfaces').Bar} Bar */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=== tests/cases/compiler/interfaces.d.ts ===
2+
export interface Bar {
3+
>Bar : Bar
4+
5+
prop: string
6+
>prop : string
7+
}
8+
9+
=== tests/cases/compiler/usage.js ===
10+
/** @type {Bar} */
11+
export let bar;
12+
>bar : Bar
13+
14+
/** @typedef {import('./interfaces').Bar} Bar */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// @allowJs: true
2+
// @noEmit: true
3+
// @checkJs: true
4+
// @filename: interfaces.d.ts
5+
export interface Bar {
6+
prop: string
7+
}
8+
9+
// @filename: usage.js
10+
/** @type {Bar} */
11+
export let bar;
12+
13+
/** @typedef {import('./interfaces').Bar} Bar */

0 commit comments

Comments
 (0)