Skip to content

Commit 0bb8972

Browse files
authored
Parse nested prop and param tags the same way (microsoft#25139)
That is, only nest them if their name matches the provided parent name. Otherwise do not nest them. Note that this commit changes the behaviour of an incorrect typedef that contains both an `@type` child tag and `@property` child tags. Previously, the `@type` would be incorrectly nested under a `@property` tag with type `object`, just like `@property` tags would be. Now, the `@type` tag causes the entire typedef to ignore the `@property` tags and treat the typedef as if it were an instance of the typedef-and-nested-type pattern: ```js /** * @typedef {Object} name * @type {{ the, actual, type }} */ ```
1 parent b4cf513 commit 0bb8972

File tree

4 files changed

+82
-4
lines changed

4 files changed

+82
-4
lines changed

src/compiler/parser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6922,9 +6922,9 @@ namespace ts {
69226922
case SyntaxKind.AtToken:
69236923
if (canParseTag) {
69246924
const child = tryParseChildTag(target);
6925-
if (child && child.kind === SyntaxKind.JSDocParameterTag &&
6925+
if (child && (child.kind === SyntaxKind.JSDocParameterTag || child.kind === SyntaxKind.JSDocPropertyTag) &&
69266926
target !== PropertyLikeParse.CallbackParameter &&
6927-
(ts.isIdentifier(child.name) || !escapedTextsEqual(name!, child.name.left))) { // TODO: GH#18217
6927+
name && (ts.isIdentifier(child.name) || !escapedTextsEqual(name, child.name.left))) {
69286928
return false;
69296929
}
69306930
return child;

tests/baselines/reference/typedefTagNested.symbols

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,38 @@ const app = {
3232
* @property {string} horrible
3333
* @type {string} idea
3434
*/
35+
var intercessor = 1
36+
>intercessor : Symbol(intercessor, Decl(a.js, 23, 3))
3537

3638
/** @type {Opp} */
3739
var mistake;
38-
>mistake : Symbol(mistake, Decl(a.js, 25, 3))
40+
>mistake : Symbol(mistake, Decl(a.js, 26, 3))
41+
42+
/** @typedef {Object} Upp
43+
* @property {string} name
44+
* @property {Object} not
45+
* @property {string} nested
46+
*/
47+
48+
/** @type {Upp} */
49+
var sala = { name: 'uppsala', not: 0, nested: "ok" };
50+
>sala : Symbol(sala, Decl(a.js, 35, 3))
51+
>name : Symbol(name, Decl(a.js, 35, 12))
52+
>not : Symbol(not, Decl(a.js, 35, 29))
53+
>nested : Symbol(nested, Decl(a.js, 35, 37))
54+
55+
sala.name
56+
>sala.name : Symbol(name, Decl(a.js, 29, 3))
57+
>sala : Symbol(sala, Decl(a.js, 35, 3))
58+
>name : Symbol(name, Decl(a.js, 29, 3))
59+
60+
sala.not
61+
>sala.not : Symbol(not, Decl(a.js, 30, 3))
62+
>sala : Symbol(sala, Decl(a.js, 35, 3))
63+
>not : Symbol(not, Decl(a.js, 30, 3))
64+
65+
sala.nested
66+
>sala.nested : Symbol(nested, Decl(a.js, 31, 3))
67+
>sala : Symbol(sala, Decl(a.js, 35, 3))
68+
>nested : Symbol(nested, Decl(a.js, 31, 3))
3969

tests/baselines/reference/typedefTagNested.types

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,43 @@ const app = {
3737
* @property {string} horrible
3838
* @type {string} idea
3939
*/
40+
var intercessor = 1
41+
>intercessor : number
42+
>1 : 1
4043

4144
/** @type {Opp} */
4245
var mistake;
43-
>mistake : Opp
46+
>mistake : string
47+
48+
/** @typedef {Object} Upp
49+
* @property {string} name
50+
* @property {Object} not
51+
* @property {string} nested
52+
*/
53+
54+
/** @type {Upp} */
55+
var sala = { name: 'uppsala', not: 0, nested: "ok" };
56+
>sala : Upp
57+
>{ name: 'uppsala', not: 0, nested: "ok" } : { name: string; not: number; nested: string; }
58+
>name : string
59+
>'uppsala' : "uppsala"
60+
>not : number
61+
>0 : 0
62+
>nested : string
63+
>"ok" : "ok"
64+
65+
sala.name
66+
>sala.name : string
67+
>sala : Upp
68+
>name : string
69+
70+
sala.not
71+
>sala.not : any
72+
>sala : Upp
73+
>not : any
74+
75+
sala.nested
76+
>sala.nested : string
77+
>sala : Upp
78+
>nested : string
4479

tests/cases/conformance/jsdoc/typedefTagNested.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@ const app = {
2727
* @property {string} horrible
2828
* @type {string} idea
2929
*/
30+
var intercessor = 1
3031

3132
/** @type {Opp} */
3233
var mistake;
34+
35+
/** @typedef {Object} Upp
36+
* @property {string} name
37+
* @property {Object} not
38+
* @property {string} nested
39+
*/
40+
41+
/** @type {Upp} */
42+
var sala = { name: 'uppsala', not: 0, nested: "ok" };
43+
sala.name
44+
sala.not
45+
sala.nested

0 commit comments

Comments
 (0)