From 816a750741872705994c0d93bbfa095cdb90eda5 Mon Sep 17 00:00:00 2001 From: "alexander.akait" Date: Mon, 27 Jun 2022 20:36:17 +0300 Subject: [PATCH 01/17] test(html/minifier): more --- .../tests/fixture/text/angular/config.json | 3 +++ .../tests/fixture/text/angular/input.html | 22 +++++++++++++++++++ .../fixture/text/angular/output.min.html | 1 + 3 files changed, 26 insertions(+) create mode 100644 crates/swc_html_minifier/tests/fixture/text/angular/config.json create mode 100644 crates/swc_html_minifier/tests/fixture/text/angular/input.html create mode 100644 crates/swc_html_minifier/tests/fixture/text/angular/output.min.html 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 From 0845800b3a92efa00fa08d123e31da6c292d26b5 Mon Sep 17 00:00:00 2001 From: "alexander.akait" Date: Mon, 27 Jun 2022 20:50:45 +0300 Subject: [PATCH 02/17] test(html/minifier): more --- .../tests/fixture/text/noscript-1/config.json | 3 +++ .../tests/fixture/text/noscript-1/input.html | 18 ++++++++++++++++++ .../fixture/text/noscript-1/output.min.html | 1 + 3 files changed, 22 insertions(+) create mode 100644 crates/swc_html_minifier/tests/fixture/text/noscript-1/config.json create mode 100644 crates/swc_html_minifier/tests/fixture/text/noscript-1/input.html create mode 100644 crates/swc_html_minifier/tests/fixture/text/noscript-1/output.min.html 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
test
test
\ No newline at end of file From 69c89e097b88d6d7637a1a6506afa36c32f1b7dd Mon Sep 17 00:00:00 2001 From: "alexander.akait" Date: Mon, 27 Jun 2022 21:12:06 +0300 Subject: [PATCH 03/17] test: more --- .../fixture/text/collapse-whitespace-all/input.html | 6 ++++++ .../text/collapse-whitespace-all/output.min.html | 2 +- .../text/collapse-whitespace-conservative/input.html | 10 ++++++++++ .../collapse-whitespace-conservative/output.min.html | 2 +- .../fixture/text/collapse-whitespace-smart/input.html | 6 ++++++ .../text/collapse-whitespace-smart/output.min.html | 2 +- .../tests/fixture/text/inline-17/config.json | 3 +++ .../tests/fixture/text/inline-17/input.html | 11 +++++++++++ .../tests/fixture/text/inline-17/output.min.html | 1 + .../tests/fixture/text/inline-block-17/config.json | 3 +++ .../tests/fixture/text/inline-block-17/input.html | 7 +++++++ .../fixture/text/inline-block-17/output.min.html | 1 + .../tests/fixture/text/inline-block-18/config.json | 3 +++ .../tests/fixture/text/inline-block-18/input.html | 7 +++++++ .../fixture/text/inline-block-18/output.min.html | 1 + .../tests/fixture/text/math/config.json | 3 +++ .../tests/fixture/text/math/input.html | 7 +++++++ .../tests/fixture/text/math/output.min.html | 1 + 18 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 crates/swc_html_minifier/tests/fixture/text/inline-17/config.json create mode 100644 crates/swc_html_minifier/tests/fixture/text/inline-17/input.html create mode 100644 crates/swc_html_minifier/tests/fixture/text/inline-17/output.min.html create mode 100644 crates/swc_html_minifier/tests/fixture/text/inline-block-17/config.json create mode 100644 crates/swc_html_minifier/tests/fixture/text/inline-block-17/input.html create mode 100644 crates/swc_html_minifier/tests/fixture/text/inline-block-17/output.min.html create mode 100644 crates/swc_html_minifier/tests/fixture/text/inline-block-18/config.json create mode 100644 crates/swc_html_minifier/tests/fixture/text/inline-block-18/input.html create mode 100644 crates/swc_html_minifier/tests/fixture/text/inline-block-18/output.min.html create mode 100644 crates/swc_html_minifier/tests/fixture/text/math/config.json create mode 100644 crates/swc_html_minifier/tests/fixture/text/math/input.html create mode 100644 crates/swc_html_minifier/tests/fixture/text/math/output.min.html 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..ba565cdc0a40 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,11 @@
test
foo baz foo baz
test
+
+ + + +
+ \ 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..e6fe89d6f0ba 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,4 @@ 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
testtest
testtest

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
testtest
testtest

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 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..e93ec40df02d 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,15 @@
test
foo baz foo baz
test
+
foo + +
+ +
+ + + +
+ \ 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..8f406972ebb6 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,4 @@ 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
test test
testtest

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
test test
testtest

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
\ 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..ba565cdc0a40 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,11 @@
test
foo baz foo baz
test
+
+ + + +
+ \ 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..5c3c244f8ec7 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,4 @@ 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
test test
testtest

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
test test
testtest

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 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..4100e4b9ebd1 --- /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-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 From 98d59a2d6f50b9f095daf5dc75150a9d0699ac9e Mon Sep 17 00:00:00 2001 From: "alexander.akait" Date: Mon, 27 Jun 2022 21:22:34 +0300 Subject: [PATCH 04/17] test: more --- .../fixture/text/collapse-whitespace-all/input.html | 6 ++++++ .../text/collapse-whitespace-all/output.min.html | 6 +++++- .../text/collapse-whitespace-conservative/input.html | 6 ++++++ .../collapse-whitespace-conservative/output.min.html | 6 +++++- .../fixture/text/collapse-whitespace-smart/input.html | 6 ++++++ .../text/collapse-whitespace-smart/output.min.html | 6 +++++- .../tests/fixture/text/empty/config.json | 3 +++ .../tests/fixture/text/empty/input.html | 2 ++ .../tests/fixture/text/empty/output.min.html | 1 + .../tests/fixture/text/select-1/config.json | 3 +++ .../tests/fixture/text/select-1/input.html | 10 ++++++++++ .../tests/fixture/text/select-1/output.min.html | 1 + .../tests/fixture/text/select/config.json | 3 +++ .../tests/fixture/text/select/input.html | 10 ++++++++++ .../tests/fixture/text/select/output.min.html | 1 + 15 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 crates/swc_html_minifier/tests/fixture/text/empty/config.json create mode 100644 crates/swc_html_minifier/tests/fixture/text/empty/input.html create mode 100644 crates/swc_html_minifier/tests/fixture/text/empty/output.min.html create mode 100644 crates/swc_html_minifier/tests/fixture/text/select-1/config.json create mode 100644 crates/swc_html_minifier/tests/fixture/text/select-1/input.html create mode 100644 crates/swc_html_minifier/tests/fixture/text/select-1/output.min.html create mode 100644 crates/swc_html_minifier/tests/fixture/text/select/config.json create mode 100644 crates/swc_html_minifier/tests/fixture/text/select/input.html create mode 100644 crates/swc_html_minifier/tests/fixture/text/select/output.min.html 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 ba565cdc0a40..abd900341c42 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 @@ -261,5 +261,11 @@ +

