& is null when at root

This commit is contained in:
ConnorSkees 2020-06-17 02:35:35 -04:00
parent 86c1bb704d
commit d3413b7cbf
2 changed files with 11 additions and 2 deletions

View File

@ -372,9 +372,13 @@ impl<'a> Parser<'a> {
}
'&' => {
let span = self.toks.next().unwrap().pos();
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) {
self.span_before = *pos;

View File

@ -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\"."