From e0078364148fbfae61e9b85288a653812b98228f Mon Sep 17 00:00:00 2001 From: LuLaValva Date: Fri, 14 Aug 2026 17:08:29 -0700 Subject: [PATCH 1/4] fix(compiler): reject an html comment in a tag's attributes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit An `` written where an attribute belongs either surfaced htmljs-parser's unrelated "Unexpected types" message or, once the ` class="a">` either surfaced an unrelated "Unexpected types" parse error or, when the `` outside the tag."; const emptyRange = (part) => part.start === part.end; const isAttrTag = (tag) => tag.name.value?.[0] === "@"; const isStatementTag = (tag) => tag.tagDef?.parseOptions?.statement; @@ -146,11 +148,17 @@ export function parseMarko(file) { const parser = createParser({ onError(part) { + // htmljs-parser reads the `<` of a ` class="a">` (comment in the attributes) | `
`; `` is markup, so it only belongs in a body | | `{expr}` in markup, `className`, `key=`, `style={{...}}` | `${expr}`, `class`, `by=` on ``, `style={...}` | | `onClick={() => ...}` / `@click` / `on-click("name")` | `onClick() { ... }` | | `const [x, setX] = useState()` / `state` / `class {}` block | `` then `x = 1` | diff --git a/packages/runtime-tags/src/__tests__/fixtures/error-html-comment-after-attr/__snapshots__/error-compile-dom.debug.txt b/packages/runtime-tags/src/__tests__/fixtures/error-html-comment-after-attr/__snapshots__/error-compile-dom.debug.txt new file mode 100644 index 00000000000..79861b7364d --- /dev/null +++ b/packages/runtime-tags/src/__tests__/fixtures/error-html-comment-after-attr/__snapshots__/error-compile-dom.debug.txt @@ -0,0 +1,5 @@ + + at packages/runtime-tags/src/__tests__/fixtures/error-html-comment-after-attr/template.marko:1:18 + > 1 |
id="bar">Hello
+ | ^^^^ HTML comments are not supported in a tag's attributes. Use a JavaScript comment (`// …` or `/* … */`), or move the `` outside the tag. + 2 | \ No newline at end of file diff --git a/packages/runtime-tags/src/__tests__/fixtures/error-html-comment-after-attr/__snapshots__/error-compile-dom.txt b/packages/runtime-tags/src/__tests__/fixtures/error-html-comment-after-attr/__snapshots__/error-compile-dom.txt new file mode 100644 index 00000000000..79861b7364d --- /dev/null +++ b/packages/runtime-tags/src/__tests__/fixtures/error-html-comment-after-attr/__snapshots__/error-compile-dom.txt @@ -0,0 +1,5 @@ + + at packages/runtime-tags/src/__tests__/fixtures/error-html-comment-after-attr/template.marko:1:18 + > 1 |
id="bar">Hello
+ | ^^^^ HTML comments are not supported in a tag's attributes. Use a JavaScript comment (`// …` or `/* … */`), or move the `` outside the tag. + 2 | \ No newline at end of file diff --git a/packages/runtime-tags/src/__tests__/fixtures/error-html-comment-after-attr/__snapshots__/error-compile-html.debug.txt b/packages/runtime-tags/src/__tests__/fixtures/error-html-comment-after-attr/__snapshots__/error-compile-html.debug.txt new file mode 100644 index 00000000000..79861b7364d --- /dev/null +++ b/packages/runtime-tags/src/__tests__/fixtures/error-html-comment-after-attr/__snapshots__/error-compile-html.debug.txt @@ -0,0 +1,5 @@ + + at packages/runtime-tags/src/__tests__/fixtures/error-html-comment-after-attr/template.marko:1:18 + > 1 |
id="bar">Hello
+ | ^^^^ HTML comments are not supported in a tag's attributes. Use a JavaScript comment (`// …` or `/* … */`), or move the `` outside the tag. + 2 | \ No newline at end of file diff --git a/packages/runtime-tags/src/__tests__/fixtures/error-html-comment-after-attr/__snapshots__/error-compile-html.txt b/packages/runtime-tags/src/__tests__/fixtures/error-html-comment-after-attr/__snapshots__/error-compile-html.txt new file mode 100644 index 00000000000..79861b7364d --- /dev/null +++ b/packages/runtime-tags/src/__tests__/fixtures/error-html-comment-after-attr/__snapshots__/error-compile-html.txt @@ -0,0 +1,5 @@ + + at packages/runtime-tags/src/__tests__/fixtures/error-html-comment-after-attr/template.marko:1:18 + > 1 |
id="bar">Hello
+ | ^^^^ HTML comments are not supported in a tag's attributes. Use a JavaScript comment (`// …` or `/* … */`), or move the `` outside the tag. + 2 | \ No newline at end of file diff --git a/packages/runtime-tags/src/__tests__/fixtures/error-html-comment-after-attr/template.marko b/packages/runtime-tags/src/__tests__/fixtures/error-html-comment-after-attr/template.marko new file mode 100644 index 00000000000..d7a4575fb59 --- /dev/null +++ b/packages/runtime-tags/src/__tests__/fixtures/error-html-comment-after-attr/template.marko @@ -0,0 +1 @@ +
id="bar">Hello
diff --git a/packages/runtime-tags/src/__tests__/fixtures/error-html-comment-after-attr/test.ts b/packages/runtime-tags/src/__tests__/fixtures/error-html-comment-after-attr/test.ts new file mode 100644 index 00000000000..87d511a1f39 --- /dev/null +++ b/packages/runtime-tags/src/__tests__/fixtures/error-html-comment-after-attr/test.ts @@ -0,0 +1,5 @@ +import type { TestConfig } from "../../main.test"; + +export const config: TestConfig = { + error_compiler: true, +}; diff --git a/packages/runtime-tags/src/__tests__/fixtures/error-html-comment-in-attrs/__snapshots__/error-compile-dom.debug.txt b/packages/runtime-tags/src/__tests__/fixtures/error-html-comment-in-attrs/__snapshots__/error-compile-dom.debug.txt new file mode 100644 index 00000000000..31fd71aa7e5 --- /dev/null +++ b/packages/runtime-tags/src/__tests__/fixtures/error-html-comment-in-attrs/__snapshots__/error-compile-dom.debug.txt @@ -0,0 +1,8 @@ + + at packages/runtime-tags/src/__tests__/fixtures/error-html-comment-in-attrs/template.marko:2:3 + 1 |
2 | + | ^^^^ HTML comments are not supported in a tag's attributes. Use a JavaScript comment (`// …` or `/* … */`), or move the `` outside the tag. + 3 | class="foo" + 4 | >Hello
+ 5 | \ No newline at end of file diff --git a/packages/runtime-tags/src/__tests__/fixtures/error-html-comment-in-attrs/__snapshots__/error-compile-dom.txt b/packages/runtime-tags/src/__tests__/fixtures/error-html-comment-in-attrs/__snapshots__/error-compile-dom.txt new file mode 100644 index 00000000000..31fd71aa7e5 --- /dev/null +++ b/packages/runtime-tags/src/__tests__/fixtures/error-html-comment-in-attrs/__snapshots__/error-compile-dom.txt @@ -0,0 +1,8 @@ + + at packages/runtime-tags/src/__tests__/fixtures/error-html-comment-in-attrs/template.marko:2:3 + 1 |
2 | + | ^^^^ HTML comments are not supported in a tag's attributes. Use a JavaScript comment (`// …` or `/* … */`), or move the `` outside the tag. + 3 | class="foo" + 4 | >Hello
+ 5 | \ No newline at end of file diff --git a/packages/runtime-tags/src/__tests__/fixtures/error-html-comment-in-attrs/__snapshots__/error-compile-html.debug.txt b/packages/runtime-tags/src/__tests__/fixtures/error-html-comment-in-attrs/__snapshots__/error-compile-html.debug.txt new file mode 100644 index 00000000000..31fd71aa7e5 --- /dev/null +++ b/packages/runtime-tags/src/__tests__/fixtures/error-html-comment-in-attrs/__snapshots__/error-compile-html.debug.txt @@ -0,0 +1,8 @@ + + at packages/runtime-tags/src/__tests__/fixtures/error-html-comment-in-attrs/template.marko:2:3 + 1 |
2 | + | ^^^^ HTML comments are not supported in a tag's attributes. Use a JavaScript comment (`// …` or `/* … */`), or move the `` outside the tag. + 3 | class="foo" + 4 | >Hello
+ 5 | \ No newline at end of file diff --git a/packages/runtime-tags/src/__tests__/fixtures/error-html-comment-in-attrs/__snapshots__/error-compile-html.txt b/packages/runtime-tags/src/__tests__/fixtures/error-html-comment-in-attrs/__snapshots__/error-compile-html.txt new file mode 100644 index 00000000000..31fd71aa7e5 --- /dev/null +++ b/packages/runtime-tags/src/__tests__/fixtures/error-html-comment-in-attrs/__snapshots__/error-compile-html.txt @@ -0,0 +1,8 @@ + + at packages/runtime-tags/src/__tests__/fixtures/error-html-comment-in-attrs/template.marko:2:3 + 1 |
2 | + | ^^^^ HTML comments are not supported in a tag's attributes. Use a JavaScript comment (`// …` or `/* … */`), or move the `` outside the tag. + 3 | class="foo" + 4 | >Hello
+ 5 | \ No newline at end of file diff --git a/packages/runtime-tags/src/__tests__/fixtures/error-html-comment-in-attrs/template.marko b/packages/runtime-tags/src/__tests__/fixtures/error-html-comment-in-attrs/template.marko new file mode 100644 index 00000000000..af43a205c7f --- /dev/null +++ b/packages/runtime-tags/src/__tests__/fixtures/error-html-comment-in-attrs/template.marko @@ -0,0 +1,4 @@ +
+ class="foo" +>Hello
diff --git a/packages/runtime-tags/src/__tests__/fixtures/error-html-comment-in-attrs/test.ts b/packages/runtime-tags/src/__tests__/fixtures/error-html-comment-in-attrs/test.ts new file mode 100644 index 00000000000..87d511a1f39 --- /dev/null +++ b/packages/runtime-tags/src/__tests__/fixtures/error-html-comment-in-attrs/test.ts @@ -0,0 +1,5 @@ +import type { TestConfig } from "../../main.test"; + +export const config: TestConfig = { + error_compiler: true, +}; From a34b166d27338be21c824034b2e8af72ca95c750 Mon Sep 17 00:00:00 2001 From: LuLaValva Date: Fri, 14 Aug 2026 17:17:49 -0700 Subject: [PATCH 2/4] refactor(compiler): fold the html comment error into one throw helper Both detection sites now share `throwHTMLCommentInAttrs`, which restores `onError` to its original shape and drops the comments that stood in for the naming. Co-Authored-By: Claude Opus 5 (1M context) --- packages/compiler/src/babel-plugin/parser.js | 51 +++++++++----------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/packages/compiler/src/babel-plugin/parser.js b/packages/compiler/src/babel-plugin/parser.js index 1f7d4653c57..dfaf121a599 100644 --- a/packages/compiler/src/babel-plugin/parser.js +++ b/packages/compiler/src/babel-plugin/parser.js @@ -36,8 +36,7 @@ const withWrappedAttrValueHint = (file, part, rawValue, node) => { } return node; }; -const htmlCommentInAttrsError = - "HTML comments are not supported in a tag's attributes. Use a JavaScript comment (`// …` or `/* … */`), or move the `` outside the tag."; +const htmlCommentOpen = "` outside the tag.", + ); + }; const parseTemplateString = ({ quasis, expressions }) => { switch (expressions.length) { case 0: { @@ -148,17 +155,19 @@ export function parseMarko(file) { const parser = createParser({ onError(part) { - // htmljs-parser reads the `<` of a `` case too — though marko-js/htmljs-parser#170 raised this exact scenario and was closed as "complicates things more than it is worth", so it needs a fresh case made for the error rather than for emitting the comment. Re-verify: `compileSync('