emit proper error for map as rhs of addition

This commit is contained in:
ConnorSkees 2020-05-22 20:47:53 -04:00
parent 80e32b4290
commit 7261f57e01
3 changed files with 21 additions and 17 deletions

View File

@ -110,7 +110,7 @@ fn visit_quoted_string(buf: &mut String, force_double_quote: bool, string: &str)
impl Value { impl Value {
pub fn is_null(&self, span: Span) -> SassResult<bool> { pub fn is_null(&self, span: Span) -> SassResult<bool> {
Ok(match self { Ok(match self {
&Value::Null => true, Value::Null => true,
Value::String(i, QuoteKind::None) if i.is_empty() => true, Value::String(i, QuoteKind::None) if i.is_empty() => true,
Self::BinaryOp(..) | Self::Paren(..) | Self::UnaryOp(..) => { Self::BinaryOp(..) | Self::Paren(..) | Self::UnaryOp(..) => {
self.clone().eval(span)?.is_null(span)? self.clone().eval(span)?.is_null(span)?

View File

@ -181,12 +181,9 @@ fn parse_paren(
t: Spanned<Vec<Token>>, t: Spanned<Vec<Token>>,
scope: &Scope, scope: &Scope,
super_selector: &Selector, super_selector: &Selector,
space_separated: &mut Vec<Spanned<Value>>, ) -> SassResult<Spanned<Value>> {
) -> SassResult<()> {
if t.is_empty() { if t.is_empty() {
space_separated return Ok(Value::List(Vec::new(), ListSeparator::Space, Brackets::None).span(t.span));
.push(Value::List(Vec::new(), ListSeparator::Space, Brackets::None).span(t.span));
return Ok(());
} }
let paren_toks = &mut t.node.into_iter().peekmore(); let paren_toks = &mut t.node.into_iter().peekmore();
@ -195,11 +192,10 @@ fn parse_paren(
let key = Value::from_vec(read_until_char(paren_toks, ':'), scope, super_selector)?; let key = Value::from_vec(read_until_char(paren_toks, ':'), scope, super_selector)?;
if paren_toks.peek().is_none() { if paren_toks.peek().is_none() {
space_separated.push(Spanned { return Ok(Spanned {
node: Value::Paren(Box::new(key.node)), node: Value::Paren(Box::new(key.node)),
span: key.span, span: key.span,
}); });
return Ok(());
} }
let val = Value::from_vec(read_until_char(paren_toks, ','), scope, super_selector)?; let val = Value::from_vec(read_until_char(paren_toks, ','), scope, super_selector)?;
@ -207,11 +203,10 @@ fn parse_paren(
map.insert(key.node, val.node); map.insert(key.node, val.node);
if paren_toks.peek().is_none() { if paren_toks.peek().is_none() {
space_separated.push(Spanned { return Ok(Spanned {
node: Value::Map(map), node: Value::Map(map),
span: key.span.merge(val.span), span: key.span.merge(val.span),
}); });
return Ok(());
} }
let mut span = key.span; let mut span = key.span;
@ -229,11 +224,10 @@ fn parse_paren(
break; break;
} }
} }
space_separated.push(Spanned { Ok(Spanned {
node: Value::Map(map), node: Value::Map(map),
span, span,
}); })
Ok(())
} }
fn eat_op<I: Iterator<Item = Token>>( fn eat_op<I: Iterator<Item = Token>>(
@ -401,7 +395,14 @@ fn single_value<I: Iterator<Item = Token>>(
.span(v.span) .span(v.span)
} }
IntermediateValue::Paren(t) => { IntermediateValue::Paren(t) => {
let val = Value::from_vec(t, scope, super_selector)?; let val = parse_paren(
Spanned {
node: t,
span: next.span,
},
scope,
super_selector,
)?;
Spanned { Spanned {
node: Value::Paren(Box::new(val.node)), node: Value::Paren(Box::new(val.node)),
span: val.span, span: val.span,
@ -499,15 +500,14 @@ impl Value {
} }
IntermediateValue::Paren(t) => { IntermediateValue::Paren(t) => {
last_was_whitespace = false; last_was_whitespace = false;
parse_paren( space_separated.push(parse_paren(
Spanned { Spanned {
node: t, node: t,
span: val.span, span: val.span,
}, },
scope, scope,
super_selector, super_selector,
&mut space_separated, )?);
)?;
} }
} }
} }

View File

@ -171,3 +171,7 @@ error!(
map_lhs_add, map_lhs_add,
"a {color: (a: b) + 1;}", "Error: (a: b) isn't a valid CSS value." "a {color: (a: b) + 1;}", "Error: (a: b) isn't a valid CSS value."
); );
error!(
map_rhs_add,
"a {color: 1 + (a: b);}", "Error: (a: b) isn't a valid CSS value."
);