From 71495cd03bf7aa3816cbaa16d1f14538cb93b475 Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Thu, 23 Apr 2020 13:54:49 -0400 Subject: [PATCH] do not strip whitespace after var in call args --- src/args.rs | 13 +++++++------ src/value/parse.rs | 19 +++++-------------- tests/args.rs | 5 +++++ 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/args.rs b/src/args.rs index 2a0e98e..33d9392 100644 --- a/src/args.rs +++ b/src/args.rs @@ -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>( pub(crate) fn eat_call_args>( toks: &mut PeekMoreIterator, - scope: &Scope, - super_selector: &Selector, ) -> SassResult { let mut args: HashMap> = HashMap::new(); devour_whitespace_or_comment(toks)?; @@ -310,8 +308,8 @@ pub(crate) fn eat_call_args>( 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>( current_pos += len; tok })); + if whitespace { + val.push(Token::new(pos, ' ')); + } name.clear(); } } diff --git a/src/value/parse.rs b/src/value/parse.rs index 41fafc6..0aa1bc6 100644 --- a/src/value/parse.rs +++ b/src/value/parse.rs @@ -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), )) } _ => { diff --git a/tests/args.rs b/tests/args.rs index ca19d43..5923f89 100644 --- a/tests/args.rs +++ b/tests/args.rs @@ -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" +);