somewhat handle unary div

This commit is contained in:
ConnorSkees 2020-04-20 02:32:46 -04:00
parent f8540755f5
commit c521e0a835
2 changed files with 35 additions and 0 deletions

View File

@ -204,6 +204,25 @@ fn eat_op<I: Iterator<Item = IntermediateValue>>(
span: right.span, span: right.span,
}); });
} }
Op::Div => {
devour_whitespace(iter);
let right = single_value(iter, scope, super_selector, op.span)?;
if let Some(left) = space_separated.pop() {
space_separated.push(Spanned {
node: Value::BinaryOp(Box::new(left.node), op.node, Box::new(right.node)),
span: left.span.merge(right.span),
});
} else {
devour_whitespace(iter);
space_separated.push(Spanned {
node: Value::Ident(
format!("/{}", right.node.to_css_string(right.span)?),
QuoteKind::None,
),
span: op.span.merge(right.span),
});
}
}
Op::Plus => { Op::Plus => {
if let Some(left) = space_separated.pop() { if let Some(left) = space_separated.pop() {
devour_whitespace(iter); devour_whitespace(iter);
@ -309,6 +328,17 @@ fn single_value<I: Iterator<Item = IntermediateValue>>(
devour_whitespace(iter); devour_whitespace(iter);
single_value(iter, scope, super_selector, span)? single_value(iter, scope, super_selector, span)?
} }
Op::Div => {
devour_whitespace(iter);
let val = single_value(iter, scope, super_selector, span)?;
Spanned {
node: Value::Ident(
format!("/{}", val.node.to_css_string(val.span)?),
QuoteKind::None,
),
span: op.span.merge(val.span),
}
}
_ => todo!(), _ => todo!(),
}, },
IntermediateValue::Whitespace => unreachable!(), IntermediateValue::Whitespace => unreachable!(),

View File

@ -23,6 +23,11 @@ test!(
"a {\n color: (35px / 7in);\n}\n", "a {\n color: (35px / 7in);\n}\n",
"a {\n color: 0.0520833333;\n}\n" "a {\n color: 0.0520833333;\n}\n"
); );
test!(
slash_after_comma,
"a {\n slash-after-comma: (1, / 2);\n}\n",
"a {\n slash-after-comma: 1, /2;\n}\n"
);
// error!( // error!(
// none_div_unit, // none_div_unit,
// "a {\n color: (35 / 7%);\n}\n", // "a {\n color: (35 / 7%);\n}\n",