+    foo
+    
+    baz
+
+ \ 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 e6fe89d6f0ba..24e3fe81022c 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
testtest
testtest

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
testtest
testtest

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
+    foo
+    
+    baz
+
\ 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 e93ec40df02d..920f03acba30 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 @@ -265,5 +265,11 @@ +
+    foo
+    
+    baz
+
+ \ 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 8f406972ebb6..2f13f6eda865 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
test test
testtest

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
\ 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
test test
testtest

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
+
\ 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 ba565cdc0a40..abd900341c42 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 @@ -261,5 +261,11 @@ +
+    foo
+    
+    baz
+
+ \ 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 5c3c244f8ec7..77eec78c0f19 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
test test
testtest

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
test test
testtest

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
+    foo
+    
+    baz
+
\ 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/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 From 1026cd40cdf255251e15809a58d68f898a747391 Mon Sep 17 00:00:00 2001 From: "alexander.akait" Date: Mon, 27 Jun 2022 21:56:49 +0300 Subject: [PATCH 05/17] test: more --- crates/swc_html_minifier/src/lib.rs | 2 +- .../tests/fixture/text/collapse-whitespace-all/input.html | 2 ++ .../fixture/text/collapse-whitespace-all/output.min.html | 2 +- .../fixture/text/collapse-whitespace-conservative/input.html | 2 ++ .../text/collapse-whitespace-conservative/output.min.html | 2 +- .../tests/fixture/text/collapse-whitespace-smart/input.html | 2 ++ .../fixture/text/collapse-whitespace-smart/output.min.html | 4 ++-- 7 files changed, 11 insertions(+), 5 deletions(-) diff --git a/crates/swc_html_minifier/src/lib.rs b/crates/swc_html_minifier/src/lib.rs index 2d3455ca507d..f5a880e0546f 100644 --- a/crates/swc_html_minifier/src/lib.rs +++ b/crates/swc_html_minifier/src/lib.rs @@ -1010,7 +1010,7 @@ impl Minifier { _ => true, }; - if result && mode.is_some() { + if mode.is_some() { prev = Some(child.clone()); } 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 abd900341c42..c4afccf6177d 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 @@ -267,5 +267,7 @@ baz +
a c
+ \ 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 24e3fe81022c..d050e1642d62 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 @@ -29,4 +29,4 @@ foo baz - \ No newline at end of file +
ac
\ 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 920f03acba30..1602c483f97c 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 @@ -271,5 +271,7 @@ baz +
a c
+ \ 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 2f13f6eda865..9d3c864f44f3 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 @@ -29,4 +29,4 @@ foo baz - \ No newline at end of file +
a c
\ 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 abd900341c42..c4afccf6177d 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 @@ -267,5 +267,7 @@ baz +
a c
+ \ 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 77eec78c0f19..b7015bd590ff 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,8 +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
test test
testtest

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
+
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
     foo
     
     baz
-
\ No newline at end of file +
a c
\ No newline at end of file From fd9fe649c610d9230244356964b7c1efd3cd3073 Mon Sep 17 00:00:00 2001 From: "alexander.akait" Date: Mon, 27 Jun 2022 22:07:04 +0300 Subject: [PATCH 06/17] test: more --- .../tests/fixture/comment/spaces/config.json | 3 +++ .../tests/fixture/comment/spaces/input.html | 8 ++++++++ .../tests/fixture/comment/spaces/output.min.html | 1 + .../tests/fixture/text/collapse-whitespace-all/input.html | 8 ++++++++ .../fixture/text/collapse-whitespace-all/output.min.html | 2 +- .../text/collapse-whitespace-conservative/input.html | 8 ++++++++ .../text/collapse-whitespace-conservative/output.min.html | 2 +- .../fixture/text/collapse-whitespace-smart/input.html | 8 ++++++++ .../text/collapse-whitespace-smart/output.min.html | 2 +- .../tests/fixture/text/empty-1/config.json | 3 +++ .../tests/fixture/text/empty-1/input.html | 2 ++ .../tests/fixture/text/empty-1/output.min.html | 1 + .../tests/fixture/text/empty-2/config.json | 3 +++ .../tests/fixture/text/empty-2/input.html | 2 ++ .../tests/fixture/text/empty-2/output.min.html | 1 + .../tests/fixture/text/empty-3/config.json | 3 +++ .../tests/fixture/text/empty-3/input.html | 1 + .../tests/fixture/text/empty-3/output.min.html | 1 + .../tests/fixture/text/empty-4/config.json | 3 +++ .../tests/fixture/text/empty-4/input.html | 1 + .../tests/fixture/text/empty-4/output.min.html | 1 + .../tests/fixture/text/empty-5/config.json | 3 +++ .../tests/fixture/text/empty-5/input.html | 1 + .../tests/fixture/text/empty-5/output.min.html | 1 + 24 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 crates/swc_html_minifier/tests/fixture/comment/spaces/config.json create mode 100644 crates/swc_html_minifier/tests/fixture/comment/spaces/input.html create mode 100644 crates/swc_html_minifier/tests/fixture/comment/spaces/output.min.html create mode 100644 crates/swc_html_minifier/tests/fixture/text/empty-1/config.json create mode 100644 crates/swc_html_minifier/tests/fixture/text/empty-1/input.html create mode 100644 crates/swc_html_minifier/tests/fixture/text/empty-1/output.min.html create mode 100644 crates/swc_html_minifier/tests/fixture/text/empty-2/config.json create mode 100644 crates/swc_html_minifier/tests/fixture/text/empty-2/input.html create mode 100644 crates/swc_html_minifier/tests/fixture/text/empty-2/output.min.html create mode 100644 crates/swc_html_minifier/tests/fixture/text/empty-3/config.json create mode 100644 crates/swc_html_minifier/tests/fixture/text/empty-3/input.html create mode 100644 crates/swc_html_minifier/tests/fixture/text/empty-3/output.min.html create mode 100644 crates/swc_html_minifier/tests/fixture/text/empty-4/config.json create mode 100644 crates/swc_html_minifier/tests/fixture/text/empty-4/input.html create mode 100644 crates/swc_html_minifier/tests/fixture/text/empty-4/output.min.html create mode 100644 crates/swc_html_minifier/tests/fixture/text/empty-5/config.json create mode 100644 crates/swc_html_minifier/tests/fixture/text/empty-5/input.html create mode 100644 crates/swc_html_minifier/tests/fixture/text/empty-5/output.min.html 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/collapse-whitespace-all/input.html b/crates/swc_html_minifier/tests/fixture/text/collapse-whitespace-all/input.html index c4afccf6177d..656cf99e1f63 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 @@ -269,5 +269,13 @@
a c
+
Empty
+ + + + + \ 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 d050e1642d62..6d079190407d 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 @@ -29,4 +29,4 @@ foo baz -
ac
\ No newline at end of file +
ac
Empty
\ 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 1602c483f97c..7e877db963c8 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 @@ -273,5 +273,13 @@
a c
+
Empty
+ + + + + \ 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 9d3c864f44f3..59145b6f45ed 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 @@ -29,4 +29,4 @@ foo baz -
a c
\ No newline at end of file +
a c
Empty
\ 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 c4afccf6177d..656cf99e1f63 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 @@ -269,5 +269,13 @@
a c
+
Empty
+ + + + + \ 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 b7015bd590ff..77b2700bff68 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 @@ -29,4 +29,4 @@ foo baz -
a c
\ No newline at end of file +
a c
Empty
\ 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 From 3051d2b386a439b7df5eab8f6b1dfc2016e36b3d Mon Sep 17 00:00:00 2001 From: "alexander.akait" Date: Mon, 27 Jun 2022 23:10:39 +0300 Subject: [PATCH 07/17] fix: bug with collapsing between comments --- crates/swc_html_minifier/src/lib.rs | 19 +++++++++++++++++++ .../fixture/comment/html/output.min.html | 1 - .../collapse-whitespace-smart/output.min.html | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/crates/swc_html_minifier/src/lib.rs b/crates/swc_html_minifier/src/lib.rs index f5a880e0546f..2407e8077fb8 100644 --- a/crates/swc_html_minifier/src/lib.rs +++ b/crates/swc_html_minifier/src/lib.rs @@ -825,6 +825,25 @@ 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; + + children.retain_mut(|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 + } + _ => true, + } + }); + let mode = self .collapse_whitespaces .as_ref() 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..db5a672bf5ce 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,3 @@ Document -
test
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 77b2700bff68..154304c5e60f 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,7 +25,7 @@ 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
+
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
     foo
     
     baz

