fix: add semicolons to compiled template statements for consistency#362
Merged
fix: add semicolons to compiled template statements for consistency#362
Conversation
…Each
When a template contained literal content followed by a code block
starting with '(' (e.g., forEach, IIFE), JavaScript's Automatic
Semicolon Insertion would fail to insert a semicolon, causing the
string literal to be interpreted as a function call.
This fix adds semicolons after __eta.res+= statements in the compiled
output, preventing errors like "TypeError: '<ul>' is not a function"
when using forEach loops in included templates.
https://claude.ai/code/session_01X6wieCMrnceNg5N2phXCuA
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #362 +/- ##
=======================================
Coverage 91.46% 91.46%
=======================================
Files 11 11
Lines 293 293
Branches 78 78
=======================================
Hits 268 268
Misses 9 9
Partials 16 16 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR updates Eta’s template compiler output to consistently terminate generated __eta.res+=... statements with semicolons, and adjusts/extends tests to match and validate the new output.
Changes:
- Added semicolons to compiled output statements for string, raw, and interpolated AST blocks in
compileBody. - Updated
compileToStringexpectation tests to reflect semicolon-terminated__eta.res+=...lines. - Added render tests covering
forEachloops inside included templates and includes invoked from withinforEachloops.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/compile-string.ts |
Appends semicolons to generated __eta.res+=... statements for safer/more consistent emitted JS. |
test/compile-string.spec.ts |
Updates expected compiled function strings to include the new semicolons. |
test/render.spec.ts |
Adds regression tests for forEach + include scenarios to ensure rendering still works. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
This PR adds semicolons to the end of compiled template statements in the Eta template engine to improve code consistency and follow JavaScript best practices.
Key Changes
__eta.res+=statements in the compiled output for string literals, raw content, and interpolated valuesImplementation Details
The changes were made in
src/compile-string.tswhere three statement types are compiled:__eta.res+='...'→__eta.res+='...';__eta.res+=content→__eta.res+=content;__eta.res+=content→__eta.res+=content;Execute statements (type "e") already had newlines and were left unchanged.
The test suite was updated to verify the new output format, and new test cases were added to ensure forEach loops work correctly both within included partials and when includes are called from within loops.
https://claude.ai/code/session_01X6wieCMrnceNg5N2phXCuA
Note
Low Risk
Small, mechanical change to generated JS plus additional tests; behavior should be unchanged, with limited risk beyond edge-case parsing/formatting expectations.
Overview
Makes the template compiler emit semicolon-terminated
__eta.res += ...;statements for string, raw, and interpolated blocks (previously newline-terminated), improving generated JS consistency.Updates
compileToStringsnapshot expectations accordingly, and adds rendering tests coveringforEachloops in included templates (including includes invoked inside aforEach) to guard against regressions in loop/include interactions.Written by Cursor Bugbot for commit da0048c. This will update automatically on new commits. Configure here.