@@ -323,6 +323,8 @@ function processList(section) {
323323 delete section . list ;
324324}
325325
326+ const paramExpr = / \( ( .* ) \) ; ? $ / ;
327+
326328// textRaw = "someobject.someMethod(a[, b=100][, c])"
327329function parseSignature ( text , sig ) {
328330 var params = text . match ( paramExpr ) ;
@@ -556,42 +558,23 @@ function deepCopy_(src) {
556558
557559
558560// These parse out the contents of an H# tag.
559- const eventExpr = / ^ E v e n t (?: : | \s ) + [ ' " ] ? ( [ ^ " ' ] + ) . * $ / i ;
560- const classExpr = / ^ C l a s s : \s * ( [ ^ ] + ) .* $ / i;
561- const propExpr = / ^ [ ^ . ] + \. ( [ ^ . ( ) ] + ) \s * $ / ;
562- const braceExpr = / ^ [ ^ . [ ] + ( \[ [ ^ \] ] + \] ) \s * $ / ;
563- const classMethExpr = / ^ c l a s s \s * m e t h o d \s * : ? [ ^ . ] + \. ( [ ^ . ( ) ] + ) \( [ ^ ) ] * \) \ s* $ / i ;
564- const methExpr = / ^ (?: [ ^ . ] + \. ) ? ( [ ^ . ( ) ] + ) \( [ ^ ) ] * \) \s * $ / ;
565- const newExpr = / ^ n e w ( [ A - Z ] [ a - z A - Z ] + ) \( [ ^ ) ] * \) \s * $ / ;
566- var paramExpr = / \( ( . * ) \) ; ? $ / ;
567-
568- function newSection ( tok ) {
569- const section = { } ;
561+ const headingExpressions = [
562+ { type : 'event' , re : / ^ E v e n t (?: : | \s ) + [ ' " ] ? ( [ ^ " ' ] + ) .* $ / i } ,
563+ { type : 'class' , re : / ^ C l a s s : \s * ( [ ^ ] + ) . * $ / i } ,
564+ { type : 'property' , re : / ^ [ ^ . [ ] + ( \[ [ ^ \] ] + \] ) \s * $ / } ,
565+ { type : 'property' , re : / ^ [ ^ . ] + \. ( [ ^ . ( ) ] + ) \s * $ / } ,
566+ { type : 'classMethod' , re : / ^ c l a s s \s * m e t h o d \s * : ? [ ^ . ] + \. ( [ ^ . ( ) ] + ) \( [ ^ ) ] * \) \s * $ / i } ,
567+ { type : 'method' , re : / ^ (?: [ ^ . ] + \. ) ? ( [ ^ . ( ) ] + ) \( [ ^ ) ] * \) \s * $ / } ,
568+ { type : 'ctor' , re : / ^ n e w ( [ A - Z ] [ a - z A - Z ] + ) \( [ ^ ) ] * \) \s * $ / } ,
569+ ] ;
570+
571+ function newSection ( { text } ) {
570572 // Infer the type from the text.
571- const text = section . textRaw = tok . text ;
572- if ( text . match ( eventExpr ) ) {
573- section . type = 'event' ;
574- section . name = text . replace ( eventExpr , '$1' ) ;
575- } else if ( text . match ( classExpr ) ) {
576- section . type = 'class' ;
577- section . name = text . replace ( classExpr , '$1' ) ;
578- } else if ( text . match ( braceExpr ) ) {
579- section . type = 'property' ;
580- section . name = text . replace ( braceExpr , '$1' ) ;
581- } else if ( text . match ( propExpr ) ) {
582- section . type = 'property' ;
583- section . name = text . replace ( propExpr , '$1' ) ;
584- } else if ( text . match ( classMethExpr ) ) {
585- section . type = 'classMethod' ;
586- section . name = text . replace ( classMethExpr , '$1' ) ;
587- } else if ( text . match ( methExpr ) ) {
588- section . type = 'method' ;
589- section . name = text . replace ( methExpr , '$1' ) ;
590- } else if ( text . match ( newExpr ) ) {
591- section . type = 'ctor' ;
592- section . name = text . replace ( newExpr , '$1' ) ;
593- } else {
594- section . name = text ;
573+ for ( const { type, re } of headingExpressions ) {
574+ const [ , name ] = text . match ( re ) || [ ] ;
575+ if ( name ) {
576+ return { textRaw : text , type, name } ;
577+ }
595578 }
596- return section ;
579+ return { textRaw : text , name : text } ;
597580}
0 commit comments