From 9009888223884519cf4018113fcf95563dd4ab80 Mon Sep 17 00:00:00 2001
From: "alexander.akait" 
Date: Mon, 27 Jun 2022 23:25:49 +0300
Subject: [PATCH 08/17] refactor: code

---
 crates/swc_html_minifier/src/lib.rs           | 352 +++++++++---------
 .../fixture/comment/html/output.min.html      |   1 +
 .../collapse-whitespace-smart/output.min.html |   2 +-
 .../fixture/text/inline-17/output.min.html    |   2 +-
 4 files changed, 176 insertions(+), 181 deletions(-)

diff --git a/crates/swc_html_minifier/src/lib.rs b/crates/swc_html_minifier/src/lib.rs
index 2407e8077fb8..4bf157736571 100644
--- a/crates/swc_html_minifier/src/lib.rs
+++ b/crates/swc_html_minifier/src/lib.rs
@@ -823,44 +823,185 @@ 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;
-
-        children.retain_mut(|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
-                }
-                _ => true,
-            }
-        });
+        let (namespace, tag_name) = match &self.current_element {
+            Some(element) => (element.namespace, &element.tag_name),
+            _ => return,
+        };
 
-        let mode = self
+        if let Some(mode) = self
             .collapse_whitespaces
             .as_ref()
