Skip to content

Commit 8bd3c40

Browse files
authored
fix: onCloseTagStart event for text mode tags (#117)
1 parent 963c28d commit 8bd3c40

File tree

14 files changed

+47
-25
lines changed

14 files changed

+47
-25
lines changed

.changeset/late-cougars-attend.md

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+
Fix issue with onCloseTagStart not called for text mode tags (eg style, script, textarea & html-comment).

src/__tests__/fixtures/cdata/__snapshots__/cdata.expected.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
1╭─ <html-comment><![CDATA[[if lt IE 9]><div><![endif]]]></html-comment>
2-
│ ││ ││ │ │ ╰─ closeTagEnd(html-comment)
3-
│ ││ ││ │ ╰─ closeTagName "html-comment"
2+
│ ││ ││ │ │ │ ╰─ closeTagEnd(html-comment)
3+
│ ││ ││ │ │ ╰─ closeTagName "html-comment"
4+
│ ││ ││ │ ╰─ closeTagStart "</"
45
│ ││ ││ ╰─ cdata.value "[if lt IE 9]><div><![endif]"
56
│ ││ │╰─ cdata "<![CDATA[[if lt IE 9]><div><![endif]]]>"
67
│ ││ ╰─ openTagEnd

src/__tests__/fixtures/html-comment-tag/__snapshots__/html-comment-tag.expected.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
│ │ ╰─ comment "<!--123-->"
88
╰─ ╰─ text "\n "
99
3╭─ <html-comment>abc</html-comment>
10-
│ │ ││ ││ │ ╰─ closeTagEnd(html-comment)
11-
│ │ ││ ││ ╰─ closeTagName "html-comment"
10+
│ │ ││ ││ │ │ ╰─ closeTagEnd(html-comment)
11+
│ │ ││ ││ │ ╰─ closeTagName "html-comment"
12+
│ │ ││ ││ ╰─ closeTagStart "</"
1213
│ │ ││ │╰─ text "abc"
1314
│ │ ││ ╰─ openTagEnd
1415
│ │ │╰─ tagName "html-comment"
@@ -19,8 +20,9 @@
1920
│ │ ╰─ comment "<!--[if lt IE 9]><script src=\"...\"></script><![endif]-->"
2021
╰─ ╰─ text "\n "
2122
5╭─ <html-comment>[if lt IE 9]><script src="..."></script><![endif]</html-comment>
22-
│ │ ││ ││ │ ╰─ closeTagEnd(html-comment)
23-
│ │ ││ ││ ╰─ closeTagName "html-comment"
23+
│ │ ││ ││ │ │ ╰─ closeTagEnd(html-comment)
24+
│ │ ││ ││ │ ╰─ closeTagName "html-comment"
25+
│ │ ││ ││ ╰─ closeTagStart "</"
2426
│ │ ││ │╰─ text "[if lt IE 9]><script src=\"...\"></script><![endif]"
2527
│ │ ││ ╰─ openTagEnd
2628
│ │ │╰─ tagName "html-comment"

src/__tests__/fixtures/parsed-text-placeholder-in-template-literal-string/__snapshots__/parsed-text-placeholder-in-template-literal-string.expected.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
5├─ ${bar}
1010
6├─ */
1111
7╭─ </script>
12-
│ │ ╰─ closeTagEnd(script)
13-
╰─ ╰─ closeTagName "script"
12+
│ │ │ ╰─ closeTagEnd(script)
13+
│ │ ╰─ closeTagName "script"
14+
╰─ ╰─ closeTagStart "</"
1415
8╰─

src/__tests__/fixtures/parsed-text-style-tag/__snapshots__/parsed-text-style-tag.expected.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
1╭─ <style>/* block comment within <style> */"string within \"<style>\""'string within \'<style>\''</style>
2-
│ ││ ││ │ ╰─ closeTagEnd(style)
3-
│ ││ ││ ╰─ closeTagName "style"
2+
│ ││ ││ │ │ ╰─ closeTagEnd(style)
3+
│ ││ ││ │ ╰─ closeTagName "style"
4+
│ ││ ││ ╰─ closeTagStart "</"
45
│ ││ │╰─ text "/* block comment within <style> */\"string within \\\"<style>\\\"\"'string within \\'<style>\\''"
56
│ ││ ╰─ openTagEnd
67
│ │╰─ tagName "style"

src/__tests__/fixtures/placeholder-body-multi-line-js-comment/__snapshots__/placeholder-body-multi-line-js-comment.expected.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
1╭─ <script>/* Copyright $!{date} */</script>
2-
│ ││ ││ │ ╰─ closeTagEnd(script)
3-
│ ││ ││ ╰─ closeTagName "script"
2+
│ ││ ││ │ │ ╰─ closeTagEnd(script)
3+
│ ││ ││ │ ╰─ closeTagName "script"
4+
│ ││ ││ ╰─ closeTagStart "</"
45
│ ││ │╰─ text "/* Copyright $!{date} */"
56
│ ││ ╰─ openTagEnd
67
│ │╰─ tagName "script"

src/__tests__/fixtures/placeholder-body-single-line-js-comment/__snapshots__/placeholder-body-single-line-js-comment.expected.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
│ │╰─ tagName "script"
55
╰─ ╰─ openTagStart
66
2╭─ </script>
7-
│ │ ╰─ closeTagEnd(script)
8-
╰─ ╰─ closeTagName "script"
7+
│ │ │ ╰─ closeTagEnd(script)
8+
│ │ ╰─ closeTagName "script"
9+
╰─ ╰─ closeTagStart "</"

src/__tests__/fixtures/placeholder-within-script-tag/__snapshots__/placeholder-within-script-tag.expected.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
1╭─ <script>Hello ${xyz}!</script>
2-
│ ││ ││ │ │ │ │ ╰─ closeTagEnd(script)
3-
│ ││ ││ │ │ │ ╰─ closeTagName "script"
2+
│ ││ ││ │ │ ││ │ ╰─ closeTagEnd(script)
3+
│ ││ ││ │ │ ││ ╰─ closeTagName "script"
4+
│ ││ ││ │ │ │╰─ closeTagStart "</"
45
│ ││ ││ │ │ ╰─ text
56
│ ││ ││ │ ╰─ placeholder:escape.value "xyz"
67
│ ││ ││ ╰─ placeholder:escape "${xyz}"

src/__tests__/fixtures/placeholder-within-script-within-string/__snapshots__/placeholder-within-script-within-string.expected.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
1╭─ <script>alert("Hello ${xyz}!")</script>
2-
│ ││ ││ │ │ │ │ ╰─ closeTagEnd(script)
3-
│ ││ ││ │ │ │ ╰─ closeTagName "script"
2+
│ ││ ││ │ │ │ │ │ ╰─ closeTagEnd(script)
3+
│ ││ ││ │ │ │ │ ╰─ closeTagName "script"
4+
│ ││ ││ │ │ │ ╰─ closeTagStart "</"
45
│ ││ ││ │ │ ╰─ text "!\")"
56
│ ││ ││ │ ╰─ placeholder:escape.value "xyz"
67
│ ││ ││ ╰─ placeholder:escape "${xyz}"

src/__tests__/fixtures/script-escaped-placeholder/__snapshots__/script-escaped-placeholder.expected.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@
1111
4╭─ </script>
1212
│ │ │ ╰─ closeTagEnd(script)
1313
│ │ ╰─ closeTagName "script"
14-
╰─ ╰─ text "\n"
14+
│ ├─ text "\n"
15+
╰─ ╰─ closeTagStart "</"

0 commit comments

Comments
 (0)