Skip to content

Commit 34f6e10

Browse files
yinMatej Sadovskysandersn
authored
Enable parsing of nested parameters for @callback JSDoc tag. (#54681)
Co-authored-by: Matej Sadovsky <[email protected]> Co-authored-by: Nathan Shively-Sanders <[email protected]>
1 parent ed5008d commit 34f6e10

File tree

5 files changed

+116
-2
lines changed

5 files changed

+116
-2
lines changed

src/compiler/parser.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9225,7 +9225,7 @@ namespace Parser {
92259225

92269226
const comment = parseTrailingTagComments(start, getNodePos(), indent, indentText);
92279227

9228-
const nestedTypeLiteral = target !== PropertyLikeParse.CallbackParameter && parseNestedTypeLiteral(typeExpression, name, target, indent);
9228+
const nestedTypeLiteral = parseNestedTypeLiteral(typeExpression, name, target, indent);
92299229
if (nestedTypeLiteral) {
92309230
typeExpression = nestedTypeLiteral;
92319231
isNameFirst = true;
@@ -9540,7 +9540,6 @@ namespace Parser {
95409540
if (canParseTag) {
95419541
const child = tryParseChildTag(target, indent);
95429542
if (child && (child.kind === SyntaxKind.JSDocParameterTag || child.kind === SyntaxKind.JSDocPropertyTag) &&
9543-
target !== PropertyLikeParse.CallbackParameter &&
95449543
name && (isIdentifierNode(child.name) || !escapedTextsEqual(name, child.name.left))) {
95459544
return false;
95469545
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//// [tests/cases/conformance/jsdoc/callbackTagNestedParameter.ts] ////
2+
3+
//// [cb_nested.js]
4+
/**
5+
* @callback WorksWithPeopleCallback
6+
* @param {Object} person
7+
* @param {string} person.name
8+
* @param {number} [person.age]
9+
* @returns {void}
10+
*/
11+
12+
/**
13+
* For each person, calls your callback.
14+
* @param {WorksWithPeopleCallback} callback
15+
* @returns {void}
16+
*/
17+
function eachPerson(callback) {
18+
callback({ name: "Empty" });
19+
}
20+
21+
22+
23+
24+
//// [cb_nested.d.ts]
25+
/**
26+
* @callback WorksWithPeopleCallback
27+
* @param {Object} person
28+
* @param {string} person.name
29+
* @param {number} [person.age]
30+
* @returns {void}
31+
*/
32+
/**
33+
* For each person, calls your callback.
34+
* @param {WorksWithPeopleCallback} callback
35+
* @returns {void}
36+
*/
37+
declare function eachPerson(callback: WorksWithPeopleCallback): void;
38+
type WorksWithPeopleCallback = (person: {
39+
name: string;
40+
age?: number;
41+
}) => void;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//// [tests/cases/conformance/jsdoc/callbackTagNestedParameter.ts] ////
2+
3+
=== cb_nested.js ===
4+
/**
5+
* @callback WorksWithPeopleCallback
6+
* @param {Object} person
7+
* @param {string} person.name
8+
* @param {number} [person.age]
9+
* @returns {void}
10+
*/
11+
12+
/**
13+
* For each person, calls your callback.
14+
* @param {WorksWithPeopleCallback} callback
15+
* @returns {void}
16+
*/
17+
function eachPerson(callback) {
18+
>eachPerson : Symbol(eachPerson, Decl(cb_nested.js, 0, 0))
19+
>callback : Symbol(callback, Decl(cb_nested.js, 13, 20))
20+
21+
callback({ name: "Empty" });
22+
>callback : Symbol(callback, Decl(cb_nested.js, 13, 20))
23+
>name : Symbol(name, Decl(cb_nested.js, 14, 14))
24+
}
25+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//// [tests/cases/conformance/jsdoc/callbackTagNestedParameter.ts] ////
2+
3+
=== cb_nested.js ===
4+
/**
5+
* @callback WorksWithPeopleCallback
6+
* @param {Object} person
7+
* @param {string} person.name
8+
* @param {number} [person.age]
9+
* @returns {void}
10+
*/
11+
12+
/**
13+
* For each person, calls your callback.
14+
* @param {WorksWithPeopleCallback} callback
15+
* @returns {void}
16+
*/
17+
function eachPerson(callback) {
18+
>eachPerson : (callback: WorksWithPeopleCallback) => void
19+
>callback : WorksWithPeopleCallback
20+
21+
callback({ name: "Empty" });
22+
>callback({ name: "Empty" }) : void
23+
>callback : WorksWithPeopleCallback
24+
>{ name: "Empty" } : { name: string; }
25+
>name : string
26+
>"Empty" : "Empty"
27+
}
28+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// @emitDeclarationOnly: true
2+
// @declaration: true
3+
// @allowJs: true
4+
// @checkJs: true
5+
// @Filename: cb_nested.js
6+
/**
7+
* @callback WorksWithPeopleCallback
8+
* @param {Object} person
9+
* @param {string} person.name
10+
* @param {number} [person.age]
11+
* @returns {void}
12+
*/
13+
14+
/**
15+
* For each person, calls your callback.
16+
* @param {WorksWithPeopleCallback} callback
17+
* @returns {void}
18+
*/
19+
function eachPerson(callback) {
20+
callback({ name: "Empty" });
21+
}

0 commit comments

Comments
 (0)