From 21f85da13e595d5f7f5fb05664bf40a85c75b9dd Mon Sep 17 00:00:00 2001 From: dpiercey Date: Mon, 14 Jul 2025 16:10:21 -0700 Subject: [PATCH] fix: avoid startText at eof --- .changeset/fresh-words-fail.md | 5 +++++ .../concise-multiline-content.expected.txt | 10 ++++++++++ .../fixtures/concise-multiline-content/input.marko | 7 +++++++ src/states/BEGIN_DELIMITED_HTML_BLOCK.ts | 4 +--- 4 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 .changeset/fresh-words-fail.md create mode 100644 src/__tests__/fixtures/concise-multiline-content/__snapshots__/concise-multiline-content.expected.txt create mode 100644 src/__tests__/fixtures/concise-multiline-content/input.marko diff --git a/.changeset/fresh-words-fail.md b/.changeset/fresh-words-fail.md new file mode 100644 index 00000000..adde5e28 --- /dev/null +++ b/.changeset/fresh-words-fail.md @@ -0,0 +1,5 @@ +--- +"htmljs-parser": patch +--- + +Avoid startText call at eof. diff --git a/src/__tests__/fixtures/concise-multiline-content/__snapshots__/concise-multiline-content.expected.txt b/src/__tests__/fixtures/concise-multiline-content/__snapshots__/concise-multiline-content.expected.txt new file mode 100644 index 00000000..ff3cce84 --- /dev/null +++ b/src/__tests__/fixtures/concise-multiline-content/__snapshots__/concise-multiline-content.expected.txt @@ -0,0 +1,10 @@ +1╭─ -- +2╭─ hi + ╰─ ╰─ text "\nhi\n" +3├─ -- +4├─ +5├─ -- +6╭─ foo + ╰─ ╰─ text "\nfoo\n\n" +7├─ +8╰─ \ No newline at end of file diff --git a/src/__tests__/fixtures/concise-multiline-content/input.marko b/src/__tests__/fixtures/concise-multiline-content/input.marko new file mode 100644 index 00000000..0cf55b4a --- /dev/null +++ b/src/__tests__/fixtures/concise-multiline-content/input.marko @@ -0,0 +1,7 @@ +-- +hi +-- + +-- +foo + diff --git a/src/states/BEGIN_DELIMITED_HTML_BLOCK.ts b/src/states/BEGIN_DELIMITED_HTML_BLOCK.ts index 377904da..5b7036c7 100644 --- a/src/states/BEGIN_DELIMITED_HTML_BLOCK.ts +++ b/src/states/BEGIN_DELIMITED_HTML_BLOCK.ts @@ -101,7 +101,6 @@ function handleDelimitedBlockEOL( parser.pos += endHtmlBlockLookahead.length; if (parser.consumeWhitespaceOnLine(0)) { - parser.endText(); parser.exitState(); parser.exitState(); } else { @@ -115,7 +114,6 @@ function handleDelimitedBlockEOL( // We know the next line does not end the multiline HTML block, but we need to check if there // is any indentation that we need to skip over as we continue parsing the HTML in this // multiline HTML block - parser.startText(); parser.pos += indent.length; // We stay in the same state since we are still parsing a multiline, delimited HTML block @@ -126,7 +124,7 @@ function handleDelimitedBlockEOL( parser.endText(); parser.exitState(); parser.exitState(); - } else { + } else if (parser.pos + newLineLength !== parser.maxPos) { parser.startText(); } }