fix(parser): add {#if}/{#else}/{/if} and raw-text <style>/<script> in HTML templates #43

Merged
will.anderson merged 1 commits from fix/html-template-if-style-script into dev 2026-05-07 18:44:27 +00:00
Owner

Summary

  • {#if}/{#else}/{/if} in HTML templates: The El lexer skips # silently, so {#if} lexes as LBrace If ... — not LBrace Hash Ident. The existing {#each} check used k2=="Hash" which was dead code. Fixed detection for both {#each} and new {#if}.
  • Raw-text for <style>/<script>: CSS and JS content inside these tags was being parsed as El expressions, generating invalid C. Added parse_raw_text_content() that collects tokens verbatim until </tag_name>.
  • HtmlIf codegen: New cg_html_if() in codegen.el generates if (cond) { then } else { else } for HtmlIf AST nodes.

Why

founding_badge.el, checkout.el, and several other web components use {#if} in HTML templates and <style>/<script> inside HTML elements. The current ci-base elc OOMs on these files because the parser enters an infinite loop when it encounters {#if} without handling it.

Test plan

  • CI dev build passes
  • After merge → dev, trigger sdk-release to rebuild ci-base
  • Verify web project builds cleanly with updated ci-base elc
## Summary - **{#if}/{#else}/{/if} in HTML templates**: The El lexer skips `#` silently, so `{#if}` lexes as `LBrace If ...` — not `LBrace Hash Ident`. The existing `{#each}` check used `k2=="Hash"` which was dead code. Fixed detection for both `{#each}` and new `{#if}`. - **Raw-text for `<style>`/`<script>`**: CSS and JS content inside these tags was being parsed as El expressions, generating invalid C. Added `parse_raw_text_content()` that collects tokens verbatim until `</tag_name>`. - **HtmlIf codegen**: New `cg_html_if()` in codegen.el generates `if (cond) { then } else { else }` for HtmlIf AST nodes. ## Why `founding_badge.el`, `checkout.el`, and several other web components use `{#if}` in HTML templates and `<style>`/`<script>` inside HTML elements. The current ci-base elc OOMs on these files because the parser enters an infinite loop when it encounters `{#if}` without handling it. ## Test plan - [ ] CI dev build passes - [ ] After merge → dev, trigger sdk-release to rebuild ci-base - [ ] Verify web project builds cleanly with updated ci-base elc
will.anderson added 1 commit 2026-05-07 18:39:28 +00:00
fix(parser): add {#if}/{#else}/{/if} support and raw-text <style>/<script> in HTML templates
El SDK CI - dev / build-and-test (pull_request) Failing after 18m3s
a3732a1e9a
The El lexer silently skips '#', so {#each} lexes as LBrace Ident:"each"
and {#if} lexes as LBrace If ... (using the If keyword token, not Hash).
The existing {#each} check used k2=="Hash" which was dead code.

Parser changes (parser.el):
- Add parse_raw_text_content(): collects all tokens as raw text until
  </tag_name>, bypassing El expression parsing. Used for <style> and
  <script> elements so CSS/JS content isn't parsed as El expressions.
- parse_html_element(): use raw-text mode for <style> and <script> tags.
- parse_html_children(): fix {#each} detection (k2=="Ident", k3=="each"
  instead of dead k2=="Hash" check). Add {#if cond}...{#else}...{/if}
  support generating HtmlIf AST nodes.

Codegen changes (codegen.el):
- Add cg_html_if(): generates if (cond_c) { then_c } else { else_c }
  for HtmlIf nodes.
- cg_html_parts(): dispatch HtmlIf to cg_html_if.
will.anderson merged commit 7b7f9f353b into dev 2026-05-07 18:44:27 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: neuron-technologies/el#43