Skip to content

Commit

Permalink
Ensure incompatible rules get the correct vendor prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
devongovett committed Jun 17, 2023
1 parent 8d94ea1 commit d6e1295
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
28 changes: 28 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9631,6 +9631,34 @@ mod tests {
..Browsers::default()
},
);

prefix_test(
r#"
*,
::before,
::after,
::backdrop {
padding: 5px;
}
"#,
indoc! {r#"
*, :before, :after {
padding: 5px;
}

::-webkit-backdrop {
padding: 5px;
}

::backdrop {
padding: 5px;
}
"#},
Browsers {
safari: Some(14 << 16),
..Browsers::default()
},
);
}

#[test]
Expand Down
3 changes: 3 additions & 0 deletions src/rules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,8 @@ impl<'i, T: Clone> CssRuleList<'i, T> {
smallvec![]
};

style.update_prefix(context);

// Attempt to merge the new rule with the last rule we added.
let mut merged = false;
if let Some(CssRule::Style(last_style_rule)) = rules.last_mut() {
Expand Down Expand Up @@ -659,6 +661,7 @@ impl<'i, T: Clone> CssRuleList<'i, T> {
let list = SelectorList::new(smallvec![selector]);
let mut clone = style.clone();
clone.selectors = list;
clone.update_prefix(context);

// Also add rules for logical properties and @supports overrides.
let supports = context.handler_context.get_supports_rules(&clone);
Expand Down
12 changes: 7 additions & 5 deletions src/rules/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,6 @@ impl<'i, T: Clone> StyleRule<'i, T> {
}
}

self.vendor_prefix = get_prefix(&self.selectors);
if self.vendor_prefix.contains(VendorPrefix::None) && context.targets.should_compile_selectors() {
self.vendor_prefix = downlevel_selectors(self.selectors.0.as_mut_slice(), *context.targets);
}

Ok(false)
}
}
Expand Down Expand Up @@ -158,6 +153,13 @@ impl<'i, T> StyleRule<'i, T> {
.zip(other_rule.declarations.iter())
.all(|((a, _), (b, _))| a.property_id() == b.property_id())
}

pub(crate) fn update_prefix(&mut self, context: &mut MinifyContext<'_, 'i>) {
self.vendor_prefix = get_prefix(&self.selectors);
if self.vendor_prefix.contains(VendorPrefix::None) && context.targets.should_compile_selectors() {
self.vendor_prefix = downlevel_selectors(self.selectors.0.as_mut_slice(), *context.targets);
}
}
}

fn parse_at<'i, 't, T, F>(
Expand Down

0 comments on commit d6e1295

Please sign in to comment.