-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0ef31cd
commit fe98530
Showing
6 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"htmljs-parser": patch | ||
--- | ||
|
||
Fixes an regression where string literals inside of parsed text nodes (eg `<script>`) were not properly changing the parser state. This caused issues when comment like syntax was embedded within these string literals" |
30 changes: 30 additions & 0 deletions
30
src/__tests__/fixtures/script-with-strings/__snapshots__/script-with-strings.expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
1╭─ <script> | ||
│ ││ ╰─ openTagEnd | ||
│ │╰─ tagName "script" | ||
╰─ ╰─ openTagStart | ||
2╭─ "this is a ${test}" | ||
│ │ │ ╰─ 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 " | ||
4├─ "/*" | ||
5├─ "//" | ||
6╭─ 'this is a ${test}' | ||
│ │ ╰─ 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 " | ||
8├─ '/*' | ||
9├─ '//' | ||
10├─ `this is a ${test}` | ||
11├─ `this is a \${test}` | ||
12├─ `/*` | ||
13├─ `//` | ||
14╭─ </script> | ||
│ │ │ ╰─ closeTagEnd(script) | ||
│ │ ╰─ closeTagName "script" | ||
╰─ ╰─ closeTagStart "</" | ||
15╰─ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<script> | ||
"this is a ${test}" | ||
"this is a \${test}" | ||
"/*" | ||
"//" | ||
'this is a ${test}' | ||
'this is a \${test}' | ||
'/*' | ||
'//' | ||
`this is a ${test}` | ||
`this is a \${test}` | ||
`/*` | ||
`//` | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { CODE, ErrorCode, STATE, StateDefinition, Meta } from "../internal"; | ||
|
||
interface ParsedStringMeta extends Meta { | ||
quoteCharCode: number; | ||
} | ||
|
||
export const PARSED_STRING: StateDefinition<ParsedStringMeta> = { | ||
name: "PARSED_STRING", | ||
|
||
enter(parent, start) { | ||
return { | ||
state: PARSED_STRING, | ||
parent, | ||
start, | ||
end: start, | ||
quoteCharCode: CODE.DOUBLE_QUOTE, | ||
} as ParsedStringMeta; | ||
}, | ||
|
||
exit() {}, | ||
|
||
char(code, str) { | ||
if (code === str.quoteCharCode) { | ||
this.pos++; // skip end quote | ||
this.exitState(); | ||
} else if (!STATE.checkForPlaceholder(this, code)) { | ||
this.startText(); | ||
} | ||
}, | ||
|
||
eof(str) { | ||
this.emitError( | ||
str, | ||
ErrorCode.INVALID_TEMPLATE_STRING, | ||
"EOF reached while parsing string expression" | ||
); | ||
}, | ||
|
||
eol() {}, | ||
|
||
return() {}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters