Skip to content

Commit 501fa6e

Browse files
authored
fix(58265): JSDoc comment string with the keyword "@Private" before import statement in JS file result in cryptic error TS1191 during compilation (#58297)
1 parent e28ad99 commit 501fa6e

File tree

4 files changed

+67
-1
lines changed

4 files changed

+67
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46331,7 +46331,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4633146331
// If we hit an import declaration in an illegal context, just bail out to avoid cascading errors.
4633246332
return;
4633346333
}
46334-
if (!checkGrammarModifiers(node) && hasEffectiveModifiers(node)) {
46334+
if (!checkGrammarModifiers(node) && node.modifiers) {
4633546335
grammarErrorOnFirstToken(node, Diagnostics.An_import_declaration_cannot_have_modifiers);
4633646336
}
4633746337
if (checkExternalImportOrExportDeclaration(node)) {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//// [tests/cases/compiler/es6ImportWithJsDocTags.ts] ////
2+
3+
=== ./a.js ===
4+
export const foo = 1;
5+
>foo : Symbol(foo, Decl(a.js, 0, 12))
6+
7+
=== ./b.js ===
8+
'use strict';
9+
10+
/** @private */
11+
12+
import { foo } from './a.js';
13+
>foo : Symbol(foo, Decl(b.js, 4, 8))
14+
15+
console.log(foo);
16+
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
17+
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
18+
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
19+
>foo : Symbol(foo, Decl(b.js, 4, 8))
20+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//// [tests/cases/compiler/es6ImportWithJsDocTags.ts] ////
2+
3+
=== ./a.js ===
4+
export const foo = 1;
5+
>foo : 1
6+
> : ^
7+
>1 : 1
8+
> : ^
9+
10+
=== ./b.js ===
11+
'use strict';
12+
>'use strict' : "use strict"
13+
> : ^^^^^^^^^^^^
14+
15+
/** @private */
16+
17+
import { foo } from './a.js';
18+
>foo : 1
19+
> : ^
20+
21+
console.log(foo);
22+
>console.log(foo) : void
23+
> : ^^^^
24+
>console.log : (...data: any[]) => void
25+
> : ^^^^ ^^ ^^^^^^^^^
26+
>console : Console
27+
> : ^^^^^^^
28+
>log : (...data: any[]) => void
29+
> : ^^^^ ^^ ^^^^^^^^^
30+
>foo : 1
31+
> : ^
32+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// @allowJs: true
2+
// @checkJs: true
3+
// @noEmit: true
4+
// @filename: ./a.js
5+
export const foo = 1;
6+
7+
// @filename: ./b.js
8+
'use strict';
9+
10+
/** @private */
11+
12+
import { foo } from './a.js';
13+
14+
console.log(foo);

0 commit comments

Comments
 (0)