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}; use peekmore::{PeekMore, PeekMoreIterator};
@ -51,7 +51,7 @@ impl If {
if let Some(tok) = toks.next() { if let Some(tok) = toks.next() {
init_toks.push(tok); init_toks.push(tok);
} else { } else {
return Err(("expected \"}\".", span_before).into()) return Err(("expected \"}\".", span_before).into());
} }
devour_whitespace(toks); devour_whitespace(toks);
@ -79,7 +79,11 @@ impl If {
match tok.kind.to_ascii_lowercase() { match tok.kind.to_ascii_lowercase() {
'i' if toks.next().unwrap().kind.to_ascii_lowercase() == 'f' => { 'i' if toks.next().unwrap().kind.to_ascii_lowercase() == 'f' => {
toks.next(); 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(); toks.next();
devour_whitespace(toks); devour_whitespace(toks);
branches.push(Branch::new(cond, read_until_closing_curly_brace(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::args::eat_call_args;
use crate::builtin::GLOBAL_FUNCTIONS; use crate::builtin::GLOBAL_FUNCTIONS;
use crate::color::{Color, NAMED_COLORS}; 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::error::SassResult;
use crate::scope::Scope; use crate::scope::Scope;
use crate::selector::Selector; use crate::selector::Selector;
@ -839,7 +839,7 @@ impl Value {
} }
q @ '>' | q @ '<' => { q @ '>' | q @ '<' => {
let mut span = toks.next().unwrap().pos(); 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()); span = span.merge(toks.next().unwrap().pos());
match q { match q {
'>' => Op::GreaterThanEqual, '>' => Op::GreaterThanEqual,
@ -899,7 +899,7 @@ impl Value {
IntermediateValue::Whitespace.span(span) IntermediateValue::Whitespace.span(span)
} }
Some(..) => IntermediateValue::Op(Op::Div).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, ';' | '}' | '{' => return None,

View File

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