@@ -18,34 +18,44 @@ export const DOC_MDN_BASE_URL_JS_GLOBALS = `${DOC_MDN_BASE_URL_JS}Reference/Glob
18
18
// These are regular expressions used to determine if a given Markdown heading
19
19
// is a specific type of API Doc entry (e.g., Event, Class, Method, etc)
20
20
// 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
+
21
29
export const DOC_API_HEADING_TYPES = [
22
30
{
23
31
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' ) ,
29
33
} ,
30
34
{ type : 'event' , regex : / ^ E v e n t : + ` ? [ ' " ] ? ( [ ^ ' " ] + ) [ ' " ] ? ` ? $ / i } ,
31
35
{
32
36
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
+ ) ,
35
41
} ,
36
42
{
37
43
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
+ ) ,
39
48
} ,
40
49
{
41
50
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
+ ) ,
44
55
} ,
45
56
{
46
57
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' ) ,
49
59
} ,
50
60
] ;
51
61
0 commit comments