@@ -326,13 +326,13 @@ function _iterateDocTypes(node, cb) {
326
326
// unknown: boolean,
327
327
// types: Array.<TypeName|GenericType|FunctionType|RecordType>
328
328
res = node . types . map ( function ( subnode ) {
329
- if ( node . selfNode ) {
330
- subnode . parentNode = node . selfNode ;
329
+ if ( node . collectionNode ) {
330
+ subnode . parentNode = node . collectionNode ;
331
331
}
332
332
return _iterateDocTypes ( subnode , cb ) ;
333
333
} ) || [ ] ;
334
334
if ( node . nullable ) {
335
- var subnode = { typeName : 'null' , parentNode : node } ;
335
+ var subnode = { typeName : 'null' , collectionNode : node } ;
336
336
res . concat ( cb ( subnode ) ) ;
337
337
}
338
338
break ;
@@ -346,11 +346,14 @@ function _iterateDocTypes(node, cb) {
346
346
case node instanceof TypeBuilder . GenericType :
347
347
// genericTypeName: string,
348
348
// parameterTypeUnions: Array.<TypeUnion>
349
- node . typeName = node . genericTypeName ;
350
- res = cb ( node ) ;
349
+ node . typeName = node . genericTypeName . type ;
350
+ res = cb ( node ) || [ ] ;
351
351
if ( node . parameterTypeUnions ) {
352
- node . parameterTypeUnions . selfNode = node ;
353
- res . concat ( _iterateDocTypes ( node . parameterTypeUnions , cb ) ) ;
352
+ // node.parameterTypeUnions.collectionNode = node;
353
+ res . concat ( node . parameterTypeUnions . map ( function ( subnode ) {
354
+ subnode . parentNode = node ;
355
+ _iterateDocTypes ( subnode , cb ) ;
356
+ } ) ) ;
354
357
}
355
358
break ;
356
359
@@ -366,11 +369,11 @@ function _iterateDocTypes(node, cb) {
366
369
_iterateDocTypes ( subnode , cb ) ;
367
370
} ) ) ;
368
371
if ( node . returnTypeUnion ) {
369
- node . returnTypeUnion . selfNode = node ;
372
+ node . returnTypeUnion . collectionNode = node ;
370
373
res . concat ( _iterateDocTypes ( node . returnTypeUnion , cb ) ) ;
371
374
}
372
375
if ( node . contextTypeUnion ) {
373
- node . contextTypeUnion . selfNode = node ;
376
+ node . contextTypeUnion . collectionNode = node ;
374
377
res . concat ( _iterateDocTypes ( node . contextTypeUnion , cb ) ) ;
375
378
}
376
379
break ;
@@ -390,7 +393,7 @@ function _iterateDocTypes(node, cb) {
390
393
case node instanceof TypeBuilder . RecordType . Entry :
391
394
// name: string,
392
395
// typeUnion: TypeUnion
393
- node . typeUnion . selfNode = node ;
396
+ node . typeUnion . collectionNode = node ;
394
397
res = _iterateDocTypes ( node . typeUnion , cb ) ;
395
398
break ;
396
399
@@ -415,68 +418,11 @@ function _iterateDocTypes(node, cb) {
415
418
*/
416
419
function _simplifyType ( node ) {
417
420
var res = [ ] ;
418
-
419
- switch ( true ) {
420
- case node instanceof TypeBuilder . TypeUnion :
421
- // optional: boolean,
422
- // nullable: boolean,
423
- // variable: boolean,
424
- // nonNullable: boolean,
425
- // all: boolean,
426
- // unknown: boolean,
427
- // types: Array.<TypeName|GenericType|FunctionType|RecordType>
428
- res = node . types . map ( _simplifyType ) ;
429
- if ( node . nullable ) {
430
- res . push ( { type : 'null' } ) ;
421
+ _iterateDocTypes ( node , function ( type ) {
422
+ if ( ! type . parentNode && ( ! type . collectionNode || ! type . collectionNode . parentNode ) ) {
423
+ res . push ( { type : type . typeName } ) ;
431
424
}
432
- break ;
433
-
434
- case node instanceof TypeBuilder . TypeName :
435
- // name: string
436
- res = { type : node . name } ;
437
- break ;
438
-
439
- case node instanceof TypeBuilder . GenericType :
440
- // genericTypeName: string,
441
- // parameterTypeUnions: Array.<TypeUnion>
442
- res = { type : node . genericTypeName . type } ;
443
- // node.parameterTypeUnions.map(_simplifyType);
444
- break ;
445
-
446
- case node instanceof TypeBuilder . FunctionType :
447
- // parameterTypeUnions: Array.<TypeUnion>,
448
- // returnTypeUnion: TypeUnion|null,
449
- // isConstructor: boolean,
450
- // contextTypeUnion: TypeUnion|null
451
- res = { type : 'function' } ;
452
- // node.parameterTypeUnions.map(_simplifyType);
453
- // if (node.returnTypeUnion) {
454
- // _simplifyType(node.returnTypeUnion);
455
- // }
456
- // if (node.contextTypeUnion) {
457
- // _simplifyType(node.contextTypeUnion);
458
- // }
459
- break ;
460
-
461
- case node instanceof TypeBuilder . RecordType :
462
- // entries: Array.<RecordEntry>
463
- res = { type : 'object' } ; // node.entries.map(_simplifyType);
464
- break ;
465
-
466
- case node instanceof TypeBuilder . RecordType . Entry :
467
- // name: string,
468
- // typeUnion: TypeUnion
469
- res = _simplifyType ( node . typeUnion ) ;
470
- break ;
471
-
472
- case node instanceof TypeBuilder . ModuleName :
473
- res = { type : node . name , module : true } ;
474
- break ;
475
-
476
- default :
477
- throw new Error ( 'DocType: Unsupported doc node' ) ;
478
- }
479
-
425
+ } ) ;
480
426
return res ;
481
427
}
482
428
0 commit comments