diff --git a/crates/swc_html_minifier/src/lib.rs b/crates/swc_html_minifier/src/lib.rs index a637f4da8bca..dbb855c50104 100644 --- a/crates/swc_html_minifier/src/lib.rs +++ b/crates/swc_html_minifier/src/lib.rs @@ -1,5 +1,7 @@ #![deny(clippy::all)] +use std::mem::take; + use once_cell::sync::Lazy; use serde_json::Value; use swc_atoms::{js_word, JsWord}; @@ -684,45 +686,51 @@ impl Minifier { } } - fn remove_whitespace_from_first_text_element(&self, node: &mut Child) { - match node { - Child::Text(text) => { - text.data = text.data.trim_start_matches(is_whitespace).into(); - } - Child::Element(Element { - namespace, - tag_name, - children, - .. - }) if get_white_space(*namespace, tag_name) == WhiteSpace::Normal => { - if let Some(last) = children.first_mut() { - self.remove_whitespace_from_first_text_element(last) + fn remove_leading_and_trailing_whitespaces(&self, children: &mut Vec) { + if let Some(last) = children.first_mut() { + match last { + Child::Text(text) => { + text.data = text.data.trim_start_matches(is_whitespace).into(); + + if text.data.is_empty() { + children.remove(0); + } + } + Child::Element(Element { + namespace, + tag_name, + children, + .. + }) if get_white_space(*namespace, tag_name) == WhiteSpace::Normal => { + self.remove_leading_and_trailing_whitespaces(children); } + _ => {} } - _ => {} } - } - fn remove_whitespace_from_last_text_element(&self, node: &mut Child) { - match node { - Child::Text(text) => { - text.data = text.data.trim_end_matches(is_whitespace).into(); - } - Child::Element(Element { - namespace, - tag_name, - children, - .. - }) if get_white_space(*namespace, tag_name) == WhiteSpace::Normal => { - if let Some(last) = children.last_mut() { - self.remove_whitespace_from_last_text_element(last) + if let Some(last) = children.last_mut() { + match last { + Child::Text(text) => { + text.data = text.data.trim_end_matches(is_whitespace).into(); + + if text.data.is_empty() { + children.pop(); + } + } + Child::Element(Element { + namespace, + tag_name, + children, + .. + }) if get_white_space(*namespace, tag_name) == WhiteSpace::Normal => { + self.remove_leading_and_trailing_whitespaces(children); } + _ => {} } - _ => {} } } - fn get_deep_last_text_element<'a>(&self, node: &'a mut Child) -> Option<&'a mut Text> { + fn get_deep_last_text_element<'a>(&self, node: &'a Child) -> Option<&'a Text> { match node { Child::Text(text) => Some(text), Child::Element(Element { @@ -731,7 +739,7 @@ impl Minifier { children, .. }) if get_white_space(*namespace, tag_name) == WhiteSpace::Normal => { - if let Some(last) = children.last_mut() { + if let Some(last) = children.last() { self.get_deep_last_text_element(last) } else { None @@ -741,6 +749,47 @@ impl Minifier { } } + fn get_prev_non_comment_node<'a>( + &self, + children: &'a Vec, + index: usize, + ) -> Option<&'a Child> { + let prev = children.get(index); + + match prev { + Some(Child::Comment(_)) if index >= 1 => { + self.get_prev_non_comment_node(children, index - 1) + } + Some(_) => prev, + _ => None, + } + } + + fn get_next_non_comment_node<'a>( + &self, + children: &'a Vec, + index: usize, + ) -> Option<&'a Child> { + let next = children.get(index); + + match next { + Some(Child::Comment(_)) => self.get_next_non_comment_node(children, index + 1), + Some(_) => next, + _ => None, + } + } + + fn get_next_text_node<'a>(&self, children: &'a Vec, index: usize) -> Option<&'a Child> { + let next = children.get(index); + + match next { + Some(Child::Text(_)) => next, + Some(Child::Element(_)) => None, + Some(_) => self.get_next_text_node(children, index + 1), + _ => None, + } + } + fn get_whitespace_minification_for_tag( &self, mode: &CollapseWhitespaces, @@ -818,199 +867,232 @@ impl Minifier { } fn minify_children(&mut self, children: &mut Vec) { - let namespace = self.current_element.as_ref().unwrap().namespace; - let tag_name = &self.current_element.as_ref().unwrap().tag_name; + let (namespace, tag_name) = match &self.current_element { + Some(element) => (element.namespace, &element.tag_name), + _ => return, + }; + let mode = self .collapse_whitespaces .as_ref() .map(|mode| self.get_whitespace_minification_for_tag(mode, namespace, tag_name)); - let mut index = 0; - - let mut cloned_children = None; - - if mode.is_some() { - cloned_children = Some(children.clone()); - } - - let mut prev = None; - let mut next = None; - - if namespace == Namespace::HTML && &**tag_name == "body" { - if let Some(first) = children.first_mut() { - self.remove_whitespace_from_first_text_element(first); - } - - if let Some(last) = children.last_mut() { - self.remove_whitespace_from_last_text_element(last) - } - } - - children.retain_mut(|child| { - index += 1; - - if mode.is_some() { - if let Some(cloned_children) = &cloned_children { - next = cloned_children.get(index); - } - } - - let result = match child { - Child::Comment(comment) if self.remove_comments => { - self.is_preserved_comment(&comment.data) - } - // Always remove whitespaces from html and head elements (except nested elements), - // it should be safe - Child::Text(text) - if namespace == Namespace::HTML - && matches!(&**tag_name, "html" | "head") - && text.data.chars().all(is_whitespace) => - { - false - } - Child::Text(text) - if !self.descendant_of_pre - && get_white_space(namespace, &**tag_name) == WhiteSpace::Normal => - { - let mut is_smart_left_trim = false; - let mut is_smart_right_trim = false; - - if self.collapse_whitespaces == Some(CollapseWhitespaces::Smart) { - let prev_display = if let Some(Child::Element(Element { - namespace, - tag_name, - .. - })) = &prev - { - Some(self.get_display(*namespace, &**tag_name)) - } else { - None - }; - - is_smart_left_trim = match prev_display { - // Block-level containers: - // - // `Display::Block` - `display: block flow` - // `Display::ListItem` - `display: block flow list-item` - // `Display::Table` - `display: block table` - // + internal table display (only whitespace characters allowed there) - Some( - Display::Block - | Display::ListItem - | Display::Table - | Display::TableColumnGroup - | Display::TableCaption - | Display::TableColumn - | Display::TableRow - | Display::TableCell - | Display::TableHeaderGroup - | Display::TableRowGroup - | Display::TableFooterGroup, - ) => true, - // Inline box - Some(Display::Inline) => { - let deep = self.get_deep_last_text_element(prev.as_mut().unwrap()); - - if let Some(deep) = deep { - deep.data.ends_with(is_whitespace) - } else { - false - } - } - // Inline level containers and etc - Some(_) => false, - None => { - let parent_display = self.get_display(namespace, &**tag_name); - - match parent_display { - Display::Inline => { - if let Some(Child::Text(Text { data, .. })) = - &self.latest_element - { - data.ends_with(is_whitespace) + let child_will_be_retained = + |child: &mut Child, prev: Option<&Child>, next: Option<&Child>| { + match child { + Child::Comment(comment) if self.remove_comments => { + self.is_preserved_comment(&comment.data) + } + // Always remove whitespaces from html and head elements (except nested + // elements), it should be safe + Child::Text(text) + if namespace == Namespace::HTML + && matches!(&**tag_name, "html" | "head") + && text.data.chars().all(is_whitespace) => + { + false + } + Child::Text(text) if text.data.is_empty() => false, + Child::Text(text) + if !self.descendant_of_pre + && get_white_space(namespace, tag_name) == WhiteSpace::Normal + && mode.is_some() => + { + let mode = mode.unwrap(); + let mut is_smart_left_trim = false; + let mut is_smart_right_trim = false; + + if self.collapse_whitespaces == Some(CollapseWhitespaces::Smart) { + let prev_display = if let Some(Child::Element(Element { + namespace, + tag_name, + .. + })) = &prev + { + Some(self.get_display(*namespace, tag_name)) + } else { + None + }; + + is_smart_left_trim = match prev_display { + // Block-level containers: + // + // `Display::Block` - `display: block flow` + // `Display::ListItem` - `display: block flow list-item` + // `Display::Table` - `display: block table` + // + internal table display (only whitespace characters allowed + // there) + Some( + Display::Block + | Display::ListItem + | Display::Table + | Display::TableColumnGroup + | Display::TableCaption + | Display::TableColumn + | Display::TableRow + | Display::TableCell + | Display::TableHeaderGroup + | Display::TableRowGroup + | Display::TableFooterGroup, + ) => true, + // Inline box + Some(Display::Inline) => { + if let Some(prev) = &prev { + let deep = self.get_deep_last_text_element(prev); + + if let Some(deep) = deep { + deep.data.ends_with(is_whitespace) } else { false } + } else { + false } - _ => true, } - } - }; + // Inline level containers and etc + Some(_) => false, + None => { + let parent_display = self.get_display(namespace, tag_name); + + match parent_display { + Display::Inline => { + if let Some(Child::Text(Text { data, .. })) = + &self.latest_element + { + data.ends_with(is_whitespace) + } else { + false + } + } + _ => true, + } + } + }; - let next_display = if let Some(Child::Element(Element { - namespace, - tag_name, - .. - })) = &next - { - Some(self.get_display(*namespace, &**tag_name)) + let next_display = if let Some(Child::Element(Element { + namespace, + tag_name, + .. + })) = &next + { + Some(self.get_display(*namespace, tag_name)) + } else { + None + }; + + is_smart_right_trim = match next_display { + // Block-level containers: + // + // `Display::Block` - `display: block flow` + // `Display::ListItem` - `display: block flow list-item` + // `Display::Table` - `display: block table` + // + internal table display (only whitespace characters allowed + // there) + Some( + Display::Block + | Display::ListItem + | Display::Table + | Display::TableColumnGroup + | Display::TableCaption + | Display::TableColumn + | Display::TableRow + | Display::TableCell + | Display::TableHeaderGroup + | Display::TableRowGroup + | Display::TableFooterGroup, + ) => true, + Some(_) => false, + None => { + let parent_display = self.get_display(namespace, tag_name); + + !matches!(parent_display, Display::Inline) + } + }; + } + + let mut value = if (mode.trim) || is_smart_left_trim { + text.data.trim_start_matches(is_whitespace) } else { - None + &*text.data }; - is_smart_right_trim = match next_display { - // Block-level containers: - // - // `Display::Block` - `display: block flow` - // `Display::ListItem` - `display: block flow list-item` - // `Display::Table` - `display: block table` - // + internal table display (only whitespace characters allowed there) - Some( - Display::Block - | Display::ListItem - | Display::Table - | Display::TableColumnGroup - | Display::TableCaption - | Display::TableColumn - | Display::TableRow - | Display::TableCell - | Display::TableHeaderGroup - | Display::TableRowGroup - | Display::TableFooterGroup, - ) => true, - Some(_) => false, - None => { - let parent_display = self.get_display(namespace, &**tag_name); - - !matches!(parent_display, Display::Inline) - } + value = if (mode.trim) || is_smart_right_trim { + value.trim_end_matches(is_whitespace) + } else { + value }; + + if value.is_empty() { + false + } else if mode.collapse { + text.data = self.collapse_whitespace(value).into(); + + true + } else { + text.data = value.into(); + + true + } } + _ => true, + } + }; - let mut value = if (mode.is_some() && mode.unwrap().trim) || is_smart_left_trim - { - text.data.trim_start_matches(is_whitespace) - } else { - &*text.data - }; + let cloned_children = children.clone(); - value = if (mode.is_some() && mode.unwrap().trim) || is_smart_right_trim { - value.trim_end_matches(is_whitespace) - } else { - value - }; + let mut index = 0; + let mut pending_text = vec![]; - if value.is_empty() { - false - } else if mode.is_some() && mode.unwrap().collapse { - text.data = self.collapse_whitespace(value).into(); + children.retain_mut(|child| { + match child { + Child::Text(text) + if self + .get_next_text_node(&cloned_children, index + 1) + .is_some() + && !child_will_be_retained( + &mut cloned_children.get(index + 1).cloned().unwrap(), + self.get_prev_non_comment_node(&cloned_children, index), + self.get_next_non_comment_node(&cloned_children, index + 2), + ) => + { + pending_text.push(text.data.clone()); - true - } else { - text.data = value.into(); + index += 1; + + return false; + } + Child::Text(text) if !pending_text.is_empty() => { + let mut new_value = String::new(); - true + for text in take(&mut pending_text) { + new_value.push_str(&text); } + + new_value.push_str(&text.data); + + text.data = new_value.into(); } - _ => true, + _ => {} + } + + let prev = if index >= 1 { + self.get_prev_non_comment_node(&cloned_children, index - 1) + } else { + None }; + let next = self.get_next_non_comment_node(&cloned_children, index + 1); - if result && mode.is_some() { - prev = Some(child.clone()); - } + let result = child_will_be_retained(child, prev, next); + + index += 1; 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, name: &str) -> Option { diff --git a/crates/swc_html_minifier/tests/fixture/comment/basic/input.html b/crates/swc_html_minifier/tests/fixture/comment/basic/input.html index 64711eacec9e..3ee11c712777 100644 --- a/crates/swc_html_minifier/tests/fixture/comment/basic/input.html +++ b/crates/swc_html_minifier/tests/fixture/comment/basic/input.html @@ -79,5 +79,19 @@ According to the conditional comment this is not IE 5-9

