Add Named Capture Support to JavaScript Templating API #6136
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.
This PR adds support for named captures in the JavaScript templating API, allowing for more concise pattern matching and template generation.
Added optional
nameparameter to thecapture()function, enabling inline named captures for cleaner rewrite rules.Key Changes
Named Captures Support
The
capture()function now accepts an optional name parameter:Trade-offs
Slightly more verbose for rewrite rules:
But enables direct literal string insertion:
This is valuable for common use cases where you want to insert variable code fragments.
API Behavior
Template parameter types:
capture()objects → Late binding via the values map (for pattern matching)The explicit
capture()requirement makes the API more extensible for future enhancements while keeping common literal insertion cases simple.