@@ -553,15 +553,54 @@ function cloneValue(src) {
553553}
554554
555555
556- // These parse out the contents of an H# tag.
556+ // This section parse out the contents of an H# tag.
557+
558+ // To reduse escape slashes in RegExp string components.
559+ const r = String . raw ;
560+
561+ const eventPrefix = '^Event: +' ;
562+ const classPrefix = '^[Cc]lass: +' ;
563+ const ctorPrefix = '^(?:[Cc]onstructor: +)?new +' ;
564+ const classMethodPrefix = '^Class Method: +' ;
565+ const maybeClassPropertyPrefix = '(?:Class Property: +)?' ;
566+
567+ const maybeQuote = '[\'"]?' ;
568+ const notQuotes = '[^\'"]+' ;
569+
570+ // To include constructs like `readable\[Symbol.asyncIterator\]()`
571+ // or `readable.\_read(size)` (with Markdown escapes).
572+ const simpleId = r `(?:(?:\\?_)+|\b)\w+\b` ;
573+ const computedId = r `\\?\[[\w\.]+\\?\]` ;
574+ const id = `(?:${ simpleId } |${ computedId } )` ;
575+ const classId = r `[A-Z]\w+` ;
576+
577+ const ancestors = r `(?:${ id } \.?)+` ;
578+ const maybeAncestors = r `(?:${ id } \.?)*` ;
579+
580+ const callWithParams = r `\([^)]*\)` ;
581+
582+ const noCallOrProp = '(?![.[(])' ;
583+
584+ const maybeExtends = `(?: +extends +${ maybeAncestors } ${ classId } )?` ;
585+
557586const headingExpressions = [
558- { type : 'event' , re : / ^ E v e n t (?: : | \s ) + [ ' " ] ? ( [ ^ " ' ] + ) .* $ / i } ,
559- { type : 'class' , re : / ^ C l a s s : \s * ( [ ^ ] + ) .* $ / i } ,
560- { type : 'property' , re : / ^ [ ^ . [ ] + ( \[ [ ^ \] ] + \] ) \s * $ / } ,
561- { type : 'property' , re : / ^ [ ^ . ] + \. ( [ ^ . ( ) ] + ) \s * $ / } ,
562- { type : 'classMethod' , re : / ^ c l a s s \s * m e t h o d \s * : ? [ ^ . ] + \. ( [ ^ . ( ) ] + ) \( [ ^ ) ] * \) \s * $ / i } ,
563- { type : 'method' , re : / ^ (?: [ ^ . ] + \. ) ? ( [ ^ . ( ) ] + ) \( [ ^ ) ] * \) \s * $ / } ,
564- { type : 'ctor' , re : / ^ n e w ( [ A - Z ] [ a - z A - Z ] + ) \( [ ^ ) ] * \) \s * $ / } ,
587+ { type : 'event' , re : RegExp (
588+ `${ eventPrefix } ${ maybeQuote } (${ notQuotes } )${ maybeQuote } $` , 'i' ) } ,
589+
590+ { type : 'class' , re : RegExp (
591+ `${ classPrefix } (${ maybeAncestors } ${ classId } )${ maybeExtends } $` , '' ) } ,
592+
593+ { type : 'ctor' , re : RegExp (
594+ `${ ctorPrefix } (${ maybeAncestors } ${ classId } )${ callWithParams } $` , '' ) } ,
595+
596+ { type : 'classMethod' , re : RegExp (
597+ `${ classMethodPrefix } ${ maybeAncestors } (${ id } )${ callWithParams } $` , 'i' ) } ,
598+
599+ { type : 'method' , re : RegExp (
600+ `^${ maybeAncestors } (${ id } )${ callWithParams } $` , 'i' ) } ,
601+
602+ { type : 'property' , re : RegExp (
603+ `^${ maybeClassPropertyPrefix } ${ ancestors } (${ id } )${ noCallOrProp } $` , 'i' ) } ,
565604] ;
566605
567606function newSection ( { text } ) {
0 commit comments