Skip to content

Commit e942bbb

Browse files
committed
Test: jsdoc @param type literals
1 parent 8d2d226 commit e942bbb

3 files changed

Lines changed: 385 additions & 0 deletions

File tree

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
=== tests/cases/conformance/jsdoc/0.js ===
2+
/**
3+
* @param {Object} notSpecial
4+
* @param {string} unrelated - not actually related because it's not notSpecial.unrelated
5+
*/
6+
function normal(notSpecial) {
7+
>normal : Symbol(normal, Decl(0.js, 0, 0))
8+
>notSpecial : Symbol(notSpecial, Decl(0.js, 4, 16))
9+
10+
notSpecial; // should just be 'any'
11+
>notSpecial : Symbol(notSpecial, Decl(0.js, 4, 16))
12+
}
13+
normal(12);
14+
>normal : Symbol(normal, Decl(0.js, 0, 0))
15+
16+
/**
17+
* @param {Object} opts1 doc1
18+
* @param {string} opts1.x doc2
19+
* @param {string=} opts1.y doc3
20+
* @param {string} [opts1.z] doc4
21+
* @param {string} [opts1.w="hi"] doc5
22+
*/
23+
function foo1(opts1) {
24+
>foo1 : Symbol(foo1, Decl(0.js, 7, 11))
25+
>opts1 : Symbol(opts1, Decl(0.js, 16, 14))
26+
27+
opts1.x;
28+
>opts1.x : Symbol(x, Decl(0.js, 11, 3))
29+
>opts1 : Symbol(opts1, Decl(0.js, 16, 14))
30+
>x : Symbol(x, Decl(0.js, 11, 3))
31+
}
32+
33+
foo1({x: 'abc'});
34+
>foo1 : Symbol(foo1, Decl(0.js, 7, 11))
35+
>x : Symbol(x, Decl(0.js, 20, 6))
36+
37+
/**
38+
* @param {Object[]} opts2
39+
* @param {string} opts2[].anotherX
40+
* @param {string=} opts2[].anotherY
41+
*/
42+
function foo2(/** @param opts2 bad idea theatre! */opts2) {
43+
>foo2 : Symbol(foo2, Decl(0.js, 20, 17))
44+
>opts2 : Symbol(opts2, Decl(0.js, 27, 14))
45+
46+
opts2[0].anotherX;
47+
>opts2[0].anotherX : Symbol(anotherX, Decl(0.js, 24, 3))
48+
>opts2 : Symbol(opts2, Decl(0.js, 27, 14))
49+
>anotherX : Symbol(anotherX, Decl(0.js, 24, 3))
50+
}
51+
52+
foo2([{anotherX: "world"}]);
53+
>foo2 : Symbol(foo2, Decl(0.js, 20, 17))
54+
>anotherX : Symbol(anotherX, Decl(0.js, 31, 7))
55+
56+
/**
57+
* @param {object} opts3
58+
* @param {string} opts3.x
59+
*/
60+
function foo3(opts3) {
61+
>foo3 : Symbol(foo3, Decl(0.js, 31, 28))
62+
>opts3 : Symbol(opts3, Decl(0.js, 37, 14))
63+
64+
opts3.x;
65+
>opts3.x : Symbol(x, Decl(0.js, 35, 3))
66+
>opts3 : Symbol(opts3, Decl(0.js, 37, 14))
67+
>x : Symbol(x, Decl(0.js, 35, 3))
68+
}
69+
foo3({x: 'abc'});
70+
>foo3 : Symbol(foo3, Decl(0.js, 31, 28))
71+
>x : Symbol(x, Decl(0.js, 40, 6))
72+
73+
/**
74+
* @param {object[]} opts4
75+
* @param {string} opts4[].x
76+
* @param {string=} opts4[].y
77+
* @param {string} [opts4[].z]
78+
* @param {string} [opts4[].w="hi"]
79+
*/
80+
function foo4(opts4) {
81+
>foo4 : Symbol(foo4, Decl(0.js, 40, 17))
82+
>opts4 : Symbol(opts4, Decl(0.js, 49, 14))
83+
84+
opts4[0].x;
85+
>opts4[0].x : Symbol(x, Decl(0.js, 44, 3))
86+
>opts4 : Symbol(opts4, Decl(0.js, 49, 14))
87+
>x : Symbol(x, Decl(0.js, 44, 3))
88+
}
89+
90+
foo4([{ x: 'hi' }]);
91+
>foo4 : Symbol(foo4, Decl(0.js, 40, 17))
92+
>x : Symbol(x, Decl(0.js, 53, 7))
93+
94+
/**
95+
* @param {object[]} opts5 - Let's test out some multiple nesting levels
96+
* @param {string} opts5[].help - (This one is just normal)
97+
* @param {object} opts5[].what - Look at us go! Here's the first nest!
98+
* @param {string} opts5[].what.a - (Another normal one)
99+
* @param {Object[]} opts5[].what.bad - Now we're nesting inside a nested type
100+
* @param {string} opts5[].what.bad[].idea - I don't think you can get back out of this level...
101+
* @param {boolean} opts5[].what.bad[].oh - Oh ... that's how you do it.
102+
* @param {number} opts5[].unnest - Here we are almost all the way back at the beginning.
103+
*/
104+
function foo5(opts5) {
105+
>foo5 : Symbol(foo5, Decl(0.js, 53, 20))
106+
>opts5 : Symbol(opts5, Decl(0.js, 65, 14))
107+
108+
opts5[0].what.bad[0].idea;
109+
>opts5[0].what.bad[0].idea : Symbol(idea, Decl(0.js, 61, 3))
110+
>opts5[0].what.bad : Symbol(bad, Decl(0.js, 60, 3))
111+
>opts5[0].what : Symbol(what, Decl(0.js, 58, 3))
112+
>opts5 : Symbol(opts5, Decl(0.js, 65, 14))
113+
>what : Symbol(what, Decl(0.js, 58, 3))
114+
>bad : Symbol(bad, Decl(0.js, 60, 3))
115+
>idea : Symbol(idea, Decl(0.js, 61, 3))
116+
117+
opts5[0].unnest;
118+
>opts5[0].unnest : Symbol(unnest, Decl(0.js, 63, 3))
119+
>opts5 : Symbol(opts5, Decl(0.js, 65, 14))
120+
>unnest : Symbol(unnest, Decl(0.js, 63, 3))
121+
}
122+
123+
foo5([{ help: "help", what: { a: 'a', bad: [{ idea: 'idea', oh: false }] }, unnest: 1 }]);
124+
>foo5 : Symbol(foo5, Decl(0.js, 53, 20))
125+
>help : Symbol(help, Decl(0.js, 70, 7))
126+
>what : Symbol(what, Decl(0.js, 70, 21))
127+
>a : Symbol(a, Decl(0.js, 70, 29))
128+
>bad : Symbol(bad, Decl(0.js, 70, 37))
129+
>idea : Symbol(idea, Decl(0.js, 70, 45))
130+
>oh : Symbol(oh, Decl(0.js, 70, 59))
131+
>unnest : Symbol(unnest, Decl(0.js, 70, 75))
132+
133+
// TODO: Also write these ridiculous object[] / nested tests for @typedef as well
134+
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
=== tests/cases/conformance/jsdoc/0.js ===
2+
/**
3+
* @param {Object} notSpecial
4+
* @param {string} unrelated - not actually related because it's not notSpecial.unrelated
5+
*/
6+
function normal(notSpecial) {
7+
>normal : (notSpecial: any) => void
8+
>notSpecial : any
9+
10+
notSpecial; // should just be 'any'
11+
>notSpecial : any
12+
}
13+
normal(12);
14+
>normal(12) : void
15+
>normal : (notSpecial: any) => void
16+
>12 : 12
17+
18+
/**
19+
* @param {Object} opts1 doc1
20+
* @param {string} opts1.x doc2
21+
* @param {string=} opts1.y doc3
22+
* @param {string} [opts1.z] doc4
23+
* @param {string} [opts1.w="hi"] doc5
24+
*/
25+
function foo1(opts1) {
26+
>foo1 : (opts1: { x: string; y?: string; z?: string; w?: string; }) => void
27+
>opts1 : { x: string; y?: string; z?: string; w?: string; }
28+
29+
opts1.x;
30+
>opts1.x : string
31+
>opts1 : { x: string; y?: string; z?: string; w?: string; }
32+
>x : string
33+
}
34+
35+
foo1({x: 'abc'});
36+
>foo1({x: 'abc'}) : void
37+
>foo1 : (opts1: { x: string; y?: string; z?: string; w?: string; }) => void
38+
>{x: 'abc'} : { x: string; }
39+
>x : string
40+
>'abc' : "abc"
41+
42+
/**
43+
* @param {Object[]} opts2
44+
* @param {string} opts2[].anotherX
45+
* @param {string=} opts2[].anotherY
46+
*/
47+
function foo2(/** @param opts2 bad idea theatre! */opts2) {
48+
>foo2 : (opts2: { anotherX: string; anotherY?: string; }[]) => void
49+
>opts2 : { anotherX: string; anotherY?: string; }[]
50+
51+
opts2[0].anotherX;
52+
>opts2[0].anotherX : string
53+
>opts2[0] : { anotherX: string; anotherY?: string; }
54+
>opts2 : { anotherX: string; anotherY?: string; }[]
55+
>0 : 0
56+
>anotherX : string
57+
}
58+
59+
foo2([{anotherX: "world"}]);
60+
>foo2([{anotherX: "world"}]) : void
61+
>foo2 : (opts2: { anotherX: string; anotherY?: string; }[]) => void
62+
>[{anotherX: "world"}] : { anotherX: string; }[]
63+
>{anotherX: "world"} : { anotherX: string; }
64+
>anotherX : string
65+
>"world" : "world"
66+
67+
/**
68+
* @param {object} opts3
69+
* @param {string} opts3.x
70+
*/
71+
function foo3(opts3) {
72+
>foo3 : (opts3: { x: string; }) => void
73+
>opts3 : { x: string; }
74+
75+
opts3.x;
76+
>opts3.x : string
77+
>opts3 : { x: string; }
78+
>x : string
79+
}
80+
foo3({x: 'abc'});
81+
>foo3({x: 'abc'}) : void
82+
>foo3 : (opts3: { x: string; }) => void
83+
>{x: 'abc'} : { x: string; }
84+
>x : string
85+
>'abc' : "abc"
86+
87+
/**
88+
* @param {object[]} opts4
89+
* @param {string} opts4[].x
90+
* @param {string=} opts4[].y
91+
* @param {string} [opts4[].z]
92+
* @param {string} [opts4[].w="hi"]
93+
*/
94+
function foo4(opts4) {
95+
>foo4 : (opts4: { x: string; y?: string; z?: string; w?: string; }[]) => void
96+
>opts4 : { x: string; y?: string; z?: string; w?: string; }[]
97+
98+
opts4[0].x;
99+
>opts4[0].x : string
100+
>opts4[0] : { x: string; y?: string; z?: string; w?: string; }
101+
>opts4 : { x: string; y?: string; z?: string; w?: string; }[]
102+
>0 : 0
103+
>x : string
104+
}
105+
106+
foo4([{ x: 'hi' }]);
107+
>foo4([{ x: 'hi' }]) : void
108+
>foo4 : (opts4: { x: string; y?: string; z?: string; w?: string; }[]) => void
109+
>[{ x: 'hi' }] : { x: string; }[]
110+
>{ x: 'hi' } : { x: string; }
111+
>x : string
112+
>'hi' : "hi"
113+
114+
/**
115+
* @param {object[]} opts5 - Let's test out some multiple nesting levels
116+
* @param {string} opts5[].help - (This one is just normal)
117+
* @param {object} opts5[].what - Look at us go! Here's the first nest!
118+
* @param {string} opts5[].what.a - (Another normal one)
119+
* @param {Object[]} opts5[].what.bad - Now we're nesting inside a nested type
120+
* @param {string} opts5[].what.bad[].idea - I don't think you can get back out of this level...
121+
* @param {boolean} opts5[].what.bad[].oh - Oh ... that's how you do it.
122+
* @param {number} opts5[].unnest - Here we are almost all the way back at the beginning.
123+
*/
124+
function foo5(opts5) {
125+
>foo5 : (opts5: { help: string; what: { a: string; bad: { idea: string; oh: boolean; }[]; }; unnest: number; }[]) => void
126+
>opts5 : { help: string; what: { a: string; bad: { idea: string; oh: boolean; }[]; }; unnest: number; }[]
127+
128+
opts5[0].what.bad[0].idea;
129+
>opts5[0].what.bad[0].idea : string
130+
>opts5[0].what.bad[0] : { idea: string; oh: boolean; }
131+
>opts5[0].what.bad : { idea: string; oh: boolean; }[]
132+
>opts5[0].what : { a: string; bad: { idea: string; oh: boolean; }[]; }
133+
>opts5[0] : { help: string; what: { a: string; bad: { idea: string; oh: boolean; }[]; }; unnest: number; }
134+
>opts5 : { help: string; what: { a: string; bad: { idea: string; oh: boolean; }[]; }; unnest: number; }[]
135+
>0 : 0
136+
>what : { a: string; bad: { idea: string; oh: boolean; }[]; }
137+
>bad : { idea: string; oh: boolean; }[]
138+
>0 : 0
139+
>idea : string
140+
141+
opts5[0].unnest;
142+
>opts5[0].unnest : number
143+
>opts5[0] : { help: string; what: { a: string; bad: { idea: string; oh: boolean; }[]; }; unnest: number; }
144+
>opts5 : { help: string; what: { a: string; bad: { idea: string; oh: boolean; }[]; }; unnest: number; }[]
145+
>0 : 0
146+
>unnest : number
147+
}
148+
149+
foo5([{ help: "help", what: { a: 'a', bad: [{ idea: 'idea', oh: false }] }, unnest: 1 }]);
150+
>foo5([{ help: "help", what: { a: 'a', bad: [{ idea: 'idea', oh: false }] }, unnest: 1 }]) : void
151+
>foo5 : (opts5: { help: string; what: { a: string; bad: { idea: string; oh: boolean; }[]; }; unnest: number; }[]) => void
152+
>[{ help: "help", what: { a: 'a', bad: [{ idea: 'idea', oh: false }] }, unnest: 1 }] : { help: string; what: { a: string; bad: { idea: string; oh: false; }[]; }; unnest: number; }[]
153+
>{ help: "help", what: { a: 'a', bad: [{ idea: 'idea', oh: false }] }, unnest: 1 } : { help: string; what: { a: string; bad: { idea: string; oh: false; }[]; }; unnest: number; }
154+
>help : string
155+
>"help" : "help"
156+
>what : { a: string; bad: { idea: string; oh: false; }[]; }
157+
>{ a: 'a', bad: [{ idea: 'idea', oh: false }] } : { a: string; bad: { idea: string; oh: false; }[]; }
158+
>a : string
159+
>'a' : "a"
160+
>bad : { idea: string; oh: false; }[]
161+
>[{ idea: 'idea', oh: false }] : { idea: string; oh: false; }[]
162+
>{ idea: 'idea', oh: false } : { idea: string; oh: false; }
163+
>idea : string
164+
>'idea' : "idea"
165+
>oh : boolean
166+
>false : false
167+
>unnest : number
168+
>1 : 1
169+
170+
// TODO: Also write these ridiculous object[] / nested tests for @typedef as well
171+
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// @allowJS: true
2+
// @checkJs: true
3+
// @noEmit: true
4+
// @strict: true
5+
// @suppressOutputPathCheck: true
6+
7+
// @Filename: 0.js
8+
/**
9+
* @param {Object} notSpecial
10+
* @param {string} unrelated - not actually related because it's not notSpecial.unrelated
11+
*/
12+
function normal(notSpecial) {
13+
notSpecial; // should just be 'any'
14+
}
15+
normal(12);
16+
17+
/**
18+
* @param {Object} opts1 doc1
19+
* @param {string} opts1.x doc2
20+
* @param {string=} opts1.y doc3
21+
* @param {string} [opts1.z] doc4
22+
* @param {string} [opts1.w="hi"] doc5
23+
*/
24+
function foo1(opts1) {
25+
opts1.x;
26+
}
27+
28+
foo1({x: 'abc'});
29+
30+
/**
31+
* @param {Object[]} opts2
32+
* @param {string} opts2[].anotherX
33+
* @param {string=} opts2[].anotherY
34+
*/
35+
function foo2(/** @param opts2 bad idea theatre! */opts2) {
36+
opts2[0].anotherX;
37+
}
38+
39+
foo2([{anotherX: "world"}]);
40+
41+
/**
42+
* @param {object} opts3
43+
* @param {string} opts3.x
44+
*/
45+
function foo3(opts3) {
46+
opts3.x;
47+
}
48+
foo3({x: 'abc'});
49+
50+
/**
51+
* @param {object[]} opts4
52+
* @param {string} opts4[].x
53+
* @param {string=} opts4[].y
54+
* @param {string} [opts4[].z]
55+
* @param {string} [opts4[].w="hi"]
56+
*/
57+
function foo4(opts4) {
58+
opts4[0].x;
59+
}
60+
61+
foo4([{ x: 'hi' }]);
62+
63+
/**
64+
* @param {object[]} opts5 - Let's test out some multiple nesting levels
65+
* @param {string} opts5[].help - (This one is just normal)
66+
* @param {object} opts5[].what - Look at us go! Here's the first nest!
67+
* @param {string} opts5[].what.a - (Another normal one)
68+
* @param {Object[]} opts5[].what.bad - Now we're nesting inside a nested type
69+
* @param {string} opts5[].what.bad[].idea - I don't think you can get back out of this level...
70+
* @param {boolean} opts5[].what.bad[].oh - Oh ... that's how you do it.
71+
* @param {number} opts5[].unnest - Here we are almost all the way back at the beginning.
72+
*/
73+
function foo5(opts5) {
74+
opts5[0].what.bad[0].idea;
75+
opts5[0].unnest;
76+
}
77+
78+
foo5([{ help: "help", what: { a: 'a', bad: [{ idea: 'idea', oh: false }] }, unnest: 1 }]);
79+
80+
// TODO: Also write these ridiculous object[] / nested tests for @typedef as well

0 commit comments

Comments
 (0)