From 501fa6e4e4cd1eb41253d3b3ed74884c6dd82ef2 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Thu, 25 Apr 2024 07:18:31 +0300 Subject: [PATCH] fix(58265): JSDoc comment string with the keyword "@private" before import statement in JS file result in cryptic error TS1191 during compilation (#58297) --- src/compiler/checker.ts | 2 +- .../reference/es6ImportWithJsDocTags.symbols | 20 ++++++++++++ .../reference/es6ImportWithJsDocTags.types | 32 +++++++++++++++++++ .../cases/compiler/es6ImportWithJsDocTags.ts | 14 ++++++++ 4 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/es6ImportWithJsDocTags.symbols create mode 100644 tests/baselines/reference/es6ImportWithJsDocTags.types create mode 100644 tests/cases/compiler/es6ImportWithJsDocTags.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c4ae0196f0e..6bb0efc2c83 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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)) { diff --git a/tests/baselines/reference/es6ImportWithJsDocTags.symbols b/tests/baselines/reference/es6ImportWithJsDocTags.symbols new file mode 100644 index 00000000000..aa588d9fbc2 --- /dev/null +++ b/tests/baselines/reference/es6ImportWithJsDocTags.symbols @@ -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)) + diff --git a/tests/baselines/reference/es6ImportWithJsDocTags.types b/tests/baselines/reference/es6ImportWithJsDocTags.types new file mode 100644 index 00000000000..4e5b3c05511 --- /dev/null +++ b/tests/baselines/reference/es6ImportWithJsDocTags.types @@ -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 +> : ^ + diff --git a/tests/cases/compiler/es6ImportWithJsDocTags.ts b/tests/cases/compiler/es6ImportWithJsDocTags.ts new file mode 100644 index 00000000000..fadace52053 --- /dev/null +++ b/tests/cases/compiler/es6ImportWithJsDocTags.ts @@ -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);