From 39573317a24ed69f0edd6c0ae568ad0987b8d5f7 Mon Sep 17 00:00:00 2001 From: "Ilenia M." <26656284+majestic-owl448@users.noreply.github.com> Date: Sat, 30 May 2026 13:05:26 +0200 Subject: [PATCH 1/3] docs: document functionRegex capture nested blocks limitation --- src/content/docs/curriculum-help.mdx | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/content/docs/curriculum-help.mdx b/src/content/docs/curriculum-help.mdx index 0c5be4ba..75dc9b19 100644 --- a/src/content/docs/curriculum-help.mdx +++ b/src/content/docs/curriculum-help.mdx @@ -534,6 +534,27 @@ const match = match[1]; // "myFunc = arg1 => arg1; console.log();\n // captured, unfortunately" ``` +NOTE: `capture: true` does not work correctly for regular functions whose body contains nested blocks (`if`, `try`, `for`, etc.). The captured content is truncated at the first `}` inside the body, so everything after the first closing brace of a nested block is silently excluded. + +```js +const regEx = __helpers.functionRegex('registerUser', [], { capture: true }); + +const match = `function registerUser() { + if (name.trim() === "") { + throw new Error("Name is required"); + } + if (age.trim() === "") { + throw new Error("Age is required"); + } +}`.match(regEx); + +match[1]; +// Ends at the closing } of the first if block. +// match[1].includes('age.trim') === false +``` + +For functions with nested blocks, match directly against `code` instead of relying on `match[1]`. + #### `.getFunctionParams()` Available via `__helpers.getFunctionParams(codeString)`, this method extracts parameter information from a function definition string. From 0df5eff758e49fe7deeb77a4c488a4139dccc1bd Mon Sep 17 00:00:00 2001 From: "Ilenia M." <26656284+majestic-owl448@users.noreply.github.com> Date: Sat, 30 May 2026 13:08:57 +0200 Subject: [PATCH 2/3] docs: clarify workaround for functionRegex nested blocks limitation --- src/content/docs/curriculum-help.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/curriculum-help.mdx b/src/content/docs/curriculum-help.mdx index 75dc9b19..c71952f4 100644 --- a/src/content/docs/curriculum-help.mdx +++ b/src/content/docs/curriculum-help.mdx @@ -553,7 +553,7 @@ match[1]; // match[1].includes('age.trim') === false ``` -For functions with nested blocks, match directly against `code` instead of relying on `match[1]`. +For functions with nested blocks, match directly against `code` or the stringified function instead of relying on `match[1]`. #### `.getFunctionParams()` From 0f293211d0064a3460b5bc8b8c8a6beecdc1b8cb Mon Sep 17 00:00:00 2001 From: "Ilenia M." <26656284+majestic-owl448@users.noreply.github.com> Date: Sat, 30 May 2026 13:17:36 +0200 Subject: [PATCH 3/3] docs: clarify functionRegex example with explicit assertions --- src/content/docs/curriculum-help.mdx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/content/docs/curriculum-help.mdx b/src/content/docs/curriculum-help.mdx index c71952f4..22b16d13 100644 --- a/src/content/docs/curriculum-help.mdx +++ b/src/content/docs/curriculum-help.mdx @@ -548,9 +548,8 @@ const match = `function registerUser() { } }`.match(regEx); -match[1]; -// Ends at the closing } of the first if block. -// match[1].includes('age.trim') === false +match[1].includes('throw new Error("Name is required")'); // true — first if block IS captured +match[1].includes('age.trim'); // false — second if block is NOT captured ``` For functions with nested blocks, match directly against `code` or the stringified function instead of relying on `match[1]`.