resolve panic from the input foo($--)
This commit is contained in:
parent
f2cd74528b
commit
3757c39c6f
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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"
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user