more robustly parse default function arguments

This commit is contained in:
Connor Skees 2020-08-08 01:57:56 -04:00
parent a3a21928c0
commit a9bef0e24e
2 changed files with 36 additions and 1 deletions

View File

@ -7,7 +7,10 @@ use crate::{
common::QuoteKind, common::QuoteKind,
error::SassResult, error::SassResult,
scope::Scope, 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, value::Value,
Token, Token,
}; };
@ -67,6 +70,27 @@ impl<'a> Parser<'a> {
default.push(self.toks.next().unwrap()); default.push(self.toks.next().unwrap());
default.extend(read_until_closing_paren(self.toks)?); 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()), _ => default.push(self.toks.next().unwrap()),
} }
} }

View File

@ -187,3 +187,14 @@ test!(
}", }",
"a {\n color: kwd-y;\n}\n" "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"
);