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

View File

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