,
+ #[serde(default = "default_collapse_whitespaces")]
+ pub collapse_whitespaces: CollapseWhitespaces,
#[serde(default = "true_by_default")]
pub remove_comments: bool,
#[serde(default = "default_preserve_comments")]
@@ -76,13 +94,8 @@ impl Default for MinifyOptions {
}
}
-#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
-#[serde(deny_unknown_fields)]
-#[serde(rename_all = "kebab-case")]
-pub enum CollapseWhitespaces {
- All,
- Smart,
- Conservative,
+const fn default_collapse_whitespaces() -> CollapseWhitespaces {
+ CollapseWhitespaces::OnlyMetadata
}
const fn true_by_default() -> bool {
diff --git a/crates/swc_html_minifier/tests/fixture/text/collapse-whitespace-disabled/config.json b/crates/swc_html_minifier/tests/fixture/text/collapse-whitespace-disabled/config.json
new file mode 100644
index 000000000000..3631d0e846ff
--- /dev/null
+++ b/crates/swc_html_minifier/tests/fixture/text/collapse-whitespace-disabled/config.json
@@ -0,0 +1,3 @@
+{
+ "collapseWhitespaces": "none"
+}
\ No newline at end of file
diff --git a/crates/swc_html_minifier/tests/fixture/text/collapse-whitespace-disabled/input.html b/crates/swc_html_minifier/tests/fixture/text/collapse-whitespace-disabled/input.html
new file mode 100644
index 000000000000..b579ce15b599
--- /dev/null
+++ b/crates/swc_html_minifier/tests/fixture/text/collapse-whitespace-disabled/input.html
@@ -0,0 +1,290 @@
+
+
+
+ Document
+
+
+ test
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Foo Bar
+ Foo Bar
+
+
+ The quick brown fox
+ jumps over the lazy
+ dog.
+
+
+
+
+
+ Hey, I just found
+ out about this cool website!
+ [1]
+
+
+
+
+ Text
+
+
+
+ Text
+
+
+
+
+
+ Text
+
+
+
+
+
+foo
+
+
+
+
+ bar
+
+
+
+
+
+ Text
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ <circle>
+
+
+
+
+
+
+
+
+
+
+ test
+
+
+
+
+
+
+
+ foo
+
+
+
+ text
test
+
+
+testtest
+test test
+
+
+
+test test
+test test
+ a c
+
+
+
+ a b
+
+
+
+
+ test
+ test
+
+
+
+
+
test
+
test
+
test
+
test
+
+
+
+
test
+
test
+
test
+
test
+
+
+
+
+
+
+
+
+test test
+test test
+foo test foo
+footest foo
+foo test foo
+footest foo
+foo test foo
+foo test foo
+foo test foo
+
+ foo
+foo bar
+foo bar
+foo bar
+foo bar
+foo bar
+foo bar
+foo a bar
+ fo o
+ fo o
+
+a b
+
+
foo bar
+
+ foo bar
+foo
+foo
+
+foo test foo
+foo test foo test foo
+ foo foo foo
+ foo foo foo
+
+ a b c
+ a b c
+ a b c
+
+foo baz
+foo baz
+foo baz
+foobaz
+
+test foo baz
+foo baz test
+
+test
foo baz
+foo baz test
+
+
+
+
+ foo
+
+ baz
+
+
+ a c
+
+Empty
+
+
+
+
+
+a b
+
+a b c d
+
+ text
+
+ text
+ text
+
+
+
\ No newline at end of file
diff --git a/crates/swc_html_minifier/tests/fixture/text/collapse-whitespace-disabled/output.min.html b/crates/swc_html_minifier/tests/fixture/text/collapse-whitespace-disabled/output.min.html
new file mode 100644
index 000000000000..ee8aeb754e2d
--- /dev/null
+++ b/crates/swc_html_minifier/tests/fixture/text/collapse-whitespace-disabled/output.min.html
@@ -0,0 +1,274 @@
+
+ Document
+
+ test
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Foo Bar
+ Foo Bar
+
+
+ The quick brown fox
+ jumps over the lazy
+ dog.
+
+
+
+
+
+ Hey, I just found
+ out about this cool website!
+ [1]
+
+
+
+
+ Text
+
+
+
+ Text
+
+
+
+
+
+ Text
+
+
+
+
+
+foo
+
+
+
+
+ bar
+
+
+
+
+
+ Text
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ <circle>
+
+
+
+
+
+
+
+
+
+
+ test
+
+
+
+
+
+
+
+ foo
+
+
+
+ text
test
+
+
+testtest
+test test
+
+
+
+test test
+test test
+ a c
+
+
+
+ a b
+
+
+
+
+ test
+ test
+
+
+
+
+
test
+
test
+
test
+
test
+
+
+
+
test
+
test
+
test
+
test
+
+
+
+
+
+
+
+
+test test
+test test
+foo test foo
+footest foo
+foo test foo
+footest foo
+foo test foo
+foo test foo
+foo test foo
+
+ foo
+foo bar
+foo bar
+foo bar
+foo bar
+foo bar
+foo bar
+foo a bar
+ fo o
+ fo o
+
+a b
+
+
foo bar
+
+ foo bar
+foo
+foo
+
+foo test foo
+foo test foo test foo
+ foo foo foo
+ foo foo foo
+
+ a b c
+ a b c
+ a b c
+
+foo baz
+foo baz
+foo baz
+foobaz
+
+test foo baz
+foo baz test
+
+test
foo baz
+foo baz test
+
+
+
+
+ foo
+
+ baz
+
+
+ a c
+
+Empty
+
+
+
+
+
+a b
+
+a b c d
+
+ text
+
+ text
+ text
\ No newline at end of file
diff --git a/crates/swc_html_minifier/tests/fixture/text/collapse-whitespace-only-metadata/config.json b/crates/swc_html_minifier/tests/fixture/text/collapse-whitespace-only-metadata/config.json
new file mode 100644
index 000000000000..1e5187093c5c
--- /dev/null
+++ b/crates/swc_html_minifier/tests/fixture/text/collapse-whitespace-only-metadata/config.json
@@ -0,0 +1,3 @@
+{
+ "collapseWhitespaces": "only-metadata"
+}
\ No newline at end of file
diff --git a/crates/swc_html_minifier/tests/fixture/text/collapse-whitespace-only-metadata/input.html b/crates/swc_html_minifier/tests/fixture/text/collapse-whitespace-only-metadata/input.html
new file mode 100644
index 000000000000..b579ce15b599
--- /dev/null
+++ b/crates/swc_html_minifier/tests/fixture/text/collapse-whitespace-only-metadata/input.html
@@ -0,0 +1,290 @@
+
+
+
+ Document
+
+
+ test
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Foo Bar
+ Foo Bar
+
+
+ The quick brown fox
+ jumps over the lazy
+ dog.
+
+
+
+
+
+ Hey, I just found
+ out about this cool website!
+ [1]
+
+
+
+
+ Text
+
+
+
+ Text
+
+
+
+
+
+ Text
+
+
+
+
+
+foo
+
+
+
+
+ bar
+
+
+
+
+
+ Text
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ <circle>
+
+
+
+
+
+
+
+
+
+
+ test
+
+
+
+
+
+
+
+ foo
+
+
+
+ text
test
+
+
+testtest
+test test
+
+
+
+test test
+test test
+ a c
+
+
+
+ a b
+
+
+
+
+ test
+ test
+
+
+
+
+
test
+
test
+
test
+
test
+
+
+
+
test
+
test
+
test
+
test
+
+
+
+
+
+
+
+
+test test
+test test
+foo test foo
+footest foo
+foo test foo
+footest foo
+foo test foo
+foo test foo
+foo test foo
+
+ foo
+foo bar
+foo bar
+foo bar
+foo bar
+foo bar
+foo bar
+foo a bar
+ fo o
+ fo o
+
+a b
+
+
foo bar
+
+ foo bar
+foo
+foo
+
+foo test foo
+foo test foo test foo
+ foo foo foo
+ foo foo foo
+
+ a b c
+ a b c
+ a b c
+
+foo baz
+foo baz
+foo baz
+foobaz
+
+test foo baz
+foo baz test
+
+test
foo baz
+foo baz test
+
+
+
+
+ foo
+
+ baz
+
+
+ a c
+
+Empty
+
+
+
+
+
+a b
+
+a b c d
+
+ text
+
+ text
+ text
+
+
+
\ No newline at end of file
diff --git a/crates/swc_html_minifier/tests/fixture/text/collapse-whitespace-only-metadata/output.min.html b/crates/swc_html_minifier/tests/fixture/text/collapse-whitespace-only-metadata/output.min.html
new file mode 100644
index 000000000000..51fd7248b36a
--- /dev/null
+++ b/crates/swc_html_minifier/tests/fixture/text/collapse-whitespace-only-metadata/output.min.html
@@ -0,0 +1,271 @@
+Document test
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Foo Bar
+ Foo Bar
+
+
+ The quick brown fox
+ jumps over the lazy
+ dog.
+
+
+
+
+
+ Hey, I just found
+ out about this cool website!
+ [1]
+
+
+
+
+ Text
+
+
+
+ Text
+
+
+
+
+
+ Text
+
+
+
+
+
+foo
+
+
+
+
+ bar
+
+
+
+
+
+ Text
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ <circle>
+
+
+
+
+
+
+
+
+
+
+ test
+
+
+
+
+
+
+
+ foo
+
+
+
+ text
test
+
+
+testtest
+test test
+
+
+
+test test
+test test
+ a c
+
+
+
+ a b
+
+
+
+
+ test
+ test
+
+
+
+
+
test
+
test
+
test
+
test
+
+
+
+
test
+
test
+
test
+
test
+
+
+
+
+
+
+
+
+test test
+test test
+foo test foo
+footest foo
+foo test foo
+footest foo
+foo test foo
+foo test foo
+foo test foo
+
+ foo
+foo bar
+foo bar
+foo bar
+foo bar
+foo bar
+foo bar
+foo a bar
+ fo o
+ fo o
+
+a b
+
+
foo bar
+
+ foo bar
+foo
+foo
+
+foo test foo
+foo test foo test foo
+ foo foo foo
+ foo foo foo
+
+ a b c
+ a b c
+ a b c
+
+foo baz
+foo baz
+foo baz
+foobaz
+
+test foo baz
+foo baz test
+
+test
foo baz
+foo baz test
+
+
+
+
+ foo
+
+ baz
+
+
+ a c
+
+Empty
+
+
+
+
+
+a b
+
+a b c d
+
+ text
+
+ text
+ text
\ No newline at end of file