more robustly parse default function arguments
This commit is contained in:
parent
a3a21928c0
commit
a9bef0e24e
@ -7,7 +7,10 @@ use crate::{
|
||||
common::QuoteKind,
|
||||
error::SassResult,
|
||||
scope::Scope,
|
||||
utils::{peek_ident_no_interpolation, peek_whitespace_or_comment, read_until_closing_paren},
|
||||
utils::{
|
||||
peek_ident_no_interpolation, peek_whitespace_or_comment, read_until_closing_paren,
|
||||
read_until_closing_quote, read_until_newline,
|
||||
},
|
||||
value::Value,
|
||||
Token,
|
||||
};
|
||||
@ -67,6 +70,27 @@ impl<'a> Parser<'a> {
|
||||
default.push(self.toks.next().unwrap());
|
||||
default.extend(read_until_closing_paren(self.toks)?);
|
||||
}
|
||||
'/' => {
|
||||
let next = self.toks.next().unwrap();
|
||||
match self.toks.peek() {
|
||||
Some(Token { kind: '/', .. }) => read_until_newline(self.toks),
|
||||
_ => default.push(next),
|
||||
};
|
||||
continue;
|
||||
}
|
||||
q @ '"' | q @ '\'' => {
|
||||
let q = *q;
|
||||
default.push(self.toks.next().unwrap());
|
||||
default.extend(read_until_closing_quote(self.toks, q)?);
|
||||
continue;
|
||||
}
|
||||
'\\' => {
|
||||
default.push(self.toks.next().unwrap());
|
||||
default.push(match self.toks.next() {
|
||||
Some(tok) => tok,
|
||||
None => continue,
|
||||
});
|
||||
}
|
||||
_ => default.push(self.toks.next().unwrap()),
|
||||
}
|
||||
}
|
||||
|
@ -187,3 +187,14 @@ test!(
|
||||
}",
|
||||
"a {\n color: kwd-y;\n}\n"
|
||||
);
|
||||
test!(
|
||||
quoted_string_as_default_argument_value,
|
||||
r#"@function foo($font-family: 'Roboto, "Helvetica Neue", sans-serif') {
|
||||
@return $font-family;
|
||||
}
|
||||
|
||||
a {
|
||||
color: foo();
|
||||
}"#,
|
||||
"a {\n color: 'Roboto, \"Helvetica Neue\", sans-serif';\n}\n"
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user