+ +
a b c
+
+ + a + + + + b + + + + c +
\ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/comment/basic/output.min.html b/crates/swc_html_minifier/tests/fixture/comment/basic/output.min.html index 98e002f6ead0..2adbf96aa05c 100644 --- a/crates/swc_html_minifier/tests/fixture/comment/basic/output.min.html +++ b/crates/swc_html_minifier/tests/fixture/comment/basic/output.min.html @@ -52,4 +52,18 @@ According to the conditional comment this is not IE 5-9
- \ No newline at end of file +

+ +
a b c
+
+ + a + + + + b + + + + c +
\ 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 index 499acff5dee5..a9029b6f9af8 100644 --- a/crates/swc_html_minifier/tests/fixture/comment/html/output.min.html +++ b/crates/swc_html_minifier/tests/fixture/comment/html/output.min.html @@ -1,4 +1 @@ -Document - -
test
- +Document
test
\ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/comment/spaces/config.json b/crates/swc_html_minifier/tests/fixture/comment/spaces/config.json new file mode 100644 index 000000000000..ebe99c53ed18 --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/comment/spaces/config.json @@ -0,0 +1,3 @@ +{ + "collapseWhitespaces": "smart" +} \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/comment/spaces/input.html b/crates/swc_html_minifier/tests/fixture/comment/spaces/input.html new file mode 100644 index 000000000000..51af9442754d --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/comment/spaces/input.html @@ -0,0 +1,8 @@ + + + + Document + + +
foo
baz
bar
+ \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/comment/spaces/output.min.html b/crates/swc_html_minifier/tests/fixture/comment/spaces/output.min.html new file mode 100644 index 000000000000..068fb70078f3 --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/comment/spaces/output.min.html @@ -0,0 +1 @@ +Document
foo
baz
bar
\ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/angular/config.json b/crates/swc_html_minifier/tests/fixture/text/angular/config.json new file mode 100644 index 000000000000..ebe99c53ed18 --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/text/angular/config.json @@ -0,0 +1,3 @@ +{ + "collapseWhitespaces": "smart" +} \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/angular/input.html b/crates/swc_html_minifier/tests/fixture/text/angular/input.html new file mode 100644 index 000000000000..c7c386375539 --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/text/angular/input.html @@ -0,0 +1,22 @@ + + + + + Document + + + +
+
+ + +
+ +
+ + \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/angular/output.min.html b/crates/swc_html_minifier/tests/fixture/text/angular/output.min.html new file mode 100644 index 000000000000..5085db6664fc --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/text/angular/output.min.html @@ -0,0 +1 @@ +Document
\ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/collapse-whitespace-all/input.html b/crates/swc_html_minifier/tests/fixture/text/collapse-whitespace-all/input.html index 641d6c7734cf..b579ce15b599 100644 --- a/crates/swc_html_minifier/tests/fixture/text/collapse-whitespace-all/input.html +++ b/crates/swc_html_minifier/tests/fixture/text/collapse-whitespace-all/input.html @@ -255,5 +255,36 @@
test
foo baz foo baz
test
+
+ + + +
+ +
+    foo
+    
+    baz
+
+ +
a c
+ +
Empty
+ + + + + +
a b
+ +
a b c d
+ +
text
+ + text + text + \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/collapse-whitespace-all/output.min.html b/crates/swc_html_minifier/tests/fixture/text/collapse-whitespace-all/output.min.html index 2a4bd2ddeeab..9b8c1a809a1a 100644 --- a/crates/swc_html_minifier/tests/fixture/text/collapse-whitespace-all/output.min.html +++ b/crates/swc_html_minifier/tests/fixture/text/collapse-whitespace-all/output.min.html @@ -25,4 +25,8 @@ test -
foobazbar foobazbar foobazbar
foobazbar foobazbar foobazbar
foo
texttesttest
testtesttesttest

