From e3558d6865001b580b334b0229bf680de2403ab9 Mon Sep 17 00:00:00 2001 From: Corbin Crutchley Date: Wed, 13 May 2026 21:55:59 -0400 Subject: [PATCH] chore: add HTML comments as tests --- .../tests/__snapshots__/index.spec.ts.snap | 8 +++++ packages/compiler/tests/index.spec.ts | 9 +++++ packages/parser/tests/root-lexer.spec.ts | 35 +++++++++++++++++++ packages/parser/tests/root-parser.spec.ts | 27 ++++++++++++++ sample/comments.json.blot | 11 ++++++ 5 files changed, 90 insertions(+) create mode 100644 sample/comments.json.blot diff --git a/packages/compiler/tests/__snapshots__/index.spec.ts.snap b/packages/compiler/tests/__snapshots__/index.spec.ts.snap index ac3b338..1bbb64e 100644 --- a/packages/compiler/tests/__snapshots__/index.spec.ts.snap +++ b/packages/compiler/tests/__snapshots__/index.spec.ts.snap @@ -8,6 +8,14 @@ exports[`compiles a basic file 1`] = ` " `; +exports[`compiles a file with top-level HTML comments 1`] = ` +" +{ + "test": 123 +} +" +`; + exports[`compiles a top-level await file 1`] = ` " { diff --git a/packages/compiler/tests/index.spec.ts b/packages/compiler/tests/index.spec.ts index 20e6684..b2be1e4 100644 --- a/packages/compiler/tests/index.spec.ts +++ b/packages/compiler/tests/index.spec.ts @@ -45,6 +45,15 @@ test("compiles an import file", async () => { expect(result).toMatchSnapshot(); }); +test("compiles a file with top-level HTML comments", async () => { + const result = await compilePath( + path.resolve(__dirname, "../../../sample/comments.json.blot"), + undefined, + ); + + expect(result).toMatchSnapshot(); +}); + test("passes params to a tempblot file", async () => { const result = await compilePath( path.resolve(__dirname, "../../../sample/params.json.blot"), diff --git a/packages/parser/tests/root-lexer.spec.ts b/packages/parser/tests/root-lexer.spec.ts index 29d1340..9a00e9d 100644 --- a/packages/parser/tests/root-lexer.spec.ts +++ b/packages/parser/tests/root-lexer.spec.ts @@ -78,3 +78,38 @@ const hello = 123; { type: "TagClose", attributes: { name: "output" } }, ]); }); + +test("tokenizeRoot ignores top-level HTML comments", () => { + const source = ` + + +const setup = 123; + + + +{ + "test": <> +} + + +`.trim(); + + const tokens = tokenizeRoot(source); + expect(withoutOffsets(tokens)).toStrictEqual([ + { type: "Text", attributes: { value: "\n" } }, + { type: "TagOpenStart", attributes: { name: "setup" } }, + { type: "TagOpenEnd", attributes: { name: "setup" } }, + { type: "Text", attributes: { value: "\nconst setup = 123;\n" } }, + { type: "TagClose", attributes: { name: "setup" } }, + { + type: "Text", + attributes: { value: "\n\n" }, + }, + { type: "TagOpenStart", attributes: { name: "output" } }, + { type: "TagAttribute", attributes: { name: "lang", value: "json" } }, + { type: "TagOpenEnd", attributes: { name: "output" } }, + { type: "Text", attributes: { value: "\n{\n \"test\": <>\n}\n" } }, + { type: "TagClose", attributes: { name: "output" } }, + { type: "Text", attributes: { value: "\n" } }, + ]); +}); diff --git a/packages/parser/tests/root-parser.spec.ts b/packages/parser/tests/root-parser.spec.ts index cd31277..84e6754 100644 --- a/packages/parser/tests/root-parser.spec.ts +++ b/packages/parser/tests/root-parser.spec.ts @@ -38,3 +38,30 @@ const setup = 123; expect(root.setup.startTagEnd).toBe(source.indexOf(">") + 1); expect(root.output.contents).toContain("<>"); }); + +test("parseRoot ignores top-level HTML comments", () => { + const sourceWithComments = ` + + +const setup = 123; + + + +{ + "test": <> +} + + +`.trim(); + + const root = parseRoot(tokenizeRoot(sourceWithComments)); + + expect(root.setup.contents).toBe(` +const setup = 123; +`); + expect(root.output.contents).toBe(` +{ + "test": <> +} +`); +}); diff --git a/sample/comments.json.blot b/sample/comments.json.blot new file mode 100644 index 0000000..e2c99ad --- /dev/null +++ b/sample/comments.json.blot @@ -0,0 +1,11 @@ + + +const hello = 123; + + + +{ + "test": <> +} + + -- 2.51.2