Skip to content

Commit

Permalink
fix: scriptlet block with semi-colon (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey authored Feb 7, 2023
1 parent e864b4b commit 948830e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/gentle-bugs-beg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"htmljs-parser": patch
---

Fix issue with semi-colon after a block scriptlet.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
1╭─ $ { hello() };
│ │ ╰─ scriptlet:block.value " hello() "
╰─ ╰─ scriptlet:block " { hello() };"
2├─
3╭─ $ { hello() } ;
│ │ ╰─ scriptlet:block.value " hello() "
╰─ ╰─ scriptlet:block " { hello() } ;"
4├─
5╭─ $ { hello() };
│ │ ╰─ scriptlet:block.value " hello() "
╰─ ╰─ scriptlet:block " { hello() };"
6├─
7╰─
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
$ { hello() };

$ { hello() } ;

$ { hello() };

10 changes: 9 additions & 1 deletion src/states/INLINE_SCRIPT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,15 @@ export const INLINE_SCRIPT: StateDefinition<ScriptletMeta> = {
},

return(child, inlineScript) {
if (inlineScript.block) this.pos++; // skip }
if (inlineScript.block) {
this.pos++; // skip }
if (
this.lookAtCharCodeAhead(0) === CODE.SEMICOLON ||
this.consumeWhitespaceIfBefore(";")
) {
this.pos++;
}
}
inlineScript.value.start = child.start;
inlineScript.value.end = child.end;
this.exitState();
Expand Down

0 comments on commit 948830e

Please sign in to comment.