From 0ed48d3dd317936b227a6eb65cf45bd051d64332 Mon Sep 17 00:00:00 2001 From: avivkeller Date: Fri, 25 Jul 2025 17:37:59 -0400 Subject: [PATCH 1/2] fix(regexp): re-use common patterns --- src/utils/parser/constants.mjs | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/utils/parser/constants.mjs b/src/utils/parser/constants.mjs index fb6f221c..7ba20d18 100644 --- a/src/utils/parser/constants.mjs +++ b/src/utils/parser/constants.mjs @@ -18,34 +18,44 @@ export const DOC_MDN_BASE_URL_JS_GLOBALS = `${DOC_MDN_BASE_URL_JS}Reference/Glob // These are regular expressions used to determine if a given Markdown heading // is a specific type of API Doc entry (e.g., Event, Class, Method, etc) // and to extract the inner content of said Heading to be used as the API doc entry name +const CAMEL_CASE = '\\w+(?:\\.\\w+)*'; +const FUNCTION_CALL = '\\([^)]*\\)'; + +// Matches "bar": +// Group 1: foo[bar] +// Group 2: foo.bar +const PROPERTY = `${CAMEL_CASE}(?:(\\[${CAMEL_CASE}\\])|\\.(\\w+))`; + export const DOC_API_HEADING_TYPES = [ { type: 'method', - regex: - // Group 1: foo[bar]() - // Group 2: foo.bar() - // Group 3: foobar() - /^`?(?:\w*(?:(\[[^\]]+\])|(?:\.(\w+)))|(\w+))\([^)]*\)`?$/i, + regex: new RegExp(`^\`${PROPERTY}${FUNCTION_CALL}\`?$`, 'i'), }, { type: 'event', regex: /^Event: +`?['"]?([^'"]+)['"]?`?$/i }, { type: 'class', - regex: - /^Class: +`?([A-Z]\w+(?:\.[A-Z]\w+)*(?: +extends +[A-Z]\w+(?:\.[A-Z]\w+)*)?)`?$/i, + regex: new RegExp( + `Class: +\`?(${CAMEL_CASE}(?: extends +${CAMEL_CASE})?)\`?$`, + 'i' + ), }, { type: 'ctor', - regex: /^(?:Constructor: +)?`?new +([A-Z]\w+(?:\.[A-Z]\w+)*)\([^)]*\)`?$/i, + regex: new RegExp( + `^(?:Constructor: +)?\`?new +(${CAMEL_CASE})${FUNCTION_CALL}\`?$`, + 'i' + ), }, { type: 'classMethod', - regex: - /^Static method: +`?[A-Z]\w+(?:\.[A-Z]\w+)*(?:(\[\w+\.\w+\])|\.(\w+))\([^)]*\)`?$/i, + regex: new RegExp( + `^Static method: +\`?${PROPERTY}${FUNCTION_CALL}\`?$`, + 'i' + ), }, { type: 'property', - regex: - /^(?:Class property: +)?`?[A-Z]\w+(?:\.[A-Z]\w+)*(?:(\[\w+\.\w+\])|\.(\w+))`?$/i, + regex: new RegExp(`^(?:Class property: +)?\`?${PROPERTY}\`?$`, 'i'), }, ]; From 0e44601023bffc8048e398675f05b98b92bfc9e7 Mon Sep 17 00:00:00 2001 From: Aviv Keller Date: Fri, 25 Jul 2025 17:45:15 -0400 Subject: [PATCH 2/2] Update src/utils/parser/constants.mjs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/utils/parser/constants.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/parser/constants.mjs b/src/utils/parser/constants.mjs index 7ba20d18..fe0b7e3d 100644 --- a/src/utils/parser/constants.mjs +++ b/src/utils/parser/constants.mjs @@ -29,7 +29,7 @@ const PROPERTY = `${CAMEL_CASE}(?:(\\[${CAMEL_CASE}\\])|\\.(\\w+))`; export const DOC_API_HEADING_TYPES = [ { type: 'method', - regex: new RegExp(`^\`${PROPERTY}${FUNCTION_CALL}\`?$`, 'i'), + regex: new RegExp(`^\`?${PROPERTY}${FUNCTION_CALL}\`?$`, 'i'), }, { type: 'event', regex: /^Event: +`?['"]?([^'"]+)['"]?`?$/i }, {