diff --git a/crates/swc_html_minifier/src/lib.rs b/crates/swc_html_minifier/src/lib.rs index 7836025bcaa..d916f211510 100644 --- a/crates/swc_html_minifier/src/lib.rs +++ b/crates/swc_html_minifier/src/lib.rs @@ -598,6 +598,20 @@ impl Minifier { } impl VisitMut for Minifier { + fn visit_mut_document(&mut self, n: &mut Document) { + n.visit_mut_children_with(self); + + n.children + .retain(|child| !matches!(child, Child::Comment(_))); + } + + fn visit_mut_document_fragment(&mut self, n: &mut DocumentFragment) { + n.visit_mut_children_with(self); + + n.children + .retain(|child| !matches!(child, Child::Comment(_))); + } + fn visit_mut_document_type(&mut self, n: &mut DocumentType) { n.visit_mut_children_with(self); diff --git a/crates/swc_html_minifier/tests/fixture/comment/html/input.html b/crates/swc_html_minifier/tests/fixture/comment/html/input.html new file mode 100644 index 00000000000..02aaf684967 --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/comment/html/input.html @@ -0,0 +1,12 @@ + + + + Document + + + +
test
+ + + + \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/comment/html/output.min.html b/crates/swc_html_minifier/tests/fixture/comment/html/output.min.html new file mode 100644 index 00000000000..3d8c66016a5 --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/comment/html/output.min.html @@ -0,0 +1,6 @@ +Document + +
test
+ + + diff --git a/crates/swc_html_minifier/tests/fixture/element/template/input.html b/crates/swc_html_minifier/tests/fixture/element/template/input.html index 0473730d51d..a483845bb73 100644 --- a/crates/swc_html_minifier/tests/fixture/element/template/input.html +++ b/crates/swc_html_minifier/tests/fixture/element/template/input.html @@ -13,5 +13,9 @@ test + \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/element/template/output.min.html b/crates/swc_html_minifier/tests/fixture/element/template/output.min.html index f47d32432ac..afeac58c8f8 100644 --- a/crates/swc_html_minifier/tests/fixture/element/template/output.min.html +++ b/crates/swc_html_minifier/tests/fixture/element/template/output.min.html @@ -4,4 +4,8 @@ test +