-            .map(|mode| self.get_whitespace_minification_for_tag(mode, namespace, tag_name));
+            .map(|mode| self.get_whitespace_minification_for_tag(mode, namespace, tag_name))
+        {
+            let cloned_children = children.clone();
 
-        let mut index = 0;
+            let mut index = 0;
+            let mut prev = None;
+            let mut next = None;
 
-        let mut cloned_children = None;
+            children.retain_mut(|child| {
+                index += 1;
+                next = cloned_children.get(index);
 
-        if mode.is_some() {
-            cloned_children = Some(children.clone());
-        }
+                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)
+                                            } else {
+                                                false
+                                            }
+                                        }
+                                        _ => true,
+                                    }
+                                }
+                            };
+
+                            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 {
+                            &*text.data
+                        };
+
+                        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();
 
-        let mut prev = None;
-        let mut next = None;
+                            true
+                        } else {
+                            text.data = value.into();
+
+                            true
+                        }
+                    }
+                    _ => true,
+                };
 
-        if namespace == Namespace::HTML && &**tag_name == "body" {
+                prev = Some(child.clone());
+
+                result
+            });
+        }
+
+        if namespace == Namespace::HTML && tag_name == "body" {
             if let Some(first) = children.first_mut() {
                 self.remove_whitespace_from_first_text_element(first);
             }
@@ -871,15 +1012,7 @@ impl Minifier {
         }
 
         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 {
+            match child {
                 Child::Comment(comment) if self.remove_comments => {
                     self.is_preserved_comment(&comment.data)
                 }
@@ -892,148 +1025,9 @@ impl Minifier {
                 {
                     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)
-                                        } else {
-                                            false
-                                        }
-                                    }
-                                    _ => true,
-                                }
-                            }
-                        };
-
-                        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.is_some() && mode.unwrap().trim) || is_smart_left_trim
-                    {
-                        text.data.trim_start_matches(is_whitespace)
-                    } else {
-                        &*text.data
-                    };
-
-                    value = if (mode.is_some() && mode.unwrap().trim) || is_smart_right_trim {
-                        value.trim_end_matches(is_whitespace)
-                    } else {
-                        value
-                    };
-
-                    if value.is_empty() {
-                        false
-                    } else if mode.is_some() && mode.unwrap().collapse {
-                        text.data = self.collapse_whitespace(value).into();
-
-                        true
-                    } else {
-                        text.data = value.into();
-
-                        true
-                    }
-                }
+                Child::Text(text) if text.data.is_empty() => false,
                 _ => true,
-            };
-
-            if mode.is_some() {
-                prev = Some(child.clone());
             }
-
-            result
         });
     }
 
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 db5a672bf5ce..499acff5dee5 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,3 +1,4 @@
 Document
+
 
test
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 154304c5e60f..77b2700bff68 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,7 +25,7 @@ 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
+
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
     foo
     
     baz
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
index 4100e4b9ebd1..1a58c16aabb6 100644
--- 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
@@ -1 +1 @@
-Document 
\ No newline at end of file
+Document
\ No newline at end of file

From e2ae6b960b12f07602910bbb092ab9687eb6b7e4 Mon Sep 17 00:00:00 2001
From: "alexander.akait" 
Date: Mon, 27 Jun 2022 23:35:21 +0300
Subject: [PATCH 09/17] refactor: code

