feat: implement each and when block statements#52
Merged
Conversation
- Add each statement: iterate over array elements, apply block to each
- Supports nested each blocks for deeply nested arrays
- Errors on non-array targets
- No-op on empty arrays
- Add when statement: conditional block execution
- Block applied when condition is truthy, skipped when falsy
- Multiple when blocks evaluate independently
- Supports nesting: when inside each for per-element conditionals
- Add parser support for block syntax with { } delimiters
- Add 11 integration tests covering all TDD scenarios
Fixes #23
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
eachandwhenblock statements as specified in #23.New Operations
each .path { ... }— Iterate over array elements, apply block to eachwhen <condition> { ... }— Conditional block executionBehavior
Tests (11 integration tests)
each_rename_in_elements— Rename in every elementeach_computed_fields— Computed fields per elementeach_on_non_array_error— Error on non-arrayeach_multiple_operations— Multiple ops in blocknested_each— Nested each blockseach_empty_array— Empty array no-opwhen_condition_true— Block appliedwhen_condition_false— Block skippedmultiple_when_blocks— Independent evaluationwhen_inside_each— Conditional inside iterationeach_with_when_conditional_per_element— Per-element conditionalFixes #23