From c981357922aaf544218cb788641018016d61a152 Mon Sep 17 00:00:00 2001 From: Dylan Piercey Date: Mon, 2 Nov 2026 15:41:44 -0700 Subject: [PATCH] feat: only comments may follow a concise `;` line's html comment After a `;` ends a concise line, code after an html comment was read as a new line indented under the tag (`div; span` nested `span` in `div`). Only comments may follow the html comment now, as after the `;`. Co-Authored-By: Claude Opus 5.5 --- .changeset/semicolon-html-comment.md | 5 +++++ ...de-after-semicolon-html-comment.expected.txt | 17 +++++++++++++++++ .../input.marko | 2 ++ src/states/CONCISE_HTML_CONTENT.ts | 5 +++++ 4 files changed, 29 insertions(+) create mode 100644 .changeset/semicolon-html-comment.md create mode 100644 src/__tests__/fixtures/invalid-code-after-semicolon-html-comment/__snapshots__/invalid-code-after-semicolon-html-comment.expected.txt create mode 100644 src/__tests__/fixtures/invalid-code-after-semicolon-html-comment/input.marko diff --git a/.changeset/semicolon-html-comment.md b/.changeset/semicolon-html-comment.md new file mode 100644 index 00000000..3de9e63e --- /dev/null +++ b/.changeset/semicolon-html-comment.md @@ -0,0 +1,5 @@ +--- +"htmljs-parser": minor +--- + +Report code after an html comment that follows a concise `;` (eg `div; span`) as an error, as after any other comment there, instead of reading it as a new line nested in the tag. More comments may still follow. diff --git a/src/__tests__/fixtures/invalid-code-after-semicolon-html-comment/__snapshots__/invalid-code-after-semicolon-html-comment.expected.txt b/src/__tests__/fixtures/invalid-code-after-semicolon-html-comment/__snapshots__/invalid-code-after-semicolon-html-comment.expected.txt new file mode 100644 index 00000000..c4a99c9a --- /dev/null +++ b/src/__tests__/fixtures/invalid-code-after-semicolon-html-comment/__snapshots__/invalid-code-after-semicolon-html-comment.expected.txt @@ -0,0 +1,17 @@ +1╭─ div; // c + │ │ ││ │ │ │ │ ╰─ comment.value " c" + │ │ ││ │ │ │ ╰─ comment "// c" + │ │ ││ │ │ ╰─ comment.value " b " + │ │ ││ │ ╰─ comment "" + │ │ ││ ╰─ comment.value " a " + │ │ │╰─ comment "" + │ │ ╰─ openTagEnd + ╰─ ╰─ tagName "div" +2╭─ span; p + │ │ ││ │ ╰─ error(INVALID_CODE_AFTER_SEMICOLON:A semicolon indicates the end of a line. Only comments may follow it.) + │ │ ││ ╰─ comment.value " d " + │ │ │╰─ comment "" + │ │ ╰─ openTagEnd + │ ├─ closeTagEnd(div) + ╰─ ╰─ tagName "span" +3╰─ \ No newline at end of file diff --git a/src/__tests__/fixtures/invalid-code-after-semicolon-html-comment/input.marko b/src/__tests__/fixtures/invalid-code-after-semicolon-html-comment/input.marko new file mode 100644 index 00000000..96c6f141 --- /dev/null +++ b/src/__tests__/fixtures/invalid-code-after-semicolon-html-comment/input.marko @@ -0,0 +1,2 @@ +div; // c +span; p diff --git a/src/states/CONCISE_HTML_CONTENT.ts b/src/states/CONCISE_HTML_CONTENT.ts index 060189d7..47d92556 100644 --- a/src/states/CONCISE_HTML_CONTENT.ts +++ b/src/states/CONCISE_HTML_CONTENT.ts @@ -188,6 +188,11 @@ export const CONCISE_HTML_CONTENT: StateDefinition = { break; } + case STATE.HTML_COMMENT: + // Only reached after a ";" (a line starting with "<" is an html + // block), so only comments may follow it either. + STATE.endConciseLine(this, this.data); + break; } }, };