From d3413b7cbf6001d6a08bd87af6af7a658d6febce Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Wed, 17 Jun 2020 02:35:35 -0400 Subject: [PATCH] `&` is `null` when at root --- src/parse/value.rs | 8 ++++++-- tests/selectors.rs | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-) 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\"."