mirror of
https://github.com/swc-project/swc.git
synced 2024-12-25 14:43:33 +03:00
fix(html/minifier): Small fix (#5079)
This commit is contained in:
parent
279d4a39c1
commit
5ac5ae200c
@ -1227,11 +1227,6 @@ impl Minifier {
|
||||
|
||||
result
|
||||
});
|
||||
|
||||
// Remove all leading and trailing whitespaces for the `body` element
|
||||
if namespace == Namespace::HTML && tag_name == "body" {
|
||||
self.remove_leading_and_trailing_whitespaces(children);
|
||||
}
|
||||
}
|
||||
|
||||
fn get_attribute_value(&self, attributes: &Vec<Attribute>, name: &str) -> Option<JsWord> {
|
||||
@ -1714,6 +1709,14 @@ impl VisitMut for Minifier {
|
||||
|
||||
n.visit_mut_children_with(self);
|
||||
|
||||
// Remove all leading and trailing whitespaces for the `body` element
|
||||
if n.namespace == Namespace::HTML
|
||||
&& &*n.tag_name == "body"
|
||||
&& self.need_collapse_whitespace()
|
||||
{
|
||||
self.remove_leading_and_trailing_whitespaces(&mut n.children);
|
||||
}
|
||||
|
||||
if self.need_collapse_whitespace() {
|
||||
self.descendant_of_pre = old_descendant_of_pre;
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
<!doctype html><html lang=en><head>
|
||||
<title>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
<div> test </div>
|
||||
|
||||
<div>
|
||||
@ -271,4 +272,6 @@
|
||||
<div> text </div>
|
||||
|
||||
<span> text </span>
|
||||
<span> text </span>
|
||||
<span> text </span>
|
||||
|
||||
|
||||
|
@ -0,0 +1,3 @@
|
||||
{
|
||||
"collapseWhitespaces": "smart"
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<div> <a href="#"> <span> <b> foo </b> z <i> bar </i> </span> </a> </div>
|
@ -0,0 +1 @@
|
||||
<!doctype html><html lang=en><div><a href=#><span><b>foo</b>z <i>bar</i></span></a></div>
|
@ -0,0 +1,3 @@
|
||||
{
|
||||
"collapseWhitespaces": "smart"
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<span> <!-- test --> text <!-- test --></span>
|
@ -0,0 +1 @@
|
||||
<!doctype html><html lang=en><span>text</span>
|
@ -0,0 +1,3 @@
|
||||
{
|
||||
"collapseWhitespaces": "smart"
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<div><span> <!-- test --> text <!-- test --></span></div>
|
@ -0,0 +1 @@
|
||||
<!doctype html><html lang=en><div><span>text</span></div>
|
@ -0,0 +1,3 @@
|
||||
{
|
||||
"collapseWhitespaces": "smart"
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<span> <!-- test --> text <!-- test --></span> <span> <!-- test --> text <!-- test --></span>
|
@ -0,0 +1 @@
|
||||
<!doctype html><html lang=en><span>text</span> <span>text</span>
|
@ -0,0 +1,3 @@
|
||||
{
|
||||
"collapseWhitespaces": "smart"
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
<!doctype html>
|
||||
<svg> <linearGradient id=gradient /> </svg>
|
@ -0,0 +1 @@
|
||||
<!doctype html><svg><linearGradient id=gradient /></svg>
|
@ -0,0 +1,3 @@
|
||||
{
|
||||
"collapseWhitespaces": "smart"
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
<!doctype html>
|
||||
<span>a</span> <svg> <linearGradient id=gradient /> </svg>
|
@ -0,0 +1 @@
|
||||
<!doctype html><span>a</span> <svg><linearGradient id=gradient /></svg>
|
@ -0,0 +1,3 @@
|
||||
{
|
||||
"collapseWhitespaces": "smart"
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
<!doctype html>
|
||||
<svg> <linearGradient id=gradient /> </svg> <span>a</span>
|
@ -0,0 +1 @@
|
||||
<!doctype html><svg><linearGradient id=gradient /></svg><span>a</span>
|
@ -0,0 +1,3 @@
|
||||
{
|
||||
"collapseWhitespaces": "smart"
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
<!doctype html>
|
||||
<span>a</span> <svg> <linearGradient id=gradient /> </svg> <span>a</span>
|
@ -0,0 +1 @@
|
||||
<!doctype html><span>a</span> <svg><linearGradient id=gradient /> </svg><span>a</span>
|
@ -1 +1 @@
|
||||
<!doctype html><html lang=en><meta charset=UTF-8><meta name=viewport content="width=device-width,user-scalable=no,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0"><meta http-equiv=X-UA-Compatible content="ie=edge"><title>Document</title><div><span>test</span><noscript><a href=#>External Link</a></noscript></div><div><span>test</span><noscript> <a href=#>External Link</a></noscript></div>
|
||||
<!doctype html><html lang=en><meta charset=UTF-8><meta name=viewport content="width=device-width,user-scalable=no,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0"><meta http-equiv=X-UA-Compatible content="ie=edge"><title>Document</title><div><span>test</span><noscript><a href=#>External Link</a></noscript></div><div><span>test</span><noscript><a href=#>External Link</a></noscript></div>
|
Loading…
Reference in New Issue
Block a user