Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(css/minifier): do not remove custom variables with different case #6655

Merged
merged 4 commits into from Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 20 additions & 6 deletions crates/swc_css_minifier/src/compressor/rules.rs
Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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);
Expand Down
Expand Up @@ -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;
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.