From 3757c39c6f178de72010da422dc19b28ca6e4650 Mon Sep 17 00:00:00 2001 From: Connor Skees Date: Sat, 25 Jul 2020 14:10:57 -0400 Subject: [PATCH] resolve panic from the input `foo($--)` --- src/parse/args.rs | 21 ++++++++------------- tests/args.rs | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/parse/args.rs b/src/parse/args.rs index 5664882..14451db 100644 --- a/src/parse/args.rs +++ b/src/parse/args.rs @@ -6,7 +6,10 @@ use crate::{ args::{CallArg, CallArgs, FuncArg, FuncArgs}, error::SassResult, scope::Scope, - utils::{read_until_closing_paren, read_until_closing_quote, read_until_closing_square_brace}, + utils::{ + peek_ident_no_interpolation, read_until_closing_paren, read_until_closing_quote, + read_until_closing_square_brace, + }, value::Value, Token, }; @@ -139,23 +142,15 @@ impl<'a> Parser<'a> { Some(Token { kind: '$', pos }) => { span = span.merge(pos); self.toks.next(); - let v = self.parse_identifier_no_interpolation(false)?; - let whitespace = self.whitespace_or_comment(); + let v = peek_ident_no_interpolation(self.toks, false, self.span_before)?; + if let Some(Token { kind: ':', .. }) = self.toks.peek() { + self.toks.truncate_iterator_to_cursor(); self.toks.next(); name = v.node; } else { val.push(Token::new(pos, '$')); - let mut current_pos = 0; - val.extend(v.chars().map(|x| { - let len = x.len_utf8() as u64; - let tok = Token::new(v.span.subspan(current_pos, current_pos + len), x); - current_pos += len; - tok - })); - if whitespace { - val.push(Token::new(pos, ' ')); - } + self.toks.reset_cursor(); name.clear(); } } diff --git a/tests/args.rs b/tests/args.rs index 003b72f..0afd994 100644 --- a/tests/args.rs +++ b/tests/args.rs @@ -64,3 +64,25 @@ error!( "@function foo($a) {\n @return foo;\n}\n\na {\n color: foo(unit(bar));\n}\n", "Error: $number: bar is not a number." ); +test!( + variable_is_only_hyphens, + "$--: red; + + a { + color: foo($--); + }", + "a {\n color: foo(red);\n}\n" +); +test!( + no_space_after_colon_in_keyword_arg, + "@function foo($a) { + @return $a; + } + + $b: red; + + a { + color: foo($a:$b); + }", + "a {\n color: red;\n}\n" +);