blah

test
test
testtest
ac
a
b
ab
test
test
test
test
test
test
testtest
test
test
test

test

test

test

test

test

test

test

blah

test
foofoo
foofoo
foofoo
foofoo
foofoo
foofoo
foofoo
foo

foobar

foobar

foobar

foobar

foobar

foo
bar

fooabar

 fo o 
 fo o 

ab

foo bar
foo bar
foo bar

foo

foo

foofoo
foofoofoo
foofoofoo
foofoofoo
abc
abc
abc
foobaz
foobaz
foobaz
foobaz
testfoobazfoobaztest
test
foobazfoobaz
test
\ No newline at end of file +
foobazbar foobazbar foobazbar
foobazbar foobazbar foobazbar
foo
texttesttest
testtesttesttest

blah

test
test
testtest
ac
a
b
ab
test
test
test
test
test
test
testtest
test
test
test

test

test

test

test

test

test

test

blah

test
foofoo
foofoo
foofoo
foofoo
foofoo
foofoo
foofoo
foo

foobar

foobar

foobar

foobar

foobar

foo
bar

fooabar

 fo o 
 fo o 

a b

foo bar
foo bar
foo bar

foo

foo

foofoo
foofoofoo
foofoofoo
foofoofoo
abc
abc
abc
foobaz
foobaz
foobaz
foobaz
testfoobazfoobaztest
test
foobazfoobaz
test
+    foo
+    
+    baz
+
ac
Empty
a b
a b c d
text
texttext \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/collapse-whitespace-conservative/input.html b/crates/swc_html_minifier/tests/fixture/text/collapse-whitespace-conservative/input.html index 641d6c7734cf..bdd62a045f72 100644 --- a/crates/swc_html_minifier/tests/fixture/text/collapse-whitespace-conservative/input.html +++ b/crates/swc_html_minifier/tests/fixture/text/collapse-whitespace-conservative/input.html @@ -255,5 +255,40 @@
test
foo baz foo baz
test
+
foo + +
+ +
+ + + +
+ +
+    foo
+    
+    baz
+
+ +
a c
+ +
Empty
+ + + + + +
a b
+ +
a b c d
+ +
text
+ + text + text + \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/collapse-whitespace-conservative/output.min.html b/crates/swc_html_minifier/tests/fixture/text/collapse-whitespace-conservative/output.min.html index 13dd59f71dd7..322ece40c814 100644 --- a/crates/swc_html_minifier/tests/fixture/text/collapse-whitespace-conservative/output.min.html +++ b/crates/swc_html_minifier/tests/fixture/text/collapse-whitespace-conservative/output.min.html @@ -25,4 +25,8 @@ test -
foo baz bar foo baz bar foo baz bar
foo baz bar foo baz bar foo baz bar
foo
text test test
testtest test test

