fix(parser): add {#if}/{#else}/{/if} and raw-text <style>/<script> in HTML templates #43
Reference in New Issue
Block a user
Delete Branch "fix/html-template-if-style-script"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
#silently, so{#if}lexes asLBrace If ...— notLBrace Hash Ident. The existing{#each}check usedk2=="Hash"which was dead code. Fixed detection for both{#each}and new{#if}.<style>/<script>: CSS and JS content inside these tags was being parsed as El expressions, generating invalid C. Addedparse_raw_text_content()that collects tokens verbatim until</tag_name>.cg_html_if()in codegen.el generatesif (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
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.