diff --git a/src/parse/value.rs b/src/parse/value.rs index 5b7ae5d..ed9bf1f 100644 --- a/src/parse/value.rs +++ b/src/parse/value.rs @@ -372,8 +372,12 @@ impl<'a> Parser<'a> { } '&' => { let span = self.toks.next().unwrap().pos(); - IntermediateValue::Value(self.super_selectors.last().clone().into_value()) - .span(span) + if self.super_selectors.is_empty() { + IntermediateValue::Value(Value::Null).span(span) + } else { + IntermediateValue::Value(self.super_selectors.last().clone().into_value()) + .span(span) + } } '#' => { if let Some(Token { kind: '{', pos }) = self.toks.peek_forward(1) { diff --git a/tests/selectors.rs b/tests/selectors.rs index 2e8731d..a9412c8 100644 --- a/tests/selectors.rs +++ b/tests/selectors.rs @@ -653,6 +653,11 @@ test!( ":nth-child(ODD) {\n color: &;\n}\n", ":nth-child(odd) {\n color: :nth-child(odd);\n}\n" ); +test!( + super_selector_is_null_when_at_root, + "@mixin foo {\n #{if(&, 'true', 'false')} {\n color: red;\n }\n}\n\n@include foo;\n\na {\n @include foo;\n}\n", + "false {\n color: red;\n}\n\na true {\n color: red;\n}\n" +); error!( a_n_plus_b_n_invalid_odd, ":nth-child(ofdd) {\n color: &;\n}\n", "Error: Expected \"odd\"."