---
 crates/swc_html_minifier/src/lib.rs           | 60 ++++++++++---------
 .../collapse-whitespace-smart/output.min.html |  2 +-
 .../fixture/text/inline-17/output.min.html    |  2 +-
 .../tests/fixture/text/inline-18/config.json  |  3 +
 .../tests/fixture/text/inline-18/input.html   | 11 ++++
 .../fixture/text/inline-18/output.min.html    |  1 +
 6 files changed, 48 insertions(+), 31 deletions(-)
 create mode 100644 crates/swc_html_minifier/tests/fixture/text/inline-18/config.json
 create mode 100644 crates/swc_html_minifier/tests/fixture/text/inline-18/input.html
 create mode 100644 crates/swc_html_minifier/tests/fixture/text/inline-18/output.min.html

diff --git a/crates/swc_html_minifier/src/lib.rs b/crates/swc_html_minifier/src/lib.rs
index 4bf157736571..3368041f5149 100644
--- a/crates/swc_html_minifier/src/lib.rs
+++ b/crates/swc_html_minifier/src/lib.rs
@@ -828,6 +828,37 @@ impl Minifier {
             _ => return,
         };
 
+        // Remove all comments and safe whitespaces firstly
+        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| {
+            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,
+                _ => true,
+            }
+        });
+
+        // Normalize whitespaces - collapse and trim them
         if let Some(mode) = self
             .collapse_whitespaces
             .as_ref()
@@ -1000,35 +1031,6 @@ impl Minifier {
                 result
             });
         }
-
-        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| {
-            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,
-                _ => true,
-            }
-        });
     }
 
     // TODO source map url output?
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 77b2700bff68..154304c5e60f 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,7 +25,7 @@
 
     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
+
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
     foo
     
     baz
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
index 1a58c16aabb6..4100e4b9ebd1 100644
--- 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
@@ -1 +1 @@
-Document
\ No newline at end of file
+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

From 97b2e3d1e3ffbbadd351ae5f239f90c02f48bd90 Mon Sep 17 00:00:00 2001
From: "alexander.akait" 
Date: Tue, 28 Jun 2022 21:01:08 +0300
Subject: [PATCH 10/17] fix: leading and trailing whitespaces

---
 crates/swc_html_minifier/src/lib.rs           | 81 ++++++++++---------
 .../fixture/comment/html/output.min.html      |  1 -
 .../fixture/text/inline-17/output.min.html    |  2 +-
 3 files changed, 42 insertions(+), 42 deletions(-)

diff --git a/crates/swc_html_minifier/src/lib.rs b/crates/swc_html_minifier/src/lib.rs
index 3368041f5149..a3a4f68969c3 100644
--- a/crates/swc_html_minifier/src/lib.rs
+++ b/crates/swc_html_minifier/src/lib.rs
@@ -689,41 +689,47 @@ 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);
                 }
+                _ => {}
             }
-            _ => {}
         }
     }
 
@@ -828,17 +834,7 @@ impl Minifier {
             _ => return,
         };
 
