diff --git a/src/parse/common.rs b/src/parse/common.rs index 7417261..ac885c5 100644 --- a/src/parse/common.rs +++ b/src/parse/common.rs @@ -77,7 +77,6 @@ impl ContextFlags { (self.0 & Self::IN_KEYFRAMES) != 0 } - #[allow(dead_code)] pub fn in_at_root_rule(self) -> bool { (self.0 & Self::IN_AT_ROOT_RULE) != 0 } diff --git a/src/parse/value/parse.rs b/src/parse/value/parse.rs index bc9e2b1..47ee279 100644 --- a/src/parse/value/parse.rs +++ b/src/parse/value/parse.rs @@ -778,7 +778,10 @@ impl<'a> Parser<'a> { } '&' => { let span = self.toks.next().unwrap().pos(); - if self.super_selectors.is_empty() && !self.at_root_has_selector && !self.at_root { + if self.super_selectors.is_empty() + && !self.at_root_has_selector + && !self.flags.in_at_root_rule() + { IntermediateValue::Value(HigherIntermediateValue::Literal(Value::Null)) .span(span) } else { diff --git a/tests/if.rs b/tests/if.rs index e805d6e..d4af0ea 100644 --- a/tests/if.rs +++ b/tests/if.rs @@ -171,6 +171,15 @@ test!( /**/ ", "/**/\n/**/\n/**/\n" ); +test!( + parent_selector_is_null_at_root, + "@if & { + a { + color: red; + } + }", + "" +); error!( nothing_after_escape, "@if \\", "Error: Expected expression." diff --git a/tests/selectors.rs b/tests/selectors.rs index 5579cf0..9cebfa6 100644 --- a/tests/selectors.rs +++ b/tests/selectors.rs @@ -676,6 +676,11 @@ test!( ":a(a , b) {\n color: &;\n}\n", ":a(a , b) {\n color: :a(a , b);\n}\n" ); +test!( + parent_selector_is_null_at_root, + "#{inspect(&)} {\n color: &;\n}\n", + "null {\n color: null;\n}\n" +); error!( a_n_plus_b_n_invalid_odd, ":nth-child(ofdd) {\n color: &;\n}\n", "Error: Expected \"odd\"."