Fix: Robust argument parsing for {{call}} syntax to support nested CBS #1034
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Checklist
Description
The Problem
The previous implementation of the
{{call::...}}
syntax used a simplestring.split('::')
method to parse its arguments. This had a critical limitation: it could not correctly handle arguments that contained nested CBS (e.g.,{{getvar::...}}
,{{slot::...}}
). This made it impossible to use powerful patterns, such as calling a function with a dynamic value from within an{{#each}}
loop.The Solution
This PR replaces the simple split logic with a more robust, context-aware parser for
{{call}}
arguments. The new implementation iterates through the argument string while tracking the nesting level of curly braces ({{...}}
). As a result, it now correctly identifies::
as a top-level argument separator, while ignoring any::
found inside nested syntaxes.Key Improvements
{{call}}
can now safely accept other CBS as arguments, enabling dynamic and modular script creation.{{#each}}
to loop through an array and call a function for each item, as demonstrated below.Demonstration
The following test case now works as intended.
Test Code:
Before:
The parser failed because it incorrectly split the nested

{{slot::fruit}}
and{{when...}}
syntaxes, leading to broken output.After:
The function is called correctly for each item in the loop, producing the expected HTML structure.
