fix(html/minifier): Fix removal of comments (#4974)

This commit is contained in:
Alexander Akait 2022-06-17 22:11:27 +03:00 committed by GitHub
parent 78ced2d65c
commit 8e63b0bbd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 40 additions and 0 deletions

View File

@ -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);

View File

@ -0,0 +1,12 @@
<!--test--><!doctype html><!--test-->
<!--test--><html lang="en"><!--test-->
<!--test--><head><!--test-->
<!--test--><title>Document</title><!--test-->
<!--test--></head><!--test-->
<!--test--><body><!--test-->
<!--test-->
<div>test</div>
<!--test-->
<!--test--></body><!--test-->
<!--test--></html><!--test-->
<!--test-->

View File

@ -0,0 +1,6 @@
<!doctype html><html lang=en><title>Document</title><body>
<div>test</div>

View File

@ -13,5 +13,9 @@
test
</div>
</template>
<template>
<!-- test -->
<div>Test</div>
</template>
</body>
</html>

View File

@ -4,4 +4,8 @@
test
</div>
</template>
<template>
<div>Test</div>
</template>