Skip to content

Commit a0a3a79

Browse files
TypeScript Bota-tarasyuk
TypeScript Bot
andauthored
🤖 Pick PR #59026 (fix(59011): TypeScript generates in...) into release-5.5 (#59039)
Co-authored-by: Oleksandr T <[email protected]>
1 parent c4108b6 commit a0a3a79

File tree

8 files changed

+117
-14
lines changed

8 files changed

+117
-14
lines changed

‎src/compiler/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2638,7 +2638,7 @@ namespace Parser {
26382638
function createIdentifier(isIdentifier: boolean, diagnosticMessage?: DiagnosticMessage, privateIdentifierDiagnosticMessage?: DiagnosticMessage): Identifier {
26392639
if (isIdentifier) {
26402640
identifierCount++;
2641-
const pos = getNodePos();
2641+
const pos = scanner.hasLeadingAsterisks() ? scanner.getTokenStart() : getNodePos();
26422642
// Store original token kind if it is not just an Identifier so we can report appropriate error later in type checker
26432643
const originalKeywordKind = token();
26442644
const text = internIdentifier(scanner.getTokenValue());

‎src/compiler/scanner.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ export interface Scanner {
112112
resetTokenState(pos: number): void;
113113
/** @internal */
114114
setSkipJsDocLeadingAsterisks(skip: boolean): void;
115+
/** @internal */
116+
hasLeadingAsterisks(): boolean;
115117
// Invokes the provided callback then unconditionally restores the scanner to the state it
116118
// was in immediately prior to invoking the callback. The result of invoking the callback
117119
// is returned from this function.
@@ -1042,6 +1044,7 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean
10421044

10431045
var commentDirectives: CommentDirective[] | undefined;
10441046
var skipJsDocLeadingAsterisks = 0;
1047+
var asteriskSeen = false;
10451048

10461049
var scriptKind = ScriptKind.Unknown;
10471050
var jsDocParsingMode = JSDocParsingMode.ParseAll;
@@ -1096,6 +1099,7 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean
10961099
resetTokenState,
10971100
setTextPos: resetTokenState,
10981101
setSkipJsDocLeadingAsterisks,
1102+
hasLeadingAsterisks,
10991103
tryScan,
11001104
lookAhead,
11011105
scanRange,
@@ -1877,7 +1881,7 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean
18771881
function scan(): SyntaxKind {
18781882
fullStartPos = pos;
18791883
tokenFlags = TokenFlags.None;
1880-
let asteriskSeen = false;
1884+
asteriskSeen = false;
18811885
while (true) {
18821886
tokenStart = pos;
18831887
if (pos >= end) {
@@ -4004,6 +4008,10 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean
40044008
function setSkipJsDocLeadingAsterisks(skip: boolean) {
40054009
skipJsDocLeadingAsterisks += skip ? 1 : -1;
40064010
}
4011+
4012+
function hasLeadingAsterisks() {
4013+
return asteriskSeen;
4014+
}
40074015
}
40084016

40094017
function codePointAt(s: string, i: number): number {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//// [tests/cases/conformance/jsdoc/importTag18.ts] ////
2+
3+
//// [a.ts]
4+
export interface Foo {}
5+
6+
//// [b.js]
7+
/**
8+
* @import {
9+
* Foo
10+
* } from "./a"
11+
*/
12+
13+
/**
14+
* @param {Foo} a
15+
*/
16+
export function foo(a) {}
17+
18+
19+
20+
21+
//// [a.d.ts]
22+
export interface Foo {
23+
}
24+
//// [b.d.ts]
25+
/**
26+
* @import {
27+
* Foo
28+
* } from "./a"
29+
*/
30+
/**
31+
* @param {Foo} a
32+
*/
33+
export function foo(a: Foo): void;
34+
import type { Foo } from "./a";
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//// [tests/cases/conformance/jsdoc/importTag18.ts] ////
2+
3+
=== a.ts ===
4+
export interface Foo {}
5+
>Foo : Symbol(Foo, Decl(a.ts, 0, 0))
6+
7+
=== b.js ===
8+
/**
9+
* @import {
10+
* Foo
11+
* } from "./a"
12+
*/
13+
14+
/**
15+
* @param {Foo} a
16+
*/
17+
export function foo(a) {}
18+
>foo : Symbol(foo, Decl(b.js, 0, 0))
19+
>a : Symbol(a, Decl(b.js, 9, 20))
20+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//// [tests/cases/conformance/jsdoc/importTag18.ts] ////
2+
3+
=== a.ts ===
4+
5+
export interface Foo {}
6+
7+
=== b.js ===
8+
/**
9+
* @import {
10+
* Foo
11+
* } from "./a"
12+
*/
13+
14+
/**
15+
* @param {Foo} a
16+
*/
17+
export function foo(a) {}
18+
>foo : (a: Foo) => void
19+
> : ^ ^^^^^^^^^^^^^^
20+
>a : Foo
21+
> : ^^^
22+

‎tests/baselines/reference/importTag6.types

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ export interface B {
2525
* @param { B } b
2626
*/
2727
function f(a, b) {}
28-
>f : (a: * A, b: * B) => void
29-
> : ^ ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^
30-
>a : * A
31-
> : ^^^^^^^
32-
>b : * B
33-
> : ^^^^^^^
28+
>f : (a: A, b: B) => void
29+
> : ^ ^^^^^ ^^^^^^^^^^^^
30+
>a : A
31+
> : ^
32+
>b : B
33+
> : ^
3434

‎tests/baselines/reference/importTag7.types

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ export interface B {
2424
* @param { B } b
2525
*/
2626
function f(a, b) {}
27-
>f : (a: * A, b: * B) => void
28-
> : ^ ^^^^^^^ ^^^^^^^^^^^^^^
29-
>a : * A
30-
> : ^^^
31-
>b : * B
32-
> : ^^^
27+
>f : (a: A, b: B) => void
28+
> : ^ ^^^^^ ^^^^^^^^^^^^
29+
>a : A
30+
> : ^
31+
>b : B
32+
> : ^
3333

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// @declaration: true
2+
// @emitDeclarationOnly: true
3+
// @checkJs: true
4+
// @allowJs: true
5+
6+
// @filename: a.ts
7+
export interface Foo {}
8+
9+
// @filename: b.js
10+
/**
11+
* @import {
12+
* Foo
13+
* } from "./a"
14+
*/
15+
16+
/**
17+
* @param {Foo} a
18+
*/
19+
export function foo(a) {}

0 commit comments

Comments
 (0)