Skip to content

Commit eb9865c

Browse files
committed
fix: avoid startText at eof
1 parent fa1a801 commit eb9865c

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

.changeset/fresh-words-fail.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"htmljs-parser": patch
3+
---
4+
5+
Avoid startText call at eof.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
1╭─ --
2+
2╭─ hi
3+
╰─ ╰─ text "\nhi\n"
4+
3├─ --
5+
4├─
6+
5├─ --
7+
6╭─ foo
8+
╰─ ╰─ text "\nfoo\n\n"
9+
7├─
10+
8╰─
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
--
2+
hi
3+
--
4+
5+
--
6+
foo
7+

src/states/BEGIN_DELIMITED_HTML_BLOCK.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ function handleDelimitedBlockEOL(
101101
parser.pos += endHtmlBlockLookahead.length;
102102

103103
if (parser.consumeWhitespaceOnLine(0)) {
104-
parser.endText();
105104
parser.exitState();
106105
parser.exitState();
107106
} else {
@@ -115,7 +114,6 @@ function handleDelimitedBlockEOL(
115114
// We know the next line does not end the multiline HTML block, but we need to check if there
116115
// is any indentation that we need to skip over as we continue parsing the HTML in this
117116
// multiline HTML block
118-
119117
parser.startText();
120118
parser.pos += indent.length;
121119
// We stay in the same state since we are still parsing a multiline, delimited HTML block
@@ -126,7 +124,7 @@ function handleDelimitedBlockEOL(
126124
parser.endText();
127125
parser.exitState();
128126
parser.exitState();
129-
} else {
127+
} else if (parser.pos + newLineLength !== parser.maxPos) {
130128
parser.startText();
131129
}
132130
}

0 commit comments

Comments
 (0)