blah

test
test
test test
a c
a
b
a b
test
test
test
test
test
test
test test
test
test
test

test

test

test

test

test

test

test

blah

test
foo foo
foofoo
foo foo
foo foo
foofoo
foo foo
foo foo
foo

foo bar

foobar

foo bar

foo bar

foo bar

foo
bar

foo a bar

 fo o 
 fo o 

a b

foo bar
foo bar
foo bar

foo

foo

foo foo
foo foo foo
foo foo foo
foo foofoo
a b c
a b c
a b c
foo baz
foo baz
foo baz
foobaz
test foo baz foo baztest
test
foo baz foo baz
test
\ No newline at end of file +
foo baz bar foo baz bar foo baz bar
foo baz bar foo baz bar foo baz bar
foo
text test test
testtest test test

blah

test
test
test test
a c
a
b
a b
test
test
test
test
test
test
test test
test
test
test

test

test

test

test

test

test

test

blah

test
foo foo
foofoo
foo foo
foo foo
foofoo
foo foo
foo foo
foo

foo bar

foobar

foo bar

foo bar

foo bar

foo
bar

foo a bar

 fo o 
 fo o 

a b

foo bar
foo bar
foo bar

foo

foo

foo foo
foo foo foo
foo foo foo
foo foofoo
a b c
a b c
a b c
foo baz
foo baz
foo baz
foobaz
test foo baz foo baztest
test
foo baz foo baz
test
foo
+    foo
+    
+    baz
+
a c
Empty
a b
a b c d
text
text text \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/collapse-whitespace-smart/input.html b/crates/swc_html_minifier/tests/fixture/text/collapse-whitespace-smart/input.html index 641d6c7734cf..b579ce15b599 100644 --- a/crates/swc_html_minifier/tests/fixture/text/collapse-whitespace-smart/input.html +++ b/crates/swc_html_minifier/tests/fixture/text/collapse-whitespace-smart/input.html @@ -255,5 +255,36 @@
test
foo baz foo baz
test
+
+ + + +
+ +
+    foo
+    
+    baz
+
+ +
a c
+ +
Empty
+ + + + + +
a b
+ +
a b c d
+ +
text
+ + text + text + \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/collapse-whitespace-smart/output.min.html b/crates/swc_html_minifier/tests/fixture/text/collapse-whitespace-smart/output.min.html index 4805aea22eea..7f478be5f7ef 100644 --- a/crates/swc_html_minifier/tests/fixture/text/collapse-whitespace-smart/output.min.html +++ b/crates/swc_html_minifier/tests/fixture/text/collapse-whitespace-smart/output.min.html @@ -25,4 +25,8 @@ test -
foo baz bar foo baz bar foo baz bar
foo baz bar foo baz bar foo baz bar
foo
text test test
testtest test test

