@@ -326,13 +326,13 @@ function _iterateDocTypes(node, cb) {
326326 // unknown: boolean,
327327 // types: Array.<TypeName|GenericType|FunctionType|RecordType>
328328 res = node . types . map ( function ( subnode ) {
329- if ( node . selfNode ) {
330- subnode . parentNode = node . selfNode ;
329+ if ( node . collectionNode ) {
330+ subnode . parentNode = node . collectionNode ;
331331 }
332332 return _iterateDocTypes ( subnode , cb ) ;
333333 } ) || [ ] ;
334334 if ( node . nullable ) {
335- var subnode = { typeName : 'null' , parentNode : node } ;
335+ var subnode = { typeName : 'null' , collectionNode : node } ;
336336 res . concat ( cb ( subnode ) ) ;
337337 }
338338 break ;
@@ -346,11 +346,14 @@ function _iterateDocTypes(node, cb) {
346346 case node instanceof TypeBuilder . GenericType :
347347 // genericTypeName: string,
348348 // parameterTypeUnions: Array.<TypeUnion>
349- node . typeName = node . genericTypeName ;
350- res = cb ( node ) ;
349+ node . typeName = node . genericTypeName . type ;
350+ res = cb ( node ) || [ ] ;
351351 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+ } ) ) ;
354357 }
355358 break ;
356359
@@ -366,11 +369,11 @@ function _iterateDocTypes(node, cb) {
366369 _iterateDocTypes ( subnode , cb ) ;
367370 } ) ) ;
368371 if ( node . returnTypeUnion ) {
369- node . returnTypeUnion . selfNode = node ;
372+ node . returnTypeUnion . collectionNode = node ;
370373 res . concat ( _iterateDocTypes ( node . returnTypeUnion , cb ) ) ;
371374 }
372375 if ( node . contextTypeUnion ) {
373- node . contextTypeUnion . selfNode = node ;
376+ node . contextTypeUnion . collectionNode = node ;
374377 res . concat ( _iterateDocTypes ( node . contextTypeUnion , cb ) ) ;
375378 }
376379 break ;
@@ -390,7 +393,7 @@ function _iterateDocTypes(node, cb) {
390393 case node instanceof TypeBuilder . RecordType . Entry :
391394 // name: string,
392395 // typeUnion: TypeUnion
393- node . typeUnion . selfNode = node ;
396+ node . typeUnion . collectionNode = node ;
394397 res = _iterateDocTypes ( node . typeUnion , cb ) ;
395398 break ;
396399
@@ -415,68 +418,11 @@ function _iterateDocTypes(node, cb) {
415418 */
416419function _simplifyType ( node ) {
417420 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 } ) ;
431424 }
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+ } ) ;
480426 return res ;
481427}
482428
0 commit comments