This commit is contained in:
ConnorSkees 2020-05-23 14:08:40 -04:00
parent ff2962b124
commit 5137353cb4
4 changed files with 15 additions and 21 deletions

View File

@ -1,4 +1,4 @@
use codemap::{Spanned, Span};
use codemap::{Span, Spanned};
use peekmore::{PeekMore, PeekMoreIterator};
@ -51,7 +51,7 @@ impl If {
if let Some(tok) = toks.next() {
init_toks.push(tok);
} else {
return Err(("expected \"}\".", span_before).into())
return Err(("expected \"}\".", span_before).into());
}
devour_whitespace(toks);
@ -79,7 +79,11 @@ impl If {
match tok.kind.to_ascii_lowercase() {
'i' if toks.next().unwrap().kind.to_ascii_lowercase() == 'f' => {
toks.next();
let cond = Value::from_vec(read_until_open_curly_brace(toks), scope, super_selector)?;
let cond = Value::from_vec(
read_until_open_curly_brace(toks),
scope,
super_selector,
)?;
toks.next();
devour_whitespace(toks);
branches.push(Branch::new(cond, read_until_closing_curly_brace(toks)));

View File

@ -14,7 +14,7 @@ use super::css_function::{eat_calc_args, eat_progid, try_eat_url};
use crate::args::eat_call_args;
use crate::builtin::GLOBAL_FUNCTIONS;
use crate::color::{Color, NAMED_COLORS};
use crate::common::{Brackets, ListSeparator, Op, QuoteKind, Identifier};
use crate::common::{Brackets, Identifier, ListSeparator, Op, QuoteKind};
use crate::error::SassResult;
use crate::scope::Scope;
use crate::selector::Selector;
@ -839,7 +839,7 @@ impl Value {
}
q @ '>' | q @ '<' => {
let mut span = toks.next().unwrap().pos();
IntermediateValue::Op(if let Some(Token { kind: '=', ..}) = toks.peek() {
IntermediateValue::Op(if let Some(Token { kind: '=', .. }) = toks.peek() {
span = span.merge(toks.next().unwrap().pos());
match q {
'>' => Op::GreaterThanEqual,
@ -899,7 +899,7 @@ impl Value {
IntermediateValue::Whitespace.span(span)
}
Some(..) => IntermediateValue::Op(Op::Div).span(span),
None => return Some(Err(("Expected expression.", span).into()))
None => return Some(Err(("Expected expression.", span).into())),
}
}
';' | '}' | '{' => return None,

View File

@ -108,23 +108,13 @@ test!(
"@if false {}\n\n@\\45lse {\n a {\n color: red;\n }\n}\n",
"a {\n color: red;\n}\n"
);
error!(
nothing_after_if,
"@if",
"Error: Expected expression."
);
error!(
no_condition,
"@if{}",
"Error: Expected expression."
);
error!(nothing_after_if, "@if", "Error: Expected expression.");
error!(no_condition, "@if{}", "Error: Expected expression.");
error!(
nothing_after_open_curly,
"@if foo {",
"Error: expected \"}\"."
"@if foo {", "Error: expected \"}\"."
);
error!(
condition_is_evaluated_eagerly,
"@if 1 + 1 =s {\n}",
"Error: expected \"=\"."
"@if 1 + 1 =s {\n}", "Error: expected \"=\"."
);