@@ -18,34 +18,44 @@ export const DOC_MDN_BASE_URL_JS_GLOBALS = `${DOC_MDN_BASE_URL_JS}Reference/Glob
1818// These are regular expressions used to determine if a given Markdown heading
1919// is a specific type of API Doc entry (e.g., Event, Class, Method, etc)
2020// and to extract the inner content of said Heading to be used as the API doc entry name
21+ const CAMEL_CASE = '\\w+(?:\\.\\w+)*' ;
22+ const FUNCTION_CALL = '\\([^)]*\\)' ;
23+
24+ // Matches "bar":
25+ // Group 1: foo[bar]
26+ // Group 2: foo.bar
27+ const PROPERTY = `${ CAMEL_CASE } (?:(\\[${ CAMEL_CASE } \\])|\\.(\\w+))` ;
28+
2129export const DOC_API_HEADING_TYPES = [
2230 {
2331 type : 'method' ,
24- regex :
25- // Group 1: foo[bar]()
26- // Group 2: foo.bar()
27- // Group 3: foobar()
28- / ^ ` ? (?: \w * (?: ( \[ [ ^ \] ] + \] ) | (?: \. ( \w + ) ) ) | ( \w + ) ) \( [ ^ ) ] * \) ` ? $ / i,
32+ regex : new RegExp ( `^\`?${ PROPERTY } ${ FUNCTION_CALL } \`?$` , 'i' ) ,
2933 } ,
3034 { type : 'event' , regex : / ^ E v e n t : + ` ? [ ' " ] ? ( [ ^ ' " ] + ) [ ' " ] ? ` ? $ / i } ,
3135 {
3236 type : 'class' ,
33- regex :
34- / ^ C l a s s : + ` ? ( [ A - Z ] \w + (?: \. [ A - Z ] \w + ) * (?: + e x t e n d s + [ A - Z ] \w + (?: \. [ A - Z ] \w + ) * ) ? ) ` ? $ / i,
37+ regex : new RegExp (
38+ `Class: +\`?(${ CAMEL_CASE } (?: extends +${ CAMEL_CASE } )?)\`?$` ,
39+ 'i'
40+ ) ,
3541 } ,
3642 {
3743 type : 'ctor' ,
38- regex : / ^ (?: C o n s t r u c t o r : + ) ? ` ? n e w + ( [ A - Z ] \w + (?: \. [ A - Z ] \w + ) * ) \( [ ^ ) ] * \) ` ? $ / i,
44+ regex : new RegExp (
45+ `^(?:Constructor: +)?\`?new +(${ CAMEL_CASE } )${ FUNCTION_CALL } \`?$` ,
46+ 'i'
47+ ) ,
3948 } ,
4049 {
4150 type : 'classMethod' ,
42- regex :
43- / ^ S t a t i c m e t h o d : + ` ? [ A - Z ] \w + (?: \. [ A - Z ] \w + ) * (?: ( \[ \w + \. \w + \] ) | \. ( \w + ) ) \( [ ^ ) ] * \) ` ? $ / i,
51+ regex : new RegExp (
52+ `^Static method: +\`?${ PROPERTY } ${ FUNCTION_CALL } \`?$` ,
53+ 'i'
54+ ) ,
4455 } ,
4556 {
4657 type : 'property' ,
47- regex :
48- / ^ (?: C l a s s p r o p e r t y : + ) ? ` ? [ A - Z ] \w + (?: \. [ A - Z ] \w + ) * (?: ( \[ \w + \. \w + \] ) | \. ( \w + ) ) ` ? $ / i,
58+ regex : new RegExp ( `^(?:Class property: +)?\`?${ PROPERTY } \`?$` , 'i' ) ,
4959 } ,
5060] ;
5161
0 commit comments