do not strip whitespace after var in call args

This commit is contained in:
ConnorSkees 2020-04-23 13:54:49 -04:00
parent c921a54edf
commit 71495cd03b
3 changed files with 17 additions and 20 deletions

View File

@ -8,8 +8,8 @@ use crate::error::SassResult;
use crate::scope::Scope;
use crate::selector::Selector;
use crate::utils::{
devour_whitespace, devour_whitespace_or_comment, eat_ident, read_until_closing_paren,
read_until_closing_quote, read_until_closing_square_brace,
devour_whitespace, devour_whitespace_or_comment, eat_ident, eat_ident_no_interpolation,
read_until_closing_paren, read_until_closing_quote, read_until_closing_square_brace,
};
use crate::value::Value;
use crate::Token;
@ -298,8 +298,6 @@ pub(crate) fn eat_func_args<I: Iterator<Item = Token>>(
pub(crate) fn eat_call_args<I: Iterator<Item = Token>>(
toks: &mut PeekMoreIterator<I>,
scope: &Scope,
super_selector: &Selector,
) -> SassResult<CallArgs> {
let mut args: HashMap<CallArg, Vec<Token>> = HashMap::new();
devour_whitespace_or_comment(toks)?;
@ -310,8 +308,8 @@ pub(crate) fn eat_call_args<I: Iterator<Item = Token>>(
match toks.peek().unwrap().kind {
'$' => {
let Token { pos, .. } = toks.next().unwrap();
let v = eat_ident(toks, scope, super_selector)?;
devour_whitespace_or_comment(toks)?;
let v = eat_ident_no_interpolation(toks, false)?;
let whitespace = devour_whitespace_or_comment(toks)?;
if toks.peek().unwrap().kind == ':' {
toks.next();
name = v.node;
@ -324,6 +322,9 @@ pub(crate) fn eat_call_args<I: Iterator<Item = Token>>(
current_pos += len;
tok
}));
if whitespace {
val.push(Token::new(pos, ' '));
}
name.clear();
}
}

View File

@ -523,11 +523,7 @@ impl Value {
Err(_) => match GLOBAL_FUNCTIONS.get(&s.replace('_', "-")) {
Some(f) => {
return Ok(IntermediateValue::Value(Spanned {
node: f.0(
eat_call_args(toks, scope, super_selector)?,
scope,
super_selector,
)?,
node: f.0(eat_call_args(toks)?, scope, super_selector)?,
span,
}))
}
@ -541,13 +537,12 @@ impl Value {
"url" => match try_eat_url(toks, scope, super_selector)? {
Some(val) => s = val,
None => s.push_str(
&eat_call_args(toks, scope, super_selector)?
&eat_call_args(toks)?
.to_css_string(scope, super_selector)?,
),
},
_ => s.push_str(
&eat_call_args(toks, scope, super_selector)?
.to_css_string(scope, super_selector)?,
&eat_call_args(toks)?.to_css_string(scope, super_selector)?,
),
}
return Ok(IntermediateValue::Value(Spanned {
@ -558,12 +553,8 @@ impl Value {
},
};
Ok(IntermediateValue::Value(
func.eval(
eat_call_args(toks, scope, super_selector)?,
scope,
super_selector,
)?
.span(span),
func.eval(eat_call_args(toks)?, scope, super_selector)?
.span(span),
))
}
_ => {

View File

@ -30,3 +30,8 @@ test!(
"$da: a;\n\n@mixin foo($x: $da) {\n color: $x;\n}\n$da: b;\n\na {\n @include foo();\n}\n",
"a {\n color: b;\n}\n"
);
test!(
variable_being_subtracted,
"$index: 1;\n\n@function foo($a) {\n @return $a;\n}\n\na {\n color: foo($index - 1);\n}\n",
"a {\n color: 0;\n}\n"
);