Skip to content

fix: add semicolons to compiled template statements for consistency#362

Merged
bgub merged 1 commit intomainfrom
claude/fix-foreach-includes-adCUX
Feb 5, 2026
Merged

fix: add semicolons to compiled template statements for consistency#362
bgub merged 1 commit intomainfrom
claude/fix-foreach-includes-adCUX

Conversation

@bgub
Copy link
Owner

@bgub bgub commented Feb 4, 2026

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

  • Added semicolons to all __eta.res+= statements in the compiled output for string literals, raw content, and interpolated values
  • Updated test expectations to reflect the new semicolon-terminated statements
  • Added comprehensive test cases for forEach loops in included templates to ensure the changes don't break existing functionality

Implementation Details

The changes were made in src/compile-string.ts where three statement types are compiled:

  • String literals: __eta.res+='...'__eta.res+='...';
  • Raw/unescaped content: __eta.res+=content__eta.res+=content;
  • Interpolated/escaped 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 compileToString snapshot expectations accordingly, and adds rendering tests covering forEach loops in included templates (including includes invoked inside a forEach) to guard against regressions in loop/include interactions.

Written by Cursor Bugbot for commit da0048c. This will update automatically on new commits. Configure here.

…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
Copilot AI review requested due to automatic review settings February 4, 2026 04:36
@bgub bgub changed the title Add semicolons to compiled template statements for consistency fix: add semicolons to compiled template statements for consistency Feb 4, 2026
@codecov
Copy link

codecov bot commented Feb 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.46%. Comparing base (0a7b5a4) to head (da0048c).
⚠️ Report is 1 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 compileToString expectation tests to reflect semicolon-terminated __eta.res+=... lines.
  • Added render tests covering forEach loops inside included templates and includes invoked from within forEach loops.

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.

@bgub bgub merged commit e0f1d65 into main Feb 5, 2026
12 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants