Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,11 @@ impl<'i, 'o> PropertyHandlerContext<'i, 'o> {
self.rtl.clear();
self.dark.clear();
}

pub fn merge(&mut self, other: Self) {
self.supports.extend(other.supports);
self.ltr.extend(other.ltr);
self.rtl.extend(other.rtl);
self.dark.extend(other.dark);
}
}
35 changes: 35 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30379,4 +30379,39 @@ mod tests {
},
);
}

#[test]
fn test_nested_declarations_logical_properties() {
nesting_test(
r#"
.foo {
:where(&) { width: unset; }
border-start-start-radius: 10px;
}
"#,
indoc! {r#"
:where(.foo) {
width: unset;
}

.foo {
border-start-start-radius: 10px;
}
"#},
);

prefix_test(
r#"
.foo {
:where(&) { width: unset; }
border-start-start-radius: 10px;
}
"#,
".foo:not(:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {\n border-top-left-radius: 10px;\n}\n\n.foo:not(:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi))) {\n border-top-left-radius: 10px;\n}\n\n.foo:-webkit-any(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {\n border-top-right-radius: 10px;\n}\n\n.foo:is(:lang(ae), :lang(ar), :lang(arc), :lang(bcc), :lang(bqi), :lang(ckb), :lang(dv), :lang(fa), :lang(glk), :lang(he), :lang(ku), :lang(mzn), :lang(nqo), :lang(pnb), :lang(ps), :lang(sd), :lang(ug), :lang(ur), :lang(yi)) {\n border-top-right-radius: 10px;\n}\n\n:where(.foo) {\n width: unset;\n}\n\n\n",
Browsers {
chrome: Some(70 << 16),
..Browsers::default()
},
);
}
}
5 changes: 4 additions & 1 deletion src/rules/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ impl<'i, T: Clone> StyleRule<'i, T> {
let mut handler_context = context.handler_context.child(DeclarationContext::StyleRule);
std::mem::swap(&mut context.handler_context, &mut handler_context);
self.rules.minify(context, unused)?;
context.handler_context = handler_context;
// Merge any logical/conditional rules from nested declarations back into the parent context.
// These will be collected by the caller when generating additional rules for this style rule.
let child_context = std::mem::replace(&mut context.handler_context, handler_context);
context.handler_context.merge(child_context);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have thought that when the nested rules get minified, the child context would get reset after the additional rules are generated. Seems like somehow that's not happening in this case?

Seems like the issue only occurs when the nested rules are before declarations, not after. This may have been caused when the spec got updated to allow intermixing rules and declarations (initially nested rules had to be after declarations). Now there is a hidden NestedDeclarations rule for these interleaved declarations. Maybe that case needs to be updated to work similarly to StyleRule (inserting additional rules after)? Otherwise what happens if you have nested rules followed by declarations followed by more rules? I guess the order of where those additional rules for logical properties get inserted might be important (right now they might all get pushed to the end)?

if unused && self.rules.0.is_empty() {
return Ok(true);
}
Expand Down
Loading