handle -(null) and -null

This commit is contained in:
ConnorSkees 2020-04-18 20:45:40 -04:00
parent 305581ad75
commit 71546d7fc4
2 changed files with 14 additions and 8 deletions

View File

@ -229,17 +229,17 @@ fn eat_op<I: Iterator<Item = IntermediateValue>>(
span: left.span.merge(right.span), span: left.span.merge(right.span),
}); });
} else { } else {
space_separated.push(Spanned { space_separated.push(right.map_node(|n| Value::UnaryOp(op.node, Box::new(n))));
node: Value::UnaryOp(op.node, Box::new(right.node)),
span: right.span,
});
} }
} else { } else {
let right = single_value(iter, scope, super_selector, op.span)?; let right = single_value(iter, scope, super_selector, op.span)?;
space_separated.push(Spanned { if right.node == Value::Null {
node: Value::UnaryOp(op.node, Box::new(right.node)), space_separated.push(
span: right.span, right.map_node(|_| Value::Ident("-null".to_string(), QuoteKind::None)),
}); );
return Ok(());
}
space_separated.push(right.map_node(|n| Value::UnaryOp(op.node, Box::new(n))));
} }
} }
Op::And | Op::Or => { Op::And | Op::Or => {

View File

@ -50,3 +50,9 @@ test!(
"$a: 1;\n\na {\n color: -$a;\n}\n", "$a: 1;\n\na {\n color: -$a;\n}\n",
"a {\n color: -1;\n}\n" "a {\n color: -1;\n}\n"
); );
test!(
unary_neg_null_paren,
"a {\n color: -(null);\n}\n",
"a {\n color: -;\n}\n"
);
test!(negative_null_as_ident, "a {\n color: -null;\n}\n");