@@ -37,39 +37,42 @@ const setTagStructure = (mode) => {
37
37
tagStructure = getDefaultTagStructureForMode ( mode ) ;
38
38
} ;
39
39
40
- /**
41
- * @typedef {{
42
- * hasPropertyRest: boolean,
43
- * hasRestElement: boolean,
44
- * names: string[],
45
- * rests: boolean[],
46
- * }} FlattendRootInfo
47
- */
48
-
49
40
/**
50
41
* @typedef {undefined|string|{
42
+ * name: Integer,
43
+ * restElement: boolean
44
+ * }|{
51
45
* isRestProperty: boolean|undefined,
52
46
* name: string,
53
- * restElement: true
54
- * }|[undefined|string, FlattendRootInfo & {
55
- * annotationParamName?: string
47
+ * restElement: boolean
56
48
* }|{
57
- * name: Integer ,
49
+ * name: string ,
58
50
* restElement: boolean
59
- * }[]]} ParamNameInfo
51
+ * }} ParamCommon
52
+ */
53
+ /**
54
+ * @typedef {ParamCommon|[string|undefined, (FlattendRootInfo & {
55
+ * annotationParamName?: string,
56
+ * })]|NestedParamInfo} ParamNameInfo
60
57
*/
61
58
62
59
/**
63
- * @typedef {undefined|string|{
64
- * isRestProperty: boolean,
65
- * restElement: boolean,
66
- * name: string
67
- * }|[string, {
60
+ * @typedef {{
68
61
* hasPropertyRest: boolean,
69
62
* hasRestElement: boolean,
70
63
* names: string[],
71
64
* rests: boolean[],
72
- * }]|[string, string[]]} ParamInfo
65
+ * }} FlattendRootInfo
66
+ */
67
+ /**
68
+ * @typedef {[string, (string[]|ParamInfo[])] } NestedParamInfo
69
+ */
70
+ /**
71
+ * @typedef {ParamCommon|
72
+ * [string|undefined, (FlattendRootInfo & {
73
+ * annotationParamName?: string
74
+ * })]|
75
+ * NestedParamInfo} ParamInfo
73
76
*/
74
77
75
78
/**
@@ -123,28 +126,28 @@ const flattenRoots = (params, root = '') => {
123
126
hasPropertyRest = true ;
124
127
}
125
128
126
- const inner = [
129
+ const inner = /** @type { string[] } */ ( [
127
130
root ? `${ root } .${ cur [ 0 ] } ` : cur [ 0 ] ,
128
131
...flattened . names ,
129
- ] . filter ( Boolean ) ;
132
+ ] . filter ( Boolean ) ) ;
130
133
rests . push ( false , ...flattened . rests ) ;
131
134
132
135
return acc . concat ( inner ) ;
133
136
}
134
137
135
138
if ( typeof cur === 'object' ) {
136
- if ( cur . isRestProperty ) {
139
+ if ( 'isRestProperty' in cur && cur . isRestProperty ) {
137
140
hasPropertyRest = true ;
138
141
rests . push ( true ) ;
139
142
} else {
140
143
rests . push ( false ) ;
141
144
}
142
145
143
- if ( cur . restElement ) {
146
+ if ( 'restElement' in cur && cur . restElement ) {
144
147
hasRestElement = true ;
145
148
}
146
149
147
- acc . push ( root ? `${ root } .${ cur . name } ` : cur . name ) ;
150
+ acc . push ( root ? `${ root } .${ String ( cur . name ) } ` : String ( cur . name ) ) ;
148
151
} else if ( typeof cur !== 'undefined' ) {
149
152
rests . push ( false ) ;
150
153
acc . push ( root ? `${ root } .${ cur } ` : cur ) ;
@@ -219,10 +222,11 @@ const getFunctionParameterNames = (
219
222
* import('@typescript-eslint/types').TSESTree.RestElement|
220
223
* import('@typescript-eslint/types').TSESTree.Identifier|
221
224
* import('@typescript-eslint/types').TSESTree.ObjectPattern|
222
- * import('@typescript-eslint/types').TSESTree.BindingName
225
+ * import('@typescript-eslint/types').TSESTree.BindingName|
226
+ * import('@typescript-eslint/types').TSESTree.Parameter
223
227
* } param
224
228
* @param {boolean } [isProperty]
225
- * @returns {ParamNameInfo }
229
+ * @returns {ParamNameInfo|[string, ParamNameInfo[]] }
226
230
*/
227
231
const getParamName = ( param , isProperty ) => {
228
232
/* eslint-enable complexity -- Temporary */
@@ -305,9 +309,10 @@ const getFunctionParameterNames = (
305
309
if ( param . type === 'Property' ) {
306
310
// eslint-disable-next-line default-case
307
311
switch ( param . value . type ) {
308
- case 'ArrayPattern' :
312
+ case 'ArrayPattern' : {
309
313
return [
310
- param . key . name ,
314
+ /** @type {import('estree').Identifier } */
315
+ ( param . key ) . name ,
311
316
/** @type {import('estree').ArrayPattern } */ (
312
317
param . value
313
318
) . elements . map ( ( prop , idx ) => {
@@ -317,42 +322,57 @@ const getFunctionParameterNames = (
317
322
} ;
318
323
} ) ,
319
324
] ;
320
- case 'ObjectPattern' :
325
+ }
326
+
327
+ case 'ObjectPattern' : {
321
328
return [
322
- param . key . name ,
329
+ /** @type { import('estree').Identifier } */ ( param . key ) . name ,
323
330
/** @type {import('estree').ObjectPattern } */ (
324
331
param . value
325
332
) . properties . map ( ( prop ) => {
326
- return getParamName ( prop , isProperty ) ;
333
+ return /** @type { string|[string, string[]] } */ ( getParamName ( prop , isProperty ) ) ;
327
334
} ) ,
328
335
] ;
336
+ }
337
+
329
338
case 'AssignmentPattern' : {
330
339
// eslint-disable-next-line default-case
331
340
switch ( param . value . left . type ) {
332
341
case 'Identifier' :
333
342
// Default parameter
334
343
if ( checkDefaultObjects && param . value . right . type === 'ObjectExpression' ) {
335
344
return [
336
- param . key . name , /** @type {import('estree').AssignmentPattern } */ (
345
+ /** @type {import('estree').Identifier } */ (
346
+ param . key
347
+ ) . name ,
348
+ /** @type {import('estree').AssignmentPattern } */ (
337
349
param . value
338
350
) . right . properties . map ( ( prop ) => {
339
- return getParamName ( prop , isProperty ) ;
351
+ return /** @type {string } */ ( getParamName (
352
+ /** @type {import('estree').Property } */
353
+ ( prop ) ,
354
+ isProperty ,
355
+ ) ) ;
340
356
} ) ,
341
357
] ;
342
358
}
343
359
344
360
break ;
345
361
case 'ObjectPattern' :
346
362
return [
347
- param . key . name , /** @type {import('estree').ObjectPattern } */ (
363
+ /** @type {import('estree').Identifier } */
364
+ ( param . key ) . name ,
365
+ /** @type {import('estree').ObjectPattern } */ (
348
366
param . value . left
349
367
) . properties . map ( ( prop ) => {
350
368
return getParamName ( prop , isProperty ) ;
351
369
} ) ,
352
370
] ;
353
371
case 'ArrayPattern' :
354
372
return [
355
- param . key . name , /** @type {import('estree').ArrayPattern } */ (
373
+ /** @type {import('estree').Identifier } */
374
+ ( param . key ) . name ,
375
+ /** @type {import('estree').ArrayPattern } */ (
356
376
param . value . left
357
377
) . elements . map ( ( prop , idx ) => {
358
378
return {
@@ -371,9 +391,9 @@ const getFunctionParameterNames = (
371
391
372
392
// The key of an object could also be a string or number
373
393
case 'Literal' :
374
- return param . key . raw ||
394
+ return /** @type { string } */ ( param . key . raw ||
375
395
// istanbul ignore next -- `raw` may not be present in all parsers
376
- param . key . value ;
396
+ param . key . value ) ;
377
397
378
398
// case 'MemberExpression':
379
399
default :
@@ -385,11 +405,18 @@ const getFunctionParameterNames = (
385
405
}
386
406
}
387
407
388
- if ( param . type === 'ArrayPattern' || param . left ?. type === 'ArrayPattern' ) {
408
+ if (
409
+ param . type === 'ArrayPattern' ||
410
+ /** @type {import('estree').AssignmentPattern } */ (
411
+ param
412
+ ) . left ?. type === 'ArrayPattern'
413
+ ) {
389
414
const elements = /** @type {import('estree').ArrayPattern } */ (
390
415
param
391
416
) . elements || /** @type {import('estree').ArrayPattern } */ (
392
- param . left
417
+ /** @type {import('estree').AssignmentPattern } */ (
418
+ param
419
+ ) . left
393
420
) ?. elements ;
394
421
const roots = elements . map ( ( prop , idx ) => {
395
422
return {
@@ -408,7 +435,10 @@ const getFunctionParameterNames = (
408
435
] . includes ( param . type ) ) {
409
436
return {
410
437
isRestProperty : isProperty ,
411
- name : param . argument . name ,
438
+ name : /** @type {import('@typescript-eslint/types').TSESTree.Identifier } */ (
439
+ /** @type {import('@typescript-eslint/types').TSESTree.RestElement } */ (
440
+ param
441
+ ) . argument ) . name ,
412
442
restElement : true ,
413
443
} ;
414
444
}
@@ -431,7 +461,11 @@ const getFunctionParameterNames = (
431
461
return [ ] ;
432
462
}
433
463
434
- return ( functionNode . params || functionNode . value ?. params || [ ] ) . map ( ( param ) => {
464
+ return ( /** @type {import('@typescript-eslint/types').TSESTree.FunctionDeclaration } */ (
465
+ functionNode
466
+ ) . params || /** @type {import('@typescript-eslint/types').TSESTree.MethodDefinition } */ (
467
+ functionNode
468
+ ) . value ?. params || [ ] ) . map ( ( param ) => {
435
469
return getParamName ( param ) ;
436
470
} ) ;
437
471
} ;
@@ -1570,7 +1604,7 @@ const dropPathSegmentQuotes = (str) => {
1570
1604
1571
1605
/**
1572
1606
* @param {string } name
1573
- * @returns {(otherPathName: string) => void }
1607
+ * @returns {(otherPathName: string) => boolean }
1574
1608
*/
1575
1609
const comparePaths = ( name ) => {
1576
1610
return ( otherPathName ) => {
0 commit comments