-        // Remove all comments and safe whitespaces firstly
-        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)
-            }
-        }
-
+        // Drop comments firstly
         children.retain_mut(|child| {
             match child {
                 Child::Comment(comment) if self.remove_comments => {
@@ -1031,6 +1027,11 @@ impl Minifier {
                 result
             });
         }
+
+        // Remove all comments and safe whitespaces lately
+        if namespace == Namespace::HTML && tag_name == "body" {
+            self.remove_leading_and_trailing_whitespaces(children);
+        }
     }
 
     // TODO source map url output?
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..db5a672bf5ce 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,3 @@
 Document
-
 
test
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 index 4100e4b9ebd1..1a58c16aabb6 100644 --- 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 @@ -1 +1 @@ -Document \ No newline at end of file +Document \ No newline at end of file From 2673ae19560a30c702b5c73e819f5a832437a4cb Mon Sep 17 00:00:00 2001 From: "alexander.akait" Date: Tue, 28 Jun 2022 22:09:48 +0300 Subject: [PATCH 11/17] refactor: code --- crates/swc_html_minifier/src/lib.rs | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/crates/swc_html_minifier/src/lib.rs b/crates/swc_html_minifier/src/lib.rs index a3a4f68969c3..d43559324e71 100644 --- a/crates/swc_html_minifier/src/lib.rs +++ b/crates/swc_html_minifier/src/lib.rs @@ -834,7 +834,8 @@ impl Minifier { _ => return, }; - // Drop comments firstly + // Drop comments and safe whitespaces (children of head and html are not + // rendered) firstly children.retain_mut(|child| { match child { Child::Comment(comment) if self.remove_comments => { @@ -868,21 +869,10 @@ impl Minifier { children.retain_mut(|child| { index += 1; + 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 => @@ -1022,7 +1012,9 @@ impl Minifier { _ => true, }; - prev = Some(child.clone()); + if matches!(child, Child::Element(_)) { + prev = Some(child.clone()); + } result }); From 7913b6971faa09417cc6819e3c3e64cd89c8fe4b Mon Sep 17 00:00:00 2001 From: "alexander.akait" Date: Tue, 28 Jun 2022 23:55:25 +0300 Subject: [PATCH 12/17] fix: bugs --- crates/swc_html_minifier/src/lib.rs | 37 +++++++++++++++++++ .../tests/fixture/comment/basic/input.html | 14 +++++++ .../fixture/comment/basic/output.min.html | 16 +++++++- .../fixture/comment/html/output.min.html | 4 +- .../collapse-whitespace-all/output.min.html | 2 +- .../output.min.html | 4 +- .../collapse-whitespace-smart/output.min.html | 2 +- 7 files changed, 71 insertions(+), 8 deletions(-) diff --git a/crates/swc_html_minifier/src/lib.rs b/crates/swc_html_minifier/src/lib.rs index d43559324e71..b7bd43eea1fe 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}; @@ -855,6 +857,41 @@ impl Minifier { } }); + // Merge text nodes after comments removing + let cloned_children = children.clone(); + + let mut index = 0; + let mut pending_text = vec![]; + + children.retain_mut(|child| { + index += 1; + + match child { + Child::Text(text) => { + if let Some(Child::Text(_)) = cloned_children.get(index) { + pending_text.push(text.data.clone()); + + false + } else if !pending_text.is_empty() { + let mut new_data = String::new(); + + for pending_text in take(&mut pending_text) { + new_data.push_str(&pending_text); + } + + new_data.push_str(&text.data); + + text.data = new_data.into(); + + true + } else { + true + } + } + _ => true, + } + }); + // Normalize whitespaces - collapse and trim them if let Some(mode) = self .collapse_whitespaces 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 db5a672bf5ce..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,3 +1 @@ -Document -
test
- +Document
test
\ 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 6d079190407d..bea24b173e0e 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,7 +25,7 @@ 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
+
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
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 59145b6f45ed..2fb0bea1d444 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,8 +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
foo
+ 
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
\ No newline at end of file +
a c
Empty
\ 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 154304c5e60f..6b2e1eefadc3 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,7 +25,7 @@ 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
+
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

From a814cce92b32038faf3f83f981243948e32f006e Mon Sep 17 00:00:00 2001
From: "alexander.akait" 
Date: Wed, 29 Jun 2022 00:48:58 +0300
Subject: [PATCH 13/17] refactor: code

---
 crates/swc_html_minifier/src/lib.rs           | 57 ++++++++++++-------
 .../text/collapse-whitespace-all/input.html   |  3 +
 .../collapse-whitespace-all/output.min.html   |  2 +-
 .../input.html                                |  3 +
 .../output.min.html                           |  2 +-
 .../text/collapse-whitespace-smart/input.html |  4 ++
 .../collapse-whitespace-smart/output.min.html |  2 +-
 7 files changed, 48 insertions(+), 25 deletions(-)

diff --git a/crates/swc_html_minifier/src/lib.rs b/crates/swc_html_minifier/src/lib.rs
index b7bd43eea1fe..967839f09164 100644
--- a/crates/swc_html_minifier/src/lib.rs
+++ b/crates/swc_html_minifier/src/lib.rs
@@ -836,9 +836,7 @@ impl Minifier {
             _ => return,
         };
 
-        // Drop comments and safe whitespaces (children of head and html are not
-        // rendered) firstly
-        children.retain_mut(|child| {
+        let child_will_be_retained = |child: &Child| {
             match child {
                 Child::Comment(comment) if self.remove_comments => {
                     self.is_preserved_comment(&comment.data)
@@ -855,40 +853,55 @@ impl Minifier {
                 Child::Text(text) if text.data.is_empty() => false,
                 _ => true,
             }
-        });
+        };
 
-        // Merge text nodes after comments removing
         let cloned_children = children.clone();
 
         let mut index = 0;
         let mut pending_text = vec![];
 
+        // Drop comments and safe whitespaces (children of head and html are not
+        // rendered) firstly
         children.retain_mut(|child| {
+            let result = child_will_be_retained(child);
+
             index += 1;
 
+            if !result {
+                return false;
+            }
+
+            let next = cloned_children.get(index);
+
             match child {
-                Child::Text(text) => {
-                    if let Some(Child::Text(_)) = cloned_children.get(index) {
-                        pending_text.push(text.data.clone());
+                Child::Text(text)
+                    if next.is_some()
+                        && !child_will_be_retained(next.unwrap())
+                        && matches!(
+                            cloned_children.get(index + 1),
+                            Some(Child::Text(_)) | Some(Child::Comment(_))
+                        ) =>
+                {
+                    pending_text.push(text.data.clone());
 
-                        false
-                    } else if !pending_text.is_empty() {
-                        let mut new_data = String::new();
+                    false
+                }
+                Child::Text(text) if !pending_text.is_empty() => {
+                    let mut new_data = String::with_capacity(
+                        pending_text.iter().map(|x| x.len()).sum::() + text.data.len(),
+                    );
 
-                        for pending_text in take(&mut pending_text) {
-                            new_data.push_str(&pending_text);
-                        }
+                    for pending_text in take(&mut pending_text) {
+                        new_data.push_str(&pending_text);
+                    }
 
-                        new_data.push_str(&text.data);
+                    new_data.push_str(&text.data);
 
-                        text.data = new_data.into();
+                    text.data = new_data.into();
 
-                        true
-                    } else {
-                        true
-                    }
+                    true
                 }
-                _ => true,
+                _ => result,
             }
         });
 
@@ -1057,7 +1070,7 @@ impl Minifier {
             });
         }
 
-        // Remove all comments and safe whitespaces lately
+        // Remove all leading and trailing whitespaces for the `body` element
         if namespace == Namespace::HTML && tag_name == "body" {
             self.remove_leading_and_trailing_whitespaces(children);
         }
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 656cf99e1f63..908f0693a21e 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
@@ -277,5 +277,8 @@
 
 
 
+
a b
+
a b c d
+ \ 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 bea24b173e0e..6230e633e970 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 @@ -29,4 +29,4 @@ foo baz -
ac
Empty
\ No newline at end of file +
ac
Empty
a b
a b c d
\ 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 7e877db963c8..39ef93e9cbac 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 @@ -281,5 +281,8 @@ +
a b
+
a b c d
+ \ 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 2fb0bea1d444..2ceeb9b38c93 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 @@ -29,4 +29,4 @@ foo baz -
a c
Empty
\ No newline at end of file +
a c
Empty
a b
a b c d
\ 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 656cf99e1f63..34d4ca5cec84 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 @@ -277,5 +277,9 @@ +
a b
+ +
a b c d
+ \ 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 6b2e1eefadc3..eecdc26954de 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 @@ -29,4 +29,4 @@ foo baz -
a c
Empty
\ No newline at end of file +
a c
Empty
a b
a b c d
\ No newline at end of file From fd511293f040e2f5fa7578d4a96aa22daec0c49f Mon Sep 17 00:00:00 2001 From: "alexander.akait" Date: Wed, 29 Jun 2022 01:02:16 +0300 Subject: [PATCH 14/17] refactor: code --- crates/swc_html_minifier/src/lib.rs | 282 ++++++++++++++-------------- 1 file changed, 140 insertions(+), 142 deletions(-) diff --git a/crates/swc_html_minifier/src/lib.rs b/crates/swc_html_minifier/src/lib.rs index 967839f09164..8bbac7f0f3e4 100644 --- a/crates/swc_html_minifier/src/lib.rs +++ b/crates/swc_html_minifier/src/lib.rs @@ -906,169 +906,167 @@ impl Minifier { }); // Normalize whitespaces - collapse and trim them - if let Some(mode) = self + let mode = self .collapse_whitespaces .as_ref() - .map(|mode| self.get_whitespace_minification_for_tag(mode, namespace, tag_name)) - { - let cloned_children = children.clone(); + .map(|mode| self.get_whitespace_minification_for_tag(mode, namespace, tag_name)); - let mut index = 0; - let mut prev = None; - let mut next = None; + let mut index = 0; + let mut prev = None; + let mut next = None; - children.retain_mut(|child| { - index += 1; + children.retain_mut(|child| { + index += 1; - next = cloned_children.get(index); + next = cloned_children.get(index); - let result = match child { - 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 - } + let result = match child { + 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) => { + 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) - } 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) + } else { + false } - _ => true, } + _ => true, } - }; - - 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) + let next_display = if let Some(Child::Element(Element { + namespace, + tag_name, + .. + })) = &next + { + Some(self.get_display(*namespace, tag_name)) } else { - &*text.data + None }; - value = if (mode.trim) || is_smart_right_trim { - value.trim_end_matches(is_whitespace) - } else { - value + 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) + } }; + } - if value.is_empty() { - false - } else if mode.collapse { - text.data = self.collapse_whitespace(value).into(); + let mut value = if (mode.trim) || is_smart_left_trim { + text.data.trim_start_matches(is_whitespace) + } else { + &*text.data + }; - true - } else { - text.data = value.into(); + value = if (mode.trim) || is_smart_right_trim { + value.trim_end_matches(is_whitespace) + } else { + value + }; - true - } - } - _ => true, - }; + if value.is_empty() { + false + } else if mode.collapse { + text.data = self.collapse_whitespace(value).into(); + + true + } else { + text.data = value.into(); - if matches!(child, Child::Element(_)) { - prev = Some(child.clone()); + true + } } + _ => child_will_be_retained(child), + }; - result - }); - } + if matches!(child, Child::Element(_)) { + prev = Some(child.clone()); + } + + result + }); // Remove all leading and trailing whitespaces for the `body` element if namespace == Namespace::HTML && tag_name == "body" { From 48600b7af70453e1fdd22741439483b8a0c764eb Mon Sep 17 00:00:00 2001 From: "alexander.akait" Date: Wed, 29 Jun 2022 01:37:26 +0300 Subject: [PATCH 15/17] refactor: code --- crates/swc_html_minifier/src/lib.rs | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/crates/swc_html_minifier/src/lib.rs b/crates/swc_html_minifier/src/lib.rs index 8bbac7f0f3e4..4611ef51dda2 100644 --- a/crates/swc_html_minifier/src/lib.rs +++ b/crates/swc_html_minifier/src/lib.rs @@ -735,7 +735,7 @@ impl Minifier { } } - 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 { @@ -744,7 +744,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 @@ -912,8 +912,8 @@ impl Minifier { .map(|mode| self.get_whitespace_minification_for_tag(mode, namespace, tag_name)); let mut index = 0; - let mut prev = None; - let mut next = None; + let mut prev: Option<&Child> = None; + let mut next: Option<&Child> = None; children.retain_mut(|child| { index += 1; @@ -965,10 +965,14 @@ impl Minifier { ) => true, // Inline box Some(Display::Inline) => { - let deep = self.get_deep_last_text_element(prev.as_mut().unwrap()); + 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) + if let Some(deep) = deep { + deep.data.ends_with(is_whitespace) + } else { + false + } } else { false } @@ -1058,12 +1062,10 @@ impl Minifier { true } } - _ => child_will_be_retained(child), + _ => true, }; - if matches!(child, Child::Element(_)) { - prev = Some(child.clone()); - } + prev = cloned_children.get(index - 1); result }); From 06135bd6a46e57e7b8016afb535fc894a5b43209 Mon Sep 17 00:00:00 2001 From: "alexander.akait" Date: Wed, 29 Jun 2022 05:28:43 +0300 Subject: [PATCH 16/17] refactor: code --- crates/swc_html_minifier/src/lib.rs | 430 +++++++++++++++------------- 1 file changed, 227 insertions(+), 203 deletions(-) diff --git a/crates/swc_html_minifier/src/lib.rs b/crates/swc_html_minifier/src/lib.rs index 4611ef51dda2..0db2b3945475 100644 --- a/crates/swc_html_minifier/src/lib.rs +++ b/crates/swc_html_minifier/src/lib.rs @@ -754,6 +754,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, @@ -836,236 +877,219 @@ impl Minifier { _ => return, }; - let child_will_be_retained = |child: &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, - _ => true, - } - }; - - let cloned_children = children.clone(); - - let mut index = 0; - let mut pending_text = vec![]; - - // Drop comments and safe whitespaces (children of head and html are not - // rendered) firstly - children.retain_mut(|child| { - let result = child_will_be_retained(child); - - index += 1; - - if !result { - return false; - } - - let next = cloned_children.get(index); - - match child { - Child::Text(text) - if next.is_some() - && !child_will_be_retained(next.unwrap()) - && matches!( - cloned_children.get(index + 1), - Some(Child::Text(_)) | Some(Child::Comment(_)) - ) => - { - pending_text.push(text.data.clone()); - - false - } - Child::Text(text) if !pending_text.is_empty() => { - let mut new_data = String::with_capacity( - pending_text.iter().map(|x| x.len()).sum::() + text.data.len(), - ); - - for pending_text in take(&mut pending_text) { - new_data.push_str(&pending_text); - } - - new_data.push_str(&text.data); - - text.data = new_data.into(); - - true - } - _ => result, - } - }); - - // Normalize whitespaces - collapse and trim them 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 prev: Option<&Child> = None; - let mut next: Option<&Child> = None; - - children.retain_mut(|child| { - index += 1; - - next = cloned_children.get(index); - - let result = match child { - 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) + 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 } - } 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) - } 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) + } else { + false + } } + _ => true, } - _ => true, } - } - }; + }; + + 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 next_display = if let Some(Child::Element(Element { - namespace, - tag_name, - .. - })) = &next - { - Some(self.get_display(*namespace, tag_name)) + 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.trim) || is_smart_left_trim { - text.data.trim_start_matches(is_whitespace) - } else { - &*text.data - }; + let cloned_children = children.clone(); - value = if (mode.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.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); + + let result = child_will_be_retained(child, prev, next); - prev = cloned_children.get(index - 1); + index += 1; result }); From 1e3d2c8cf432188d8d5193f961ce9482f4f47330 Mon Sep 17 00:00:00 2001 From: "alexander.akait" Date: Wed, 29 Jun 2022 07:02:38 +0300 Subject: [PATCH 17/17] test: more --- .../tests/fixture/text/collapse-whitespace-all/input.html | 6 ++++++ .../fixture/text/collapse-whitespace-all/output.min.html | 2 +- .../text/collapse-whitespace-conservative/input.html | 6 ++++++ .../text/collapse-whitespace-conservative/output.min.html | 2 +- .../tests/fixture/text/collapse-whitespace-smart/input.html | 5 +++++ .../fixture/text/collapse-whitespace-smart/output.min.html | 2 +- 6 files changed, 20 insertions(+), 3 deletions(-) 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 908f0693a21e..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 @@ -278,7 +278,13 @@
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 6230e633e970..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 @@ -29,4 +29,4 @@ foo baz -
ac
Empty
a b
a b c d
\ No newline at end of file +
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 39ef93e9cbac..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 @@ -282,7 +282,13 @@
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 2ceeb9b38c93..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 @@ -29,4 +29,4 @@ foo baz -
a c
Empty
a b
a b c d
\ No newline at end of file +
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 34d4ca5cec84..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 @@ -281,5 +281,10 @@
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 eecdc26954de..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 @@ -29,4 +29,4 @@ foo baz -
a c
Empty
a b
a b c d
\ No newline at end of file +
a c
Empty
a b
a b c d
text
text text \ No newline at end of file