blah

test
test
test test
a c
a
b
a b
test
test
test
test
test
test
test test
test
test
test

test

test

test

test

test

test

test

blah

test
foo foo
foofoo
foo foo
foo foo
foofoo
foo foo
foo foo
foo

foo bar

foobar

foo bar

foo bar

foo bar

foo
bar

foo a bar

 fo o 
 fo o 

ab

foo bar
foo bar
foo bar

foo

foo

foo foo
foo foo foo
foo foo foo
foo foofoo
a b c
a b c
a b c
foo baz
foo baz
foo baz
foobaz
test foo baz foo baztest
test
foo baz foo baz
test
\ No newline at end of file +
foo baz bar foo baz bar foo baz bar
foo baz bar foo baz bar foo baz bar
foo
text test test
testtest test test

blah

test
test
test test
a c
a
b
a b
test
test
test
test
test
test
test test
test
test
test

test

test

test

test

test

test

test

blah

test
foo foo
foofoo
foo foo
foo foo
foofoo
foo foo
foo foo
foo

foo bar

foobar

foo bar

foo bar

foo bar

foo
bar

foo a bar

 fo o 
 fo o 

a b

foo bar
foo bar
foo bar

foo

foo

foo foo
foo foo foo
foo foo foo
foo foofoo
a b c
a b c
a b c
foo baz
foo baz
foo baz
foobaz
test foo baz foo baztest
test
foo baz foo baz
test
+    foo
+    
+    baz
+
a c
Empty
a b
a b c d
text
text text \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/empty-1/config.json b/crates/swc_html_minifier/tests/fixture/text/empty-1/config.json new file mode 100644 index 000000000000..ebe99c53ed18 --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/text/empty-1/config.json @@ -0,0 +1,3 @@ +{ + "collapseWhitespaces": "smart" +} \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/empty-1/input.html b/crates/swc_html_minifier/tests/fixture/text/empty-1/input.html new file mode 100644 index 000000000000..e940d09d02dc --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/text/empty-1/input.html @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/empty-1/output.min.html b/crates/swc_html_minifier/tests/fixture/text/empty-1/output.min.html new file mode 100644 index 000000000000..937d25b42e2e --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/text/empty-1/output.min.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/empty-2/config.json b/crates/swc_html_minifier/tests/fixture/text/empty-2/config.json new file mode 100644 index 000000000000..ebe99c53ed18 --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/text/empty-2/config.json @@ -0,0 +1,3 @@ +{ + "collapseWhitespaces": "smart" +} \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/empty-2/input.html b/crates/swc_html_minifier/tests/fixture/text/empty-2/input.html new file mode 100644 index 000000000000..8baff692dac3 --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/text/empty-2/input.html @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/empty-2/output.min.html b/crates/swc_html_minifier/tests/fixture/text/empty-2/output.min.html new file mode 100644 index 000000000000..937d25b42e2e --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/text/empty-2/output.min.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/empty-3/config.json b/crates/swc_html_minifier/tests/fixture/text/empty-3/config.json new file mode 100644 index 000000000000..ebe99c53ed18 --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/text/empty-3/config.json @@ -0,0 +1,3 @@ +{ + "collapseWhitespaces": "smart" +} \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/empty-3/input.html b/crates/swc_html_minifier/tests/fixture/text/empty-3/input.html new file mode 100644 index 000000000000..bc3dcdcf0abd --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/text/empty-3/input.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/empty-3/output.min.html b/crates/swc_html_minifier/tests/fixture/text/empty-3/output.min.html new file mode 100644 index 000000000000..937d25b42e2e --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/text/empty-3/output.min.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/empty-4/config.json b/crates/swc_html_minifier/tests/fixture/text/empty-4/config.json new file mode 100644 index 000000000000..ebe99c53ed18 --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/text/empty-4/config.json @@ -0,0 +1,3 @@ +{ + "collapseWhitespaces": "smart" +} \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/empty-4/input.html b/crates/swc_html_minifier/tests/fixture/text/empty-4/input.html new file mode 100644 index 000000000000..b2a1a3640aa6 --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/text/empty-4/input.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/empty-4/output.min.html b/crates/swc_html_minifier/tests/fixture/text/empty-4/output.min.html new file mode 100644 index 000000000000..937d25b42e2e --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/text/empty-4/output.min.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/empty-5/config.json b/crates/swc_html_minifier/tests/fixture/text/empty-5/config.json new file mode 100644 index 000000000000..ebe99c53ed18 --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/text/empty-5/config.json @@ -0,0 +1,3 @@ +{ + "collapseWhitespaces": "smart" +} \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/empty-5/input.html b/crates/swc_html_minifier/tests/fixture/text/empty-5/input.html new file mode 100644 index 000000000000..c03345edbb02 --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/text/empty-5/input.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/empty-5/output.min.html b/crates/swc_html_minifier/tests/fixture/text/empty-5/output.min.html new file mode 100644 index 000000000000..937d25b42e2e --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/text/empty-5/output.min.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/empty/config.json b/crates/swc_html_minifier/tests/fixture/text/empty/config.json new file mode 100644 index 000000000000..ebe99c53ed18 --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/text/empty/config.json @@ -0,0 +1,3 @@ +{ + "collapseWhitespaces": "smart" +} \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/empty/input.html b/crates/swc_html_minifier/tests/fixture/text/empty/input.html new file mode 100644 index 000000000000..eadc71db1ddb --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/text/empty/input.html @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/empty/output.min.html b/crates/swc_html_minifier/tests/fixture/text/empty/output.min.html new file mode 100644 index 000000000000..937d25b42e2e --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/text/empty/output.min.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/inline-17/config.json b/crates/swc_html_minifier/tests/fixture/text/inline-17/config.json new file mode 100644 index 000000000000..ebe99c53ed18 --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/text/inline-17/config.json @@ -0,0 +1,3 @@ +{ + "collapseWhitespaces": "smart" +} \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/inline-17/input.html b/crates/swc_html_minifier/tests/fixture/text/inline-17/input.html new file mode 100644 index 000000000000..8d6ec53c9fba --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/text/inline-17/input.html @@ -0,0 +1,11 @@ + + + + Document + + + + + \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/inline-17/output.min.html b/crates/swc_html_minifier/tests/fixture/text/inline-17/output.min.html new file mode 100644 index 000000000000..1a58c16aabb6 --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/text/inline-17/output.min.html @@ -0,0 +1 @@ +Document \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/inline-18/config.json b/crates/swc_html_minifier/tests/fixture/text/inline-18/config.json new file mode 100644 index 000000000000..ebe99c53ed18 --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/text/inline-18/config.json @@ -0,0 +1,3 @@ +{ + "collapseWhitespaces": "smart" +} \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/inline-18/input.html b/crates/swc_html_minifier/tests/fixture/text/inline-18/input.html new file mode 100644 index 000000000000..700dda9c0899 --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/text/inline-18/input.html @@ -0,0 +1,11 @@ + + + + Document + +a + +a + \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/inline-18/output.min.html b/crates/swc_html_minifier/tests/fixture/text/inline-18/output.min.html new file mode 100644 index 000000000000..4d62fb4dc988 --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/text/inline-18/output.min.html @@ -0,0 +1 @@ +Documenta a \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/inline-block-17/config.json b/crates/swc_html_minifier/tests/fixture/text/inline-block-17/config.json new file mode 100644 index 000000000000..ebe99c53ed18 --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/text/inline-block-17/config.json @@ -0,0 +1,3 @@ +{ + "collapseWhitespaces": "smart" +} \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/inline-block-17/input.html b/crates/swc_html_minifier/tests/fixture/text/inline-block-17/input.html new file mode 100644 index 000000000000..08743512c43c --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/text/inline-block-17/input.html @@ -0,0 +1,7 @@ + + + + Document + + + \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/inline-block-17/output.min.html b/crates/swc_html_minifier/tests/fixture/text/inline-block-17/output.min.html new file mode 100644 index 000000000000..aecd1d11b878 --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/text/inline-block-17/output.min.html @@ -0,0 +1 @@ +Document \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/inline-block-18/config.json b/crates/swc_html_minifier/tests/fixture/text/inline-block-18/config.json new file mode 100644 index 000000000000..ebe99c53ed18 --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/text/inline-block-18/config.json @@ -0,0 +1,3 @@ +{ + "collapseWhitespaces": "smart" +} \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/inline-block-18/input.html b/crates/swc_html_minifier/tests/fixture/text/inline-block-18/input.html new file mode 100644 index 000000000000..79463e1b0fd6 --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/text/inline-block-18/input.html @@ -0,0 +1,7 @@ + + + + Document + + + \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/inline-block-18/output.min.html b/crates/swc_html_minifier/tests/fixture/text/inline-block-18/output.min.html new file mode 100644 index 000000000000..66866301769e --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/text/inline-block-18/output.min.html @@ -0,0 +1 @@ +Document \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/math/config.json b/crates/swc_html_minifier/tests/fixture/text/math/config.json new file mode 100644 index 000000000000..ebe99c53ed18 --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/text/math/config.json @@ -0,0 +1,3 @@ +{ + "collapseWhitespaces": "smart" +} \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/math/input.html b/crates/swc_html_minifier/tests/fixture/text/math/input.html new file mode 100644 index 000000000000..022b68a01fc5 --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/text/math/input.html @@ -0,0 +1,7 @@ + + + + Document + +

