@@ -443,6 +443,8 @@ class Asserter extends Stringifier {
443
443
// ${JSON.stringify(jsdoc)}\n${parent}\n${spaces}*/\n`;
444
444
for ( let name in params ) {
445
445
const type = params [ name ] ;
446
+ // Copy name for warnings, `name` may become `arguments[${paramIndex}]`.
447
+ const nameFancy = name ;
446
448
const hasParam = this . nodeHasParamName ( node , name ) ;
447
449
if ( ! hasParam ) {
448
450
let testNode = node ;
@@ -480,47 +482,53 @@ class Asserter extends Stringifier {
480
482
}
481
483
const t = JSON . stringify ( type . elementType , null , 2 ) . replaceAll ( '\n' , '\n' + spaces ) ;
482
484
if ( templates ) {
483
- out += `${ spaces } if (!inspectTypeWithTemplates(${ element . name } , ${ t } , '${ loc } ', '${ name } ', rtiTemplates)) {\n` ;
485
+ out += `${ spaces } if (!inspectTypeWithTemplates(${ element . name } , ${ t } , '${ loc } ', '${ nameFancy } ', rtiTemplates)) {\n` ;
484
486
} else {
485
- out += `${ spaces } if (!inspectType(${ element . name } , ${ t } , '${ loc } ', '${ name } ')) {\n` ;
487
+ out += `${ spaces } if (!inspectType(${ element . name } , ${ t } , '${ loc } ', '${ nameFancy } ')) {\n` ;
486
488
}
487
489
out += `${ spaces } youCanAddABreakpointHere();\n${ spaces } }\n` ;
488
490
}
489
491
continue ;
490
- } else if ( param . left . type === 'ObjectPattern' && type . type === 'object' ) {
491
- // Add a type assertion for each property of the ObjectPattern
492
- for ( const property of param . left . properties ) {
493
- if ( property . key . type !== 'Identifier' ) {
494
- this . warn ( 'ObjectPattern> Only Identifier case handled right now' ) ;
495
- continue ;
496
- }
497
- const keyName = property . key . name ;
498
- if ( type . type !== 'object' || ! type . properties ) {
499
- this . warn (
500
- "missing subtype information in JSDoc> in type" ,
501
- JSON . stringify ( type , null , 2 ) ,
502
- "for ObjectPattern:" , this . toSource ( property ) . trim ( )
503
- ) ;
504
- continue ;
505
- }
506
- const subType = type . properties [ keyName ] ;
507
- if ( ! subType ) {
508
- this . warn ( "missing subtype information in JSDoc" ) ;
509
- continue ;
492
+ } else if ( param . left . type === 'ObjectPattern' ) {
493
+ if ( type . type === 'object' ) {
494
+ // Add a type assertion for each property of the ObjectPattern
495
+ for ( const property of param . left . properties ) {
496
+ if ( property . key . type !== 'Identifier' ) {
497
+ this . warn ( 'ObjectPattern> Only Identifier case handled right now' ) ;
498
+ continue ;
499
+ }
500
+ const keyName = property . key . name ;
501
+ if ( type . type !== 'object' || ! type . properties ) {
502
+ this . warn (
503
+ "missing subtype information in JSDoc> in type" ,
504
+ JSON . stringify ( type , null , 2 ) ,
505
+ "for ObjectPattern:" , this . toSource ( property ) . trim ( )
506
+ ) ;
507
+ continue ;
508
+ }
509
+ const subType = type . properties [ keyName ] ;
510
+ if ( ! subType ) {
511
+ this . warn ( "missing subtype information in JSDoc" ) ;
512
+ continue ;
513
+ }
514
+ const t = JSON . stringify ( subType , null , 2 ) . replaceAll ( '\n' , '\n' + spaces ) ;
515
+ if ( templates ) {
516
+ out += `${ spaces } if (!inspectTypeWithTemplates(${ keyName } , ${ t } , '${ loc } ', '${ nameFancy } ', rtiTemplates)) {\n` ;
517
+ } else {
518
+ out += `${ spaces } if (!inspectType(${ keyName } , ${ t } , '${ loc } ', '${ nameFancy } ')) {\n` ;
519
+ }
520
+ out += `${ spaces } youCanAddABreakpointHere();\n${ spaces } }\n` ;
510
521
}
511
- const t = JSON . stringify ( subType , null , 2 ) . replaceAll ( '\n' , '\n' + spaces ) ;
512
- if ( templates ) {
513
- out += `${ spaces } if (!inspectTypeWithTemplates(${ keyName } , ${ t } , '${ loc } ', '${ name } ', rtiTemplates)) {\n` ;
514
- } else {
515
- out += `${ spaces } if (!inspectType(${ keyName } , ${ t } , '${ loc } ', '${ name } ')) {\n` ;
516
- }
517
- out += `${ spaces } youCanAddABreakpointHere();\n${ spaces } }\n` ;
522
+ continue ;
523
+ } else if ( typeof type === 'string' ) {
524
+ // The case when we have an ObjectPattern with a @typedef
525
+ name = `arguments[${ paramIndex } ]` ;
518
526
}
527
+ } else {
528
+ this . warn ( `generateTypeChecks> ${ loc } > todo implement` ,
529
+ `AssignmentPattern for parameter ${ name } ` ) ;
519
530
continue ;
520
531
}
521
- this . warn ( `generateTypeChecks> ${ loc } > todo implement` ,
522
- `AssignmentPattern for parameter ${ name } ` ) ;
523
- continue ;
524
532
}
525
533
} else {
526
534
const loc = this . getName ( node ) ;
@@ -552,9 +560,9 @@ class Asserter extends Stringifier {
552
560
first = false ;
553
561
}
554
562
if ( templates ) {
555
- out += `${ spaces } if (${ prevCheck } !inspectTypeWithTemplates(${ name } , ${ t } , '${ loc } ', '${ name } ', rtiTemplates)) {\n` ;
563
+ out += `${ spaces } if (${ prevCheck } !inspectTypeWithTemplates(${ name } , ${ t } , '${ loc } ', '${ nameFancy } ', rtiTemplates)) {\n` ;
556
564
} else {
557
- out += `${ spaces } if (${ prevCheck } !inspectType(${ name } , ${ t } , '${ loc } ', '${ name } ')) {\n` ;
565
+ out += `${ spaces } if (${ prevCheck } !inspectType(${ name } , ${ t } , '${ loc } ', '${ nameFancy } ')) {\n` ;
558
566
}
559
567
out += `${ spaces } youCanAddABreakpointHere();\n${ spaces } }\n` ;
560
568
}
0 commit comments