diff --git a/.changeset/gentle-bugs-beg.md b/.changeset/gentle-bugs-beg.md new file mode 100644 index 00000000..91fe1b2d --- /dev/null +++ b/.changeset/gentle-bugs-beg.md @@ -0,0 +1,5 @@ +--- +"htmljs-parser": patch +--- + +Fix issue with semi-colon after a block scriptlet. diff --git a/src/__tests__/fixtures/scriptlet-block-with-semi-colon/__snapshots__/scriptlet-block-with-semi-colon.expected.txt b/src/__tests__/fixtures/scriptlet-block-with-semi-colon/__snapshots__/scriptlet-block-with-semi-colon.expected.txt new file mode 100644 index 00000000..389661d1 --- /dev/null +++ b/src/__tests__/fixtures/scriptlet-block-with-semi-colon/__snapshots__/scriptlet-block-with-semi-colon.expected.txt @@ -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╰─ \ No newline at end of file diff --git a/src/__tests__/fixtures/scriptlet-block-with-semi-colon/input.marko b/src/__tests__/fixtures/scriptlet-block-with-semi-colon/input.marko new file mode 100644 index 00000000..995b8058 --- /dev/null +++ b/src/__tests__/fixtures/scriptlet-block-with-semi-colon/input.marko @@ -0,0 +1,6 @@ +$ { hello() }; + +$ { hello() } ; + +$ { hello() }; + diff --git a/src/states/INLINE_SCRIPT.ts b/src/states/INLINE_SCRIPT.ts index 83e2d3cb..1b11c9e6 100644 --- a/src/states/INLINE_SCRIPT.ts +++ b/src/states/INLINE_SCRIPT.ts @@ -60,7 +60,15 @@ export const INLINE_SCRIPT: StateDefinition = { }, 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();