Skip to content

Commit

Permalink
fix: parsed text placeholders should enter the text state on close qu…
Browse files Browse the repository at this point in the history
…ote char
  • Loading branch information
DylanPiercey committed Mar 15, 2023
1 parent 7a345a8 commit be73442
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/strong-deers-complain.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand Down
1 change: 1 addition & 0 deletions src/states/PARSED_STRING.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const PARSED_STRING: StateDefinition<ParsedStringMeta> = {

char(code, str) {
if (code === str.quoteCharCode) {
this.startText();
this.pos++; // skip end quote
this.exitState();
} else if (!STATE.checkForPlaceholder(this, code)) {
Expand Down

0 comments on commit be73442

Please sign in to comment.