@@ -406,32 +406,62 @@ exports.parseTagTypes = function(str, tag) {
406406 }
407407 return [ ] ;
408408 }
409- var Parser = require ( 'jsdoctypeparser' ) . Parser ;
410- var Builder = require ( 'jsdoctypeparser' ) . Builder ;
411- var result = new Parser ( ) . parse ( str . substr ( 1 , str . length - 2 ) ) ;
409+ var { parse, publish, createDefaultPublisher, NodeType, SyntaxType} = require ( 'jsdoctypeparser' ) ;
410+ var result = parse ( str . substring ( 1 , str . length - 1 ) ) ;
411+
412+ var customPublisher = Object . assign ( { } , createDefaultPublisher ( ) , {
413+ NAME ( nameNode ) {
414+ var output = '<code>' + nameNode . name + '</code>' ;
415+
416+ if ( result . type === NodeType . OPTIONAL ) {
417+ output += '|<code>undefined</code>' ;
418+ } else if ( result . type === NodeType . NULLABLE ) {
419+ output += '|<code>null</code>' ;
420+ }
421+
422+ return output ;
423+ }
424+ } ) ;
412425
413426 var types = ( function transform ( type ) {
414- if ( type instanceof Builder . TypeUnion ) {
415- return type . types . map ( transform ) ;
416- } else if ( type instanceof Builder . TypeName ) {
417- return type . name ;
418- } else if ( type instanceof Builder . RecordType ) {
419- return type . entries . reduce ( function ( obj , entry ) {
420- obj [ entry . name ] = transform ( entry . typeUnion ) ;
427+ if ( type && type . type === NodeType . UNION ) {
428+ return [ transform ( type . left ) , transform ( type . right ) ] . flat ( ) ;
429+ } else if ( type && type . type === NodeType . NAME ) {
430+ return [ type . name ] ;
431+ } else if ( type && type . type === NodeType . RECORD ) {
432+ return [ type . entries . reduce ( function ( obj , entry ) {
433+ obj [ entry . key ] = transform ( entry . value ) ;
421434 return obj ;
422- } , { } ) ;
435+ } , { } ) ] ;
436+ } else if ( type && type . type === NodeType . GENERIC ) {
437+ if ( type . meta . syntax === SyntaxType . GenericTypeSyntax . ANGLE_BRACKET ) {
438+ return [ type . subject . name + '<' + transform ( type . objects [ 0 ] ) . join ( '|' ) + '>' ] ;
439+ } else if ( type . meta . syntax === SyntaxType . GenericTypeSyntax . ANGLE_BRACKET_WITH_DOT ) {
440+ return [ type . subject . name + '.<' + transform ( type . objects [ 0 ] ) . join ( '|' ) + '>' ] ;
441+ } else if ( type . meta . syntax === SyntaxType . GenericTypeSyntax . SQUARE_BRACKET ) {
442+ return [ type . subject . name + '[' + transform ( type . objects [ 0 ] ) . join ( '|' ) + ']' ] ;
443+ } else if ( type . meta . syntax === SyntaxType . VariadicTypeSyntax . PREFIX_DOTS ) {
444+ return [ `...${ type . subject . name } ` ] ;
445+ } else if ( type . meta . syntax === SyntaxType . VariadicTypeSyntax . SUFFIX_DOTS ) {
446+ return [ `${ type . subject . name } ...` ] ;
447+ } else if ( type . meta . syntax === SyntaxType . VariadicTypeSyntax . ONLY_DOTS ) {
448+ return [ '...' ] ;
449+ }
450+ return [ type . subject . name ]
451+ } else if ( type && type . value ) {
452+ return transform ( type . value ) ;
423453 } else {
424454 return type . toString ( ) ;
425455 }
426456 } ( result ) ) ;
427457
428458 if ( tag ) {
429459 tag . types = types ;
430- tag . typesDescription = result . toHtml ( ) ;
431- tag . optional = ( tag . name && tag . name . slice ( 0 , 1 ) === '[' ) || result . optional ;
432- tag . nullable = result . nullable ;
433- tag . nonNullable = result . nonNullable ;
434- tag . variable = result . variable ;
460+ tag . typesDescription = publish ( result , customPublisher ) . replace ( / ^ \? | = $ / , '' ) ;
461+ tag . optional = ( tag . name && tag . name . slice ( 0 , 1 ) === '[' ) || result . type === NodeType . OPTIONAL ;
462+ tag . nullable = result . type === NodeType . NULLABLE ;
463+ tag . nonNullable = result . meta ? result . meta . syntax === 'SUFFIX_QUESTION_MARK' || result . meta . syntax === 'PREFIX_BANG' : false ;
464+ tag . variable = result . type === NodeType . VARIADIC ;
435465 }
436466
437467 return types ;
0 commit comments