Skip to content

Commit e45a9b3

Browse files
authored
Fix parsing error for top level html commentv (#160)
1 parent a3ce155 commit e45a9b3

File tree

4 files changed

+1258
-1
lines changed

4 files changed

+1258
-1
lines changed

src/context/index.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -260,12 +260,15 @@ type Block = {
260260

261261
/** Extract <script> blocks */
262262
function* extractBlocks(code: string): IterableIterator<Block> {
263-
const startTagOpenRe = /<(script|style)([\s>])/giu
263+
const startTagOpenRe = /<!--[\s\S]*?-->|<(script|style)([\s>])/giu
264264
const endScriptTagRe = /<\/script>/giu
265265
const endStyleTagRe = /<\/style>/giu
266266
let startTagOpenMatch
267267
while ((startTagOpenMatch = startTagOpenRe.exec(code))) {
268268
const [, tag, nextChar] = startTagOpenMatch
269+
if (!tag) {
270+
continue
271+
}
269272
let startTagEnd = startTagOpenRe.lastIndex
270273

271274
let attrs: AttributeToken[] = []
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<!-- <script> -->
2+
<script>
3+
let a = '';
4+
</script>
5+
<input type="number" bind:value={a}>

0 commit comments

Comments
 (0)