Skip to content

Commit 20a2b0c

Browse files
tschaubsandersn
authored andcommitted
Ignore newline and asterisk when parsing JSDoc typedef (microsoft#26775)
1 parent 038f665 commit 20a2b0c

File tree

4 files changed

+68
-1
lines changed

4 files changed

+68
-1
lines changed

src/compiler/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6856,7 +6856,7 @@ namespace ts {
68566856

68576857
function parseTypedefTag(atToken: AtToken, tagName: Identifier, indent: number): JSDocTypedefTag {
68586858
const typeExpression = tryParseTypeExpression();
6859-
skipWhitespace();
6859+
skipWhitespaceOrAsterisk();
68606860

68616861
const typedefTag = <JSDocTypedefTag>createNode(SyntaxKind.JSDocTypedefTag, atToken.pos);
68626862
typedefTag.atToken = atToken;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
=== tests/cases/conformance/jsdoc/mod1.js ===
2+
/**
3+
* @typedef {function(string): boolean}
4+
* MyType
5+
*/
6+
7+
/**
8+
* Tries to use a type whose name is on a different
9+
* line than the typedef tag.
10+
* @param {MyType} func The function to call.
11+
* @param {string} arg The argument to call it with.
12+
* @returns {boolean} The return.
13+
*/
14+
function callIt(func, arg) {
15+
>callIt : Symbol(callIt, Decl(mod1.js, 0, 0))
16+
>func : Symbol(func, Decl(mod1.js, 12, 16))
17+
>arg : Symbol(arg, Decl(mod1.js, 12, 21))
18+
19+
return func(arg);
20+
>func : Symbol(func, Decl(mod1.js, 12, 16))
21+
>arg : Symbol(arg, Decl(mod1.js, 12, 21))
22+
}
23+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
=== tests/cases/conformance/jsdoc/mod1.js ===
2+
/**
3+
* @typedef {function(string): boolean}
4+
* MyType
5+
*/
6+
7+
/**
8+
* Tries to use a type whose name is on a different
9+
* line than the typedef tag.
10+
* @param {MyType} func The function to call.
11+
* @param {string} arg The argument to call it with.
12+
* @returns {boolean} The return.
13+
*/
14+
function callIt(func, arg) {
15+
>callIt : (func: (arg0: string) => boolean, arg: string) => boolean
16+
>func : (arg0: string) => boolean
17+
>arg : string
18+
19+
return func(arg);
20+
>func(arg) : boolean
21+
>func : (arg0: string) => boolean
22+
>arg : string
23+
}
24+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// @noEmit: true
2+
// @allowJs: true
3+
// @checkJs: true
4+
// @Filename: mod1.js
5+
6+
/**
7+
* @typedef {function(string): boolean}
8+
* MyType
9+
*/
10+
11+
/**
12+
* Tries to use a type whose name is on a different
13+
* line than the typedef tag.
14+
* @param {MyType} func The function to call.
15+
* @param {string} arg The argument to call it with.
16+
* @returns {boolean} The return.
17+
*/
18+
function callIt(func, arg) {
19+
return func(arg);
20+
}

0 commit comments

Comments
 (0)