Skip to content

Commit

Permalink
dedupe @Property rules
Browse files Browse the repository at this point in the history
fixes #656
  • Loading branch information
devongovett committed Jan 14, 2024
1 parent f4d4413 commit 51c7c05
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/lib.rs
Expand Up @@ -26105,6 +26105,24 @@ mod tests {
"#,
"@property --property-name{syntax:\"<color>+\";inherits:false;initial-value:#ff0 #00f}",
);
minify_test(
r#"
@property --property-name {
syntax: '<color>';
inherits: false;
initial-value: yellow;
}
.foo {
color: var(--property-name)
}
@property --property-name {
syntax: '<color>';
inherits: true;
initial-value: blue;
}
"#,
"@property --property-name{syntax:\"<color>\";inherits:true;initial-value:#00f}.foo{color:var(--property-name)}",
);
}

#[test]
Expand Down
8 changes: 8 additions & 0 deletions src/rules/mod.rs
Expand Up @@ -498,6 +498,7 @@ impl<'i, T: Clone> CssRuleList<'i, T> {
) -> Result<(), MinifyError> {
let mut keyframe_rules = HashMap::new();
let mut layer_rules = HashMap::new();
let mut property_rules = HashMap::new();
let mut style_rules =
HashMap::with_capacity_and_hasher(self.0.len(), BuildHasherDefault::<PrecomputedHasher>::default());
let mut rules = Vec::new();
Expand Down Expand Up @@ -810,6 +811,13 @@ impl<'i, T: Clone> CssRuleList<'i, T> {
if context.unused_symbols.contains(property.name.0.as_ref()) {
continue;
}

if let Some(index) = property_rules.get_mut(&property.name) {
rules[*index] = rule;
continue;
} else {
property_rules.insert(property.name.clone(), rules.len());
}
}
_ => {}
}
Expand Down

0 comments on commit 51c7c05

Please sign in to comment.