diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index e37d6cf5d649d..4895028225ca7 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -9225,7 +9225,7 @@ namespace Parser { const comment = parseTrailingTagComments(start, getNodePos(), indent, indentText); - const nestedTypeLiteral = target !== PropertyLikeParse.CallbackParameter && parseNestedTypeLiteral(typeExpression, name, target, indent); + const nestedTypeLiteral = parseNestedTypeLiteral(typeExpression, name, target, indent); if (nestedTypeLiteral) { typeExpression = nestedTypeLiteral; isNameFirst = true; @@ -9540,7 +9540,6 @@ namespace Parser { if (canParseTag) { const child = tryParseChildTag(target, indent); if (child && (child.kind === SyntaxKind.JSDocParameterTag || child.kind === SyntaxKind.JSDocPropertyTag) && - target !== PropertyLikeParse.CallbackParameter && name && (isIdentifierNode(child.name) || !escapedTextsEqual(name, child.name.left))) { return false; } diff --git a/tests/baselines/reference/callbackTagNestedParameter.js b/tests/baselines/reference/callbackTagNestedParameter.js new file mode 100644 index 0000000000000..7bd2fbaa734d3 --- /dev/null +++ b/tests/baselines/reference/callbackTagNestedParameter.js @@ -0,0 +1,41 @@ +//// [tests/cases/conformance/jsdoc/callbackTagNestedParameter.ts] //// + +//// [cb_nested.js] +/** + * @callback WorksWithPeopleCallback + * @param {Object} person + * @param {string} person.name + * @param {number} [person.age] + * @returns {void} + */ + +/** + * For each person, calls your callback. + * @param {WorksWithPeopleCallback} callback + * @returns {void} + */ +function eachPerson(callback) { + callback({ name: "Empty" }); +} + + + + +//// [cb_nested.d.ts] +/** + * @callback WorksWithPeopleCallback + * @param {Object} person + * @param {string} person.name + * @param {number} [person.age] + * @returns {void} + */ +/** + * For each person, calls your callback. + * @param {WorksWithPeopleCallback} callback + * @returns {void} + */ +declare function eachPerson(callback: WorksWithPeopleCallback): void; +type WorksWithPeopleCallback = (person: { + name: string; + age?: number; +}) => void; diff --git a/tests/baselines/reference/callbackTagNestedParameter.symbols b/tests/baselines/reference/callbackTagNestedParameter.symbols new file mode 100644 index 0000000000000..41a072d8a0ee0 --- /dev/null +++ b/tests/baselines/reference/callbackTagNestedParameter.symbols @@ -0,0 +1,25 @@ +//// [tests/cases/conformance/jsdoc/callbackTagNestedParameter.ts] //// + +=== cb_nested.js === +/** + * @callback WorksWithPeopleCallback + * @param {Object} person + * @param {string} person.name + * @param {number} [person.age] + * @returns {void} + */ + +/** + * For each person, calls your callback. + * @param {WorksWithPeopleCallback} callback + * @returns {void} + */ +function eachPerson(callback) { +>eachPerson : Symbol(eachPerson, Decl(cb_nested.js, 0, 0)) +>callback : Symbol(callback, Decl(cb_nested.js, 13, 20)) + + callback({ name: "Empty" }); +>callback : Symbol(callback, Decl(cb_nested.js, 13, 20)) +>name : Symbol(name, Decl(cb_nested.js, 14, 14)) +} + diff --git a/tests/baselines/reference/callbackTagNestedParameter.types b/tests/baselines/reference/callbackTagNestedParameter.types new file mode 100644 index 0000000000000..1ab84666b791b --- /dev/null +++ b/tests/baselines/reference/callbackTagNestedParameter.types @@ -0,0 +1,28 @@ +//// [tests/cases/conformance/jsdoc/callbackTagNestedParameter.ts] //// + +=== cb_nested.js === +/** + * @callback WorksWithPeopleCallback + * @param {Object} person + * @param {string} person.name + * @param {number} [person.age] + * @returns {void} + */ + +/** + * For each person, calls your callback. + * @param {WorksWithPeopleCallback} callback + * @returns {void} + */ +function eachPerson(callback) { +>eachPerson : (callback: WorksWithPeopleCallback) => void +>callback : WorksWithPeopleCallback + + callback({ name: "Empty" }); +>callback({ name: "Empty" }) : void +>callback : WorksWithPeopleCallback +>{ name: "Empty" } : { name: string; } +>name : string +>"Empty" : "Empty" +} + diff --git a/tests/cases/conformance/jsdoc/callbackTagNestedParameter.ts b/tests/cases/conformance/jsdoc/callbackTagNestedParameter.ts new file mode 100644 index 0000000000000..5c4c8b66618a6 --- /dev/null +++ b/tests/cases/conformance/jsdoc/callbackTagNestedParameter.ts @@ -0,0 +1,21 @@ +// @emitDeclarationOnly: true +// @declaration: true +// @allowJs: true +// @checkJs: true +// @Filename: cb_nested.js +/** + * @callback WorksWithPeopleCallback + * @param {Object} person + * @param {string} person.name + * @param {number} [person.age] + * @returns {void} + */ + +/** + * For each person, calls your callback. + * @param {WorksWithPeopleCallback} callback + * @returns {void} + */ +function eachPerson(callback) { + callback({ name: "Empty" }); +}