implement short circuiting for and
This commit is contained in:
parent
218d73c982
commit
52bf3f0091
@ -895,11 +895,26 @@ impl<'a, 'b: 'a> IntermediateValueIterator<'a, 'b> {
|
|||||||
.push(Value::String(op.to_string(), QuoteKind::None).span(op.span));
|
.push(Value::String(op.to_string(), QuoteKind::None).span(op.span));
|
||||||
} else if let Some(left) = space_separated.pop() {
|
} else if let Some(left) = space_separated.pop() {
|
||||||
self.whitespace();
|
self.whitespace();
|
||||||
|
if left.node.is_true(left.span)? {
|
||||||
let right = self.single_value()?;
|
let right = self.single_value()?;
|
||||||
space_separated.push(
|
space_separated.push(
|
||||||
Value::BinaryOp(Box::new(left.node), op.node, Box::new(right.node))
|
Value::BinaryOp(Box::new(left.node), op.node, Box::new(right.node))
|
||||||
.span(left.span.merge(right.span)),
|
.span(left.span.merge(right.span)),
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
// we explicitly ignore errors here as a workaround for short circuiting
|
||||||
|
while let Some(value) = self.peek() {
|
||||||
|
if let Ok(Spanned {
|
||||||
|
node: IntermediateValue::Comma,
|
||||||
|
..
|
||||||
|
}) = value
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
self.next();
|
||||||
|
}
|
||||||
|
space_separated.push(left);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return Err(("Expected expression.", op.span).into());
|
return Err(("Expected expression.", op.span).into());
|
||||||
}
|
}
|
||||||
|
@ -51,3 +51,8 @@ test!(
|
|||||||
"a {\n color: 1 - AND;\n}\n",
|
"a {\n color: 1 - AND;\n}\n",
|
||||||
"a {\n color: 1-AND;\n}\n"
|
"a {\n color: 1-AND;\n}\n"
|
||||||
);
|
);
|
||||||
|
test!(
|
||||||
|
short_circuits_when_lhs_is_false,
|
||||||
|
"a {\n color: false and comparable(\"a\", \"b\");\n}\n",
|
||||||
|
"a {\n color: false;\n}\n"
|
||||||
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user