where R is the Rici tensor.

+ \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/math/output.min.html b/crates/swc_html_minifier/tests/fixture/text/math/output.min.html new file mode 100644 index 000000000000..6b6f8383b336 --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/text/math/output.min.html @@ -0,0 +1 @@ +Document

where R is the Rici tensor. \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/noscript-1/config.json b/crates/swc_html_minifier/tests/fixture/text/noscript-1/config.json new file mode 100644 index 000000000000..ebe99c53ed18 --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/text/noscript-1/config.json @@ -0,0 +1,3 @@ +{ + "collapseWhitespaces": "smart" +} \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/noscript-1/input.html b/crates/swc_html_minifier/tests/fixture/text/noscript-1/input.html new file mode 100644 index 000000000000..3bf6ebbf6feb --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/text/noscript-1/input.html @@ -0,0 +1,18 @@ + + + + + + + Document + + +

+ test +
+
+ test +
+ + \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/noscript-1/output.min.html b/crates/swc_html_minifier/tests/fixture/text/noscript-1/output.min.html new file mode 100644 index 000000000000..9c443f4094f6 --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/text/noscript-1/output.min.html @@ -0,0 +1 @@ +Document \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/select-1/config.json b/crates/swc_html_minifier/tests/fixture/text/select-1/config.json new file mode 100644 index 000000000000..3a42e9749209 --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/text/select-1/config.json @@ -0,0 +1,3 @@ +{ + "collapseWhitespaces": "conservative" +} \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/select-1/input.html b/crates/swc_html_minifier/tests/fixture/text/select-1/input.html new file mode 100644 index 000000000000..28590c614235 --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/text/select-1/input.html @@ -0,0 +1,10 @@ + + + + Document + +test + \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/select-1/output.min.html b/crates/swc_html_minifier/tests/fixture/text/select-1/output.min.html new file mode 100644 index 000000000000..1c383a197ad4 --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/text/select-1/output.min.html @@ -0,0 +1 @@ +Documenttest \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/select/config.json b/crates/swc_html_minifier/tests/fixture/text/select/config.json new file mode 100644 index 000000000000..ebe99c53ed18 --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/text/select/config.json @@ -0,0 +1,3 @@ +{ + "collapseWhitespaces": "smart" +} \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/select/input.html b/crates/swc_html_minifier/tests/fixture/text/select/input.html new file mode 100644 index 000000000000..c08ec85f1515 --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/text/select/input.html @@ -0,0 +1,10 @@ + + + + Document + + + \ No newline at end of file diff --git a/crates/swc_html_minifier/tests/fixture/text/select/output.min.html b/crates/swc_html_minifier/tests/fixture/text/select/output.min.html new file mode 100644 index 000000000000..747d8e62016c --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/text/select/output.min.html @@ -0,0 +1 @@ +Document \ No newline at end of file