feat: add interpolate for string template transclusion#149
Merged
Conversation
Add `interpolate(template, resolver, options?)` which renders Arazzo
string templates by replacing each embedded `{expression}` with a value
produced by a user-supplied resolver callback.
The implementation reuses the existing `expression-string` grammar/CST
(the same foundation as `extract`), so expression boundaries — including
JSON Pointers in the name part — are parsed correctly. Literal content is
preserved verbatim. Resolved values are stringified via a configurable
`stringify` option that defaults to '' for undefined/null, strings as-is,
JSON.stringify for objects and String() otherwise.
Closes #86
char0n
force-pushed
the
feat/interpolate-transclusion
branch
from
July 8, 2026 06:18
cc09748 to
7d18cc2
Compare
Adds coverage for repeated expressions, verbatim splicing of values containing replacement patterns ($&), non-re-interpolation of values that look like expressions, and JSON-object-looking braced literals left unchanged.
Replace the 'transclusion' framing with the spec's 'embeds' wording, and remove the Interpolation note whose 'see the extraction notes' reference pointed at notes that do not exist and which overstated the body-pointer limitation.
There was a problem hiding this comment.
Pull request overview
Adds a new interpolate() public API to render Arazzo “expression-string” templates by walking the existing CST for expression-string and replacing each {expression} with a caller-resolved value (with configurable stringification).
Changes:
- Implemented
src/interpolate.jsusing the existingexpression-stringgrammar +CSTTranslator. - Exported
interpolatefromsrc/index.jsand added TypeScript typings intypes/index.d.ts. - Documented interpolation in
README.mdand added a dedicated test suite intest/interpolate.js.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/interpolate.js |
Core interpolation implementation + default stringification behavior. |
src/index.js |
Public export of interpolate. |
types/index.d.ts |
Adds interpolate typings plus resolver/options types. |
test/interpolate.js |
New tests covering interpolation behavior and edge cases. |
README.md |
Adds “Interpolation” usage docs and updates package capability list/TOC. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Coalesce JSON.stringify to '' so an object whose toJSON() returns undefined does not leak the literal 'undefined' into the output, and guard the embedded-expression's expression child, emitting node text verbatim as a defensive fallback. Addresses Copilot review feedback.
Member
Author
|
🎉 This PR is included in version 3.1.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Implements the transclusion mechanism for string templates (#86) as
interpolate().interpolate(template, resolver, options?)renders Arazzo string templates by replacing each embedded{expression}with a value produced by a user-suppliedresolvercallback:Design
expression-stringgrammar/CST (same foundation asextract), so expression boundaries — including JSON Pointers in thenamepart — are parsed correctly rather than regex-matched.resolver, which receives the raw expression (e.g.$inputs.name). This composes cleanly with a downstream evaluator.stringifyoption: defaults to''forundefined/null, strings as-is,JSON.stringifyfor objects,String()otherwise.TypeErrorfor non-string templates / non-function resolvers; returns the template unchanged when it can't be parsed (mirroringextract's leniency).Changes
src/interpolate.js— implementationsrc/index.js— public exporttypes/index.d.ts—interpolate,InterpolateResolver,InterpolateOptionstypingsREADME.md— new Interpolation section, TOC entry, updated taglinetest/interpolate.js— 19 testsVerification
Full
npm run buildsucceeds with dual ESM/CJS output; all 188 tests pass; both built formats confirmed to export a workinginterpolate.Closes #86
🤖 Generated with Claude Code