diff --git a/crates/swc_css_minifier/src/compressor/rules.rs b/crates/swc_css_minifier/src/compressor/rules.rs index e7250addbab6..900def2024f0 100644 --- a/crates/swc_css_minifier/src/compressor/rules.rs +++ b/crates/swc_css_minifier/src/compressor/rules.rs @@ -58,10 +58,25 @@ impl Compressor { } } - fn get_declaration_name(&self, declaration: &Declaration) -> JsWord { - match &declaration.name { - DeclarationName::Ident(Ident { value, .. }) => value.to_ascii_lowercase(), - DeclarationName::DashedIdent(DashedIdent { value, .. }) => value.to_ascii_lowercase(), + fn is_same_declaration_name(&self, left: &Declaration, right: &Declaration) -> bool { + match (&left.name, &right.name) { + ( + DeclarationName::Ident(Ident { + value: left_value, .. + }), + DeclarationName::Ident(Ident { + value: right_value, .. + }), + ) => left_value.eq_ignore_ascii_case(right_value), + ( + DeclarationName::DashedIdent(DashedIdent { + value: left_value, .. + }), + DeclarationName::DashedIdent(DashedIdent { + value: right_value, .. + }), + ) => left_value == right_value, + _ => false, } } @@ -541,8 +556,7 @@ impl Compressor { } ComponentValue::Declaration(box declaration) if prev_rule.is_some() => { if let Some(ComponentValue::Declaration(box prev_rule)) = &mut prev_rule { - if self.get_declaration_name(prev_rule) - == self.get_declaration_name(declaration) + if self.is_same_declaration_name(prev_rule, declaration) && prev_rule.value.eq_ignore_span(&declaration.value) { remove_rules_list.push(prev_index); diff --git a/crates/swc_css_minifier/tests/fixture/compress-declaration/duplication/input.css b/crates/swc_css_minifier/tests/fixture/compress-declaration/duplication/input.css index f3e4ba205f65..1da15d685ddc 100644 --- a/crates/swc_css_minifier/tests/fixture/compress-declaration/duplication/input.css +++ b/crates/swc_css_minifier/tests/fixture/compress-declaration/duplication/input.css @@ -106,3 +106,21 @@ h1{font-weight:bold} font-weight:bold } } + +:root { + --color: red; + --color: red; + --Color: red; +} + +.class { + --color: red; + --color: red; + --Color: red; + + .nested { + --color: red; + --color: red; + --Color: red; + } +} \ No newline at end of file diff --git a/crates/swc_css_minifier/tests/fixture/compress-declaration/duplication/output.min.css b/crates/swc_css_minifier/tests/fixture/compress-declaration/duplication/output.min.css index f845eeee6f5d..02252cdc4873 100644 --- a/crates/swc_css_minifier/tests/fixture/compress-declaration/duplication/output.min.css +++ b/crates/swc_css_minifier/tests/fixture/compress-declaration/duplication/output.min.css @@ -1 +1 @@ -a{color:red;.class{color:red}@media screen and (min-width:100px){color:red}@supports(display:flex){color:red;.other{color:red}}.case-insensitivity{color:red}}.font,.class,.other{>h1{font-weight:700}}.base{color:red;.class,.class-other{color:red}@media screen{.class,.class-other{color:red}}}h1{font-weight:700}.white{_color:white;color:white}h1,h2{font-weight:700}.margin{margin:10px 0}h1{font-weight:700}@media print{h1{display:block}}.other{& h1{font-weight:700}}@media print{h1,h2{font-weight:700}} +a{color:red;.class{color:red}@media screen and (min-width:100px){color:red}@supports(display:flex){color:red;.other{color:red}}.case-insensitivity{color:red}}.font,.class,.other{>h1{font-weight:700}}.base{color:red;.class,.class-other{color:red}@media screen{.class,.class-other{color:red}}}h1{font-weight:700}.white{_color:white;color:white}h1,h2{font-weight:700}.margin{margin:10px 0}h1{font-weight:700}@media print{h1{display:block}}.other{& h1{font-weight:700}}@media print{h1,h2{font-weight:700}}:root{--color:red;--Color:red}.class{--color:red;--Color:red;.nested{--color:red;--Color:red}}