diff --git a/crates/swc_html_codegen/src/lib.rs b/crates/swc_html_codegen/src/lib.rs index a3a6cfde025..7d88a60cc6b 100644 --- a/crates/swc_html_codegen/src/lib.rs +++ b/crates/swc_html_codegen/src/lib.rs @@ -655,11 +655,9 @@ where attribute.push_str(&minifier); } else { - let quote = if value.contains('"') { '\'' } else { '"' }; + let normalized = normalize_attribute_value(value); - attribute.push(quote); - attribute.push_str(value); - attribute.push(quote); + attribute.push_str(&normalized); } } @@ -671,26 +669,16 @@ where if self.ctx.skip_escape_text { write_str!(self, n.span, &n.value); } else { - let mut data = String::new(); + let mut data = String::with_capacity(n.value.len()); if self.ctx.need_extra_newline_in_text && n.value.contains('\n') { data.push('\n'); } - for c in n.value.chars() { - match c { - '&' => { - data.push_str(&String::from("&")); - } - '<' => { - data.push_str(&String::from("<")); - } - '>' => { - data.push_str(&String::from(">")); - } - '\u{00A0}' => data.push_str(&String::from(" ")), - _ => data.push(c), - } + if self.config.minify { + data.push_str(&minify_text(&n.value)); + } else { + data.push_str(&escape_string(&n.value, false)); } write_str!(self, n.span, &data); @@ -699,7 +687,7 @@ where #[emitter] fn emit_comment(&mut self, n: &Comment) -> Result { - let mut comment = String::new(); + let mut comment = String::with_capacity(n.data.len() + 7); comment.push_str(" @@ -68,20 +68,20 @@
test
test
-
test
+
test
test
-
test
+
test
test
-
test
+
test
test
-
test
-
test
-
test
-
test
-
test
-
test
+
test
+
test
+
test
+
test
+
test
+
test
test
test
test
test
+test +test +test +test +test +test +Test +Test +Test +Test +Test +Test + +
+ &quot; +
+ + + + + +
+ foo & bar + foo&bar + foo&&& bar +
+ +
Label current;
+// Load effective address of current instruction into rcx.
+__ leaq(rcx, Operand(&current));
+__ bind(&current);
+
+ +
+ &xxx; &xxx &thorn; &thorn &curren;t &current &current; && + &gt + &unknown; + &current + &current; + &current + &current; + + ø &osLash Ø + &ø &&osLash; &Ø + &ø &&osLash; &Ø + + &oslash; &osLash; &Oslash; + &oslash; &osLash; &Oslash; +
+ \ No newline at end of file diff --git a/crates/swc_html_codegen/tests/fixture/attribute/output.min.html b/crates/swc_html_codegen/tests/fixture/attribute/output.min.html index 9dfeb0d95dc..8f548bd684a 100644 --- a/crates/swc_html_codegen/tests/fixture/attribute/output.min.html +++ b/crates/swc_html_codegen/tests/fixture/attribute/output.min.html @@ -89,5 +89,61 @@ foo
test
test
+test +test +test +test +test +test +Test +Test +Test +Test +Test +Test + +
+ &quot; +
+ + + + + +
+ foo & bar + foo&bar + foo&&& bar +
+ +
Label current;
+// Load effective address of current instruction into rcx.
+__ leaq(rcx, Operand(&current));
+__ bind(&current);
+
+ +
+ &xxx; &xxx &thorn; &thorn &curren;t &current &current; && + &gt + &unknown; + &current + &current; + &current + &current; + + ø &osLash Ø + &ø &&osLash; &Ø + &ø &&osLash; &Ø + + &oslash; &osLash; &Oslash; + &oslash; &osLash; &Oslash; +
+ diff --git a/crates/swc_html_codegen/tests/fixture/html-entity/output.html b/crates/swc_html_codegen/tests/fixture/html-entity/output.html index 4b859854fd3..b8352b9980c 100644 --- a/crates/swc_html_codegen/tests/fixture/html-entity/output.html +++ b/crates/swc_html_codegen/tests/fixture/html-entity/output.html @@ -30,8 +30,8 @@
A space character: &&
I'm ∉ I tell you
-tired meme - +tired meme + kablammo! diff --git a/crates/swc_html_codegen/tests/fixture/html-entity/output.min.html b/crates/swc_html_codegen/tests/fixture/html-entity/output.min.html index fc19f67d400..e6026f13798 100644 --- a/crates/swc_html_codegen/tests/fixture/html-entity/output.min.html +++ b/crates/swc_html_codegen/tests/fixture/html-entity/output.min.html @@ -5,9 +5,9 @@
A space character: &
A space character: &
-
A space character:  
+
A space character:  
The less-than sign: <
-
The greater-than sign: >
+
The greater-than sign: >
The double quote sign: "
The single quote sign: '
The cent sign: ¢
@@ -28,8 +28,8 @@
A space character: &&
I'm ∉ I tell you
-tired meme - +tired meme + kablammo! diff --git a/crates/swc_html_codegen/tests/fixture/optional/output.min.html b/crates/swc_html_codegen/tests/fixture/optional/output.min.html index 4d59f979dc1..03c0231dea2 100644 --- a/crates/swc_html_codegen/tests/fixture/optional/output.min.html +++ b/crates/swc_html_codegen/tests/fixture/optional/output.min.html @@ -146,7 +146,7 @@ -   +   Batman Robin The Flash @@ -168,7 +168,7 @@ -   +   Batman Robin The Flash @@ -184,7 +184,7 @@ -   +   Batman Robin The Flash @@ -206,7 +206,7 @@ -   +   Batman Robin The Flash @@ -218,7 +218,7 @@ - + @@ -231,7 +231,7 @@
He-Man and Skeletor facts
   He-Man Skeletor
- + @@ -244,7 +244,7 @@
He-Man and Skeletor facts
   He-Man Skeletor
- + diff --git a/crates/swc_html_minifier/tests/fixture/text/basic/output.min.html b/crates/swc_html_minifier/tests/fixture/text/basic/output.min.html index 2697d38bfbf..72e337caa0b 100644 --- a/crates/swc_html_minifier/tests/fixture/text/basic/output.min.html +++ b/crates/swc_html_minifier/tests/fixture/text/basic/output.min.html @@ -1,8 +1,8 @@ Document -
Test
-
Test
+
Test
+
Test
Test
Test
Test
@@ -18,9 +18,9 @@

This Registered Trademark is a Script used in HTML document.

-
I want to display <br> tag
+
I want to display <br> tag
-
I want to display <i> tag
+
I want to display <i> tag
The cent sign: ¢
The cent sign: ¢
He-Man and Skeletor facts
   He-Man Skeletor