Skip to content

Commit be73442

Browse files
committed
fix: parsed text placeholders should enter the text state on close quote char
1 parent 7a345a8 commit be73442

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed
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+
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.

src/__tests__/fixtures/script-with-strings/__snapshots__/script-with-strings.expected.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
│ │╰─ tagName "script"
44
╰─ ╰─ openTagStart
55
2╭─ "this is a ${test}"
6+
│ │ │ │ ╰─ text "\"\n \"this is a "
67
│ │ │ ╰─ placeholder:escape.value "test"
78
│ │ ╰─ placeholder:escape "${test}"
89
╰─ ╰─ text "\n \"this is a "
910
3╭─ "this is a \${test}"
10-
│ │ ╰─ text "${test}\"\n \"/*\"\n \"//\"\n 'this is a "
11-
╰─ ╰─ text "\n \"this is a "
11+
╰─ ╰─ text "${test}\"\n \"/*\"\n \"//\"\n 'this is a "
1212
4├─ "/*"
1313
5├─ "//"
1414
6╭─ 'this is a ${test}'
15+
│ │ │ ╰─ text "'\n 'this is a "
1516
│ │ ╰─ placeholder:escape.value "test"
1617
╰─ ╰─ placeholder:escape "${test}"
1718
7╭─ 'this is a \${test}'
18-
│ │ ╰─ text "${test}'\n '/*'\n '//'\n `this is a ${test}`\n `this is a \\${test}`\n `/*`\n `//`\n"
19-
╰─ ╰─ text "\n 'this is a "
19+
╰─ ╰─ text "${test}'\n '/*'\n '//'\n `this is a ${test}`\n `this is a \\${test}`\n `/*`\n `//`\n"
2020
8├─ '/*'
2121
9├─ '//'
2222
10├─ `this is a ${test}`

src/states/PARSED_STRING.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export const PARSED_STRING: StateDefinition<ParsedStringMeta> = {
2121

2222
char(code, str) {
2323
if (code === str.quoteCharCode) {
24+
this.startText();
2425
this.pos++; // skip end quote
2526
this.exitState();
2627
} else if (!STATE.checkForPlaceholder(this, code)) {

0 commit comments

Comments
 (0)