Skip to content

Commit 948830e

Browse files
authored
fix: scriptlet block with semi-colon (#148)
1 parent e864b4b commit 948830e

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

.changeset/gentle-bugs-beg.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 with semi-colon after a block scriptlet.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
1╭─ $ { hello() };
2+
│ │ ╰─ scriptlet:block.value " hello() "
3+
╰─ ╰─ scriptlet:block " { hello() };"
4+
2├─
5+
3╭─ $ { hello() } ;
6+
│ │ ╰─ scriptlet:block.value " hello() "
7+
╰─ ╰─ scriptlet:block " { hello() } ;"
8+
4├─
9+
5╭─ $ { hello() };
10+
│ │ ╰─ scriptlet:block.value " hello() "
11+
╰─ ╰─ scriptlet:block " { hello() };"
12+
6├─
13+
7╰─
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
$ { hello() };
2+
3+
$ { hello() } ;
4+
5+
$ { hello() };
6+

src/states/INLINE_SCRIPT.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,15 @@ export const INLINE_SCRIPT: StateDefinition<ScriptletMeta> = {
6060
},
6161

6262
return(child, inlineScript) {
63-
if (inlineScript.block) this.pos++; // skip }
63+
if (inlineScript.block) {
64+
this.pos++; // skip }
65+
if (
66+
this.lookAtCharCodeAhead(0) === CODE.SEMICOLON ||
67+
this.consumeWhitespaceIfBefore(";")
68+
) {
69+
this.pos++;
70+
}
71+
}
6472
inlineScript.value.start = child.start;
6573
inlineScript.value.end = child.end;
6674
this.exitState();

0 commit comments

Comments
 (0)