Skip to content

Commit 5d9c02c

Browse files
committed
fix: incorrect whitespace removal in concise mode html blocks
1 parent b2389dd commit 5d9c02c

7 files changed

Lines changed: 50 additions & 2 deletions

File tree

.changeset/metal-bobcats-bathe.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+
Fix regression which incorrectly removed some whitespace in concise mode html blocks.

src/__tests__/fixtures/argument-tag-nested-parens/__snapshots__/argument-tag-nested-parens.expected.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
3╭─ </if>
99
│ │ │ ╰─ closeTagEnd(if)
1010
│ │ ╰─ closeTagName "if"
11+
│ ├─ text "\n"
1112
╰─ ╰─ closeTagStart "</"
1213
4╰─ ---
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
1╭─ ---
2+
2╭─ 1
3+
╰─ ╰─ text "1\n"
4+
3╭─ <div>
5+
│ ││ ╰─ openTagEnd
6+
│ │╰─ tagName "div"
7+
╰─ ╰─ openTagStart
8+
4╭─ 2
9+
╰─ ╰─ text "\n 2\n"
10+
5╭─ </div>
11+
│ │ │ ╰─ closeTagEnd(div)
12+
│ │ ╰─ closeTagName "div"
13+
╰─ ╰─ closeTagStart "</"
14+
6╭─ 3
15+
╰─ ╰─ text "\n3\n"
16+
7╭─ <div>
17+
│ ││ ╰─ openTagEnd
18+
│ │╰─ tagName "div"
19+
╰─ ╰─ openTagStart
20+
8╭─ 4
21+
╰─ ╰─ text "\n 4\n"
22+
9╭─ </div>
23+
│ │ │ ╰─ closeTagEnd(div)
24+
│ │ ╰─ closeTagName "div"
25+
╰─ ╰─ closeTagStart "</"
26+
10╭─ 5
27+
╰─ ╰─ text "\n5"
28+
11├─ ---
29+
12╰─
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
1
3+
<div>
4+
2
5+
</div>
6+
3
7+
<div>
8+
4
9+
</div>
10+
5
11+
---

src/__tests__/fixtures/multiline-html-block/__snapshots__/multiline-html-block.expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
│ │ ╰─ openTagStart
1010
╰─ ╰─ text "Hello "
1111
3╭─ Line 2
12-
╰─ ╰─ text "Line 2"
12+
╰─ ╰─ text "\nLine 2"
1313
4╰─ ---

src/__tests__/fixtures/open-tag-only-with-body/__snapshots__/open-tag-only-with-body.expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
│ │╰─ tagName "img"
88
╰─ ╰─ openTagStart
99
3╭─ This is not allowed!
10-
╰─ ╰─ text " This is not allowed!\n"
10+
╰─ ╰─ text "\n This is not allowed!\n"
1111
4╭─ </img>
1212
│ ├─ error(EXTRA_CLOSING_TAG:The closing "img" tag was not expected) "</img>"
1313
╰─ ╰─ closeTagStart "</"

src/states/BEGIN_DELIMITED_HTML_BLOCK.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,5 +137,7 @@ function handleDelimitedBlockEOL(
137137
parser.pos = pos;
138138
parser.exitState();
139139
parser.exitState();
140+
} else if (!first && parser.pos + newLineLength !== parser.maxPos) {
141+
parser.startText();
140142
}
141143
}

0 commit comments

Comments
 (0)