Skip to content

Commit 635b97c

Browse files
authored
fix: issue with escaped placeholder at end of tag (#143)
1 parent 76d00ee commit 635b97c

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

.changeset/afraid-monkeys-walk.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 issue where and extra character was being consumed if an escaped placeholder was at the end of a tag.

src/__tests__/fixtures/placeholder-backslash/__snapshots__/placeholder-backslash.expected.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,14 @@
6767
│ │ │╰─ closeTagEnd(d)
6868
│ │ ╰─ closeTagName
6969
│ ├─ text "\n"
70-
╰─ ╰─ closeTagStart "</"
70+
╰─ ╰─ closeTagStart "</"
71+
16├─
72+
17╭─ <e>\${</e>
73+
│ │││ │ │ │╰─ closeTagEnd(e)
74+
│ │││ │ │ ╰─ closeTagName
75+
│ │││ │ ╰─ closeTagStart "</"
76+
│ │││ ╰─ text "${"
77+
│ ││╰─ openTagEnd
78+
│ │╰─ tagName
79+
╰─ ╰─ openTagStart
80+
18╰─

src/__tests__/fixtures/placeholder-backslash/input.marko

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@
1212
</c>
1313
<d>
1414
\\$!{test}
15-
</d>
15+
</d>
16+
17+
<e>\${</e>

src/states/PLACEHOLDER.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ export function checkForPlaceholder(parser: Parser, code: number) {
7373
}
7474

7575
if (curCode === CODE.OPEN_CURLY_BRACE) {
76+
parser.forward = 0;
77+
7678
if (ahead) {
7779
const remainder = ahead % 2;
7880
const extra = (ahead + remainder) / 2; // Number of backslashes to omit from output.
@@ -94,7 +96,6 @@ export function checkForPlaceholder(parser: Parser, code: number) {
9496
parser.endText();
9597
parser.enterState(PLACEHOLDER).escape = escape;
9698
parser.pos += escape ? 2 : 3; // skip ${ or $!{
97-
parser.forward = 0;
9899
parser.enterState(STATE.EXPRESSION).shouldTerminate =
99100
matchesCloseCurlyBrace;
100101
return true;

0 commit comments

Comments
 (0)