Repository navigation
fix(markdown-template): set elementType on join and list blocks over primitive arrays - #687
Open
rajanpanth wants to merge 1 commit into
Open
rajanpanth wants to merge 1 commit into
rajanpanth wants to merge 1 commit into
Conversation
…primitive arrays TypeVisitor only set elementType on JoinDefinition, ListBlockDefinition and ForeachDefinition when the array held concepts. Over a primitive array (String[], Integer[], DateTime[], ...) the node had no elementType, so template-engine could not pick a drafter for the items: joining an Integer[], Double[] or Boolean[] throws "Iterable yielded 1 which is not a string" from Intl.ListFormat, and a DateTime[] is joined as raw ISO strings instead of formatted dates. Set elementType from the property for primitive arrays too. The scope for the children is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: rajanpanth <rajan.pantha@samriddhicollege.edu.np>
4 of 5 tasks
This branch has not been deployed
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.
TypeVisitoronly setselementTypeonJoinDefinition,ListBlockDefinitionandForeachDefinitionwhen the array holds concepts. Over a primitive array (String[],Integer[],DateTime[], ...) the node has noelementType, so template-engine can't pick a drafter for the items.Drafting with template-engine
main(519ee9d) and the published@accordproject/markdown-template@2.0.0:{{#join counts}}{{/join}}(Integer[]=[1, 2, 3])Iterable yielded 1 which is not a string1, 2, and 3{{#join rates}}{{/join}}(Double[]=[1.5, 2])Iterable yielded 1.5 which is not a string1.5 and 2.0{{#join flags}}{{/join}}(Boolean[])Iterable yielded true which is not a stringtrue and false{{#join dates}}{{/join}}(DateTime[])2024-03-05T00:00:00.000Z and 2024-04-01T00:00:00.000Z03/05/2024 and 04/01/2024{{#join names}}{{/join}}(String[])Ann and BenAnn and BenThe throw comes from
Intl.ListFormat, which only accepts strings. Without an element type, template-engine passes the raw numbers and booleans through.Changes
TypeVisitor: setelementTypefrom the property for primitive arrays as well. The child scope is unchanged (still the property for primitives, the class declaration for concepts).TemplateMarkTransformer.test.ts:#joinoverInteger[],DateTime[]andString[];#ulist/#olistover primitive arrays; and arrays of concepts, which keep their class type. The four primitive-array tests fail without the change.Flags
elementTypeon join and list nodes over primitive arrays. With this build, template-engine's suite passes except one snapshot (TemplateMarkToJavaScriptCompiler.test.ts), which gains"elementType": "String"on itsString[]join and list nodes. That snapshot needs updating when template-engine bumps the dependency.{{#foreach}}isn't covered by a test: it isn't parsed into aForeachDefinitiontoday (it comes out as text), and template-engine skips its foreach template as broken. Thecasehere sets the field for it the same way.Author Checklist
--signoffoption of git commit.mainfromfork:branchnameAll workspace tests pass locally (
npm run build && npm test) with no snapshot changes in this repo.🤖 Generated with Claude Code