From 6bb6ba4a98df053220de012b8c797bf81e4444a4 Mon Sep 17 00:00:00 2001 From: Dylan Piercey Date: Wed, 15 Mar 2023 13:20:00 -0700 Subject: [PATCH] fix: parsed text placeholders should enter the text state on close quote char --- .changeset/strong-deers-complain.md | 5 +++++ .../__snapshots__/script-with-strings.expected.txt | 8 ++++---- src/states/PARSED_STRING.ts | 1 + 3 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 .changeset/strong-deers-complain.md diff --git a/.changeset/strong-deers-complain.md b/.changeset/strong-deers-complain.md new file mode 100644 index 00000000..609ce3c5 --- /dev/null +++ b/.changeset/strong-deers-complain.md @@ -0,0 +1,5 @@ +--- +"htmljs-parser": patch +--- + +Fixes a regression where the parsed text state (used by eg `script`, `style`) was not properly entering back into text for the closing quote on the string. diff --git a/src/__tests__/fixtures/script-with-strings/__snapshots__/script-with-strings.expected.txt b/src/__tests__/fixtures/script-with-strings/__snapshots__/script-with-strings.expected.txt index e56d5baf..c804a9bd 100644 --- a/src/__tests__/fixtures/script-with-strings/__snapshots__/script-with-strings.expected.txt +++ b/src/__tests__/fixtures/script-with-strings/__snapshots__/script-with-strings.expected.txt @@ -3,20 +3,20 @@ │ │╰─ tagName "script" ╰─ ╰─ openTagStart 2╭─ "this is a ${test}" + │ │ │ │ ╰─ text "\"\n \"this is a " │ │ │ ╰─ placeholder:escape.value "test" │ │ ╰─ placeholder:escape "${test}" ╰─ ╰─ text "\n \"this is a " 3╭─ "this is a \${test}" - │ │ ╰─ text "${test}\"\n \"/*\"\n \"//\"\n 'this is a " - ╰─ ╰─ text "\n \"this is a " + ╰─ ╰─ text "${test}\"\n \"/*\"\n \"//\"\n 'this is a " 4├─ "/*" 5├─ "//" 6╭─ 'this is a ${test}' + │ │ │ ╰─ text "'\n 'this is a " │ │ ╰─ placeholder:escape.value "test" ╰─ ╰─ placeholder:escape "${test}" 7╭─ 'this is a \${test}' - │ │ ╰─ text "${test}'\n '/*'\n '//'\n `this is a ${test}`\n `this is a \\${test}`\n `/*`\n `//`\n" - ╰─ ╰─ text "\n 'this is a " + ╰─ ╰─ text "${test}'\n '/*'\n '//'\n `this is a ${test}`\n `this is a \\${test}`\n `/*`\n `//`\n" 8├─ '/*' 9├─ '//' 10├─ `this is a ${test}` diff --git a/src/states/PARSED_STRING.ts b/src/states/PARSED_STRING.ts index 7ef88e29..ef1324bc 100644 --- a/src/states/PARSED_STRING.ts +++ b/src/states/PARSED_STRING.ts @@ -21,6 +21,7 @@ export const PARSED_STRING: StateDefinition = { char(code, str) { if (code === str.quoteCharCode) { + this.startText(); this.pos++; // skip end quote this.exitState(); } else if (!STATE.checkForPlaceholder(this, code)) {