fix(58265): JSDoc comment string with the keyword "@private" before import statement in JS file result in cryptic error TS1191 during compilation (#58297)

This commit is contained in:
Oleksandr T 2024-04-25 07:18:31 +03:00 committed by GitHub
parent e28ad995d1
commit 501fa6e4e4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 67 additions and 1 deletions

View File

@ -46331,7 +46331,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
// If we hit an import declaration in an illegal context, just bail out to avoid cascading errors.
return;
}
if (!checkGrammarModifiers(node) && hasEffectiveModifiers(node)) {
if (!checkGrammarModifiers(node) && node.modifiers) {
grammarErrorOnFirstToken(node, Diagnostics.An_import_declaration_cannot_have_modifiers);
}
if (checkExternalImportOrExportDeclaration(node)) {

View File

@ -0,0 +1,20 @@
//// [tests/cases/compiler/es6ImportWithJsDocTags.ts] ////
=== ./a.js ===
export const foo = 1;
>foo : Symbol(foo, Decl(a.js, 0, 12))
=== ./b.js ===
'use strict';
/** @private */
import { foo } from './a.js';
>foo : Symbol(foo, Decl(b.js, 4, 8))
console.log(foo);
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>foo : Symbol(foo, Decl(b.js, 4, 8))

View File

@ -0,0 +1,32 @@
//// [tests/cases/compiler/es6ImportWithJsDocTags.ts] ////
=== ./a.js ===
export const foo = 1;
>foo : 1
> : ^
>1 : 1
> : ^
=== ./b.js ===
'use strict';
>'use strict' : "use strict"
> : ^^^^^^^^^^^^
/** @private */
import { foo } from './a.js';
>foo : 1
> : ^
console.log(foo);
>console.log(foo) : void
> : ^^^^
>console.log : (...data: any[]) => void
> : ^^^^ ^^ ^^^^^^^^^
>console : Console
> : ^^^^^^^
>log : (...data: any[]) => void
> : ^^^^ ^^ ^^^^^^^^^
>foo : 1
> : ^

View File

@ -0,0 +1,14 @@
// @allowJs: true
// @checkJs: true
// @noEmit: true
// @filename: ./a.js
export const foo = 1;
// @filename: ./b.js
'use strict';
/** @private */
import { foo } from './a.js';
console.log(foo);