better handle silent comments in maps and fn args
This commit is contained in:
parent
dee6699bde
commit
f69b863e33
@ -48,6 +48,7 @@ impl<'a> Parser<'a> {
|
|||||||
match &tok.kind {
|
match &tok.kind {
|
||||||
',' => {
|
',' => {
|
||||||
self.toks.next();
|
self.toks.next();
|
||||||
|
self.whitespace_or_comment();
|
||||||
args.push(FuncArg {
|
args.push(FuncArg {
|
||||||
name: name.node.into(),
|
name: name.node.into(),
|
||||||
default: Some(default),
|
default: Some(default),
|
||||||
|
@ -1062,9 +1062,16 @@ impl<'a, 'b: 'a> IntermediateValueIterator<'a, 'b> {
|
|||||||
let paren_toks = &mut t.node.into_iter().peekmore();
|
let paren_toks = &mut t.node.into_iter().peekmore();
|
||||||
|
|
||||||
let mut map = SassMap::new();
|
let mut map = SassMap::new();
|
||||||
let key = self
|
let key_toks = read_until_char(paren_toks, ':')?;
|
||||||
.parser
|
if key_toks.iter().all(|t| t.is_whitespace()) {
|
||||||
.parse_value_from_vec(read_until_char(paren_toks, ':')?, true)?;
|
return Ok(Spanned {
|
||||||
|
node: HigherIntermediateValue::Paren(Box::new(HigherIntermediateValue::Literal(
|
||||||
|
Value::Map(map),
|
||||||
|
))),
|
||||||
|
span: t.span,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
let key = self.parser.parse_value_from_vec(key_toks, true)?;
|
||||||
|
|
||||||
if paren_toks.peek().is_none() {
|
if paren_toks.peek().is_none() {
|
||||||
return Ok(Spanned {
|
return Ok(Spanned {
|
||||||
@ -1096,13 +1103,14 @@ impl<'a, 'b: 'a> IntermediateValueIterator<'a, 'b> {
|
|||||||
let key = self
|
let key = self
|
||||||
.parser
|
.parser
|
||||||
.parse_value_from_vec(read_until_char(paren_toks, ':')?, true)?;
|
.parse_value_from_vec(read_until_char(paren_toks, ':')?, true)?;
|
||||||
|
|
||||||
devour_whitespace(paren_toks);
|
devour_whitespace(paren_toks);
|
||||||
let val = self
|
let val = self
|
||||||
.parser
|
.parser
|
||||||
.parse_value_from_vec(read_until_char(paren_toks, ',')?, true)?;
|
.parse_value_from_vec(read_until_char(paren_toks, ',')?, true)?;
|
||||||
span = span.merge(val.span);
|
span = span.merge(val.span);
|
||||||
devour_whitespace(paren_toks);
|
devour_whitespace(paren_toks);
|
||||||
if map.insert(key.node, val.node) {
|
if map.insert(key.node.clone(), val.node) {
|
||||||
return Err(("Duplicate key.", key.span).into());
|
return Err(("Duplicate key.", key.span).into());
|
||||||
}
|
}
|
||||||
if paren_toks.peek().is_none() {
|
if paren_toks.peek().is_none() {
|
||||||
|
@ -4,7 +4,7 @@ use peekmore::PeekMoreIterator;
|
|||||||
|
|
||||||
use crate::{error::SassResult, Token};
|
use crate::{error::SassResult, Token};
|
||||||
|
|
||||||
use super::{read_until_closing_paren, read_until_closing_quote};
|
use super::{read_until_closing_paren, read_until_closing_quote, read_until_newline};
|
||||||
/// Reads until the char is found, consuming the char,
|
/// Reads until the char is found, consuming the char,
|
||||||
/// or until the end of the iterator is hit
|
/// or until the end of the iterator is hit
|
||||||
pub(crate) fn read_until_char(
|
pub(crate) fn read_until_char(
|
||||||
@ -24,6 +24,13 @@ pub(crate) fn read_until_char(
|
|||||||
v.extend(read_until_closing_paren(toks)?);
|
v.extend(read_until_closing_paren(toks)?);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
'/' => {
|
||||||
|
match toks.peek() {
|
||||||
|
Some(Token { kind: '/', .. }) => read_until_newline(toks),
|
||||||
|
_ => v.push(tok),
|
||||||
|
};
|
||||||
|
continue;
|
||||||
|
}
|
||||||
t if t == c => break,
|
t if t == c => break,
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
@ -86,3 +86,16 @@ test!(
|
|||||||
}",
|
}",
|
||||||
"a {\n color: red;\n}\n"
|
"a {\n color: red;\n}\n"
|
||||||
);
|
);
|
||||||
|
test!(
|
||||||
|
comment_after_comma_in_func_args,
|
||||||
|
"@mixin a(
|
||||||
|
$foo,//foo
|
||||||
|
) {
|
||||||
|
color: $foo;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
@include a(red);
|
||||||
|
}",
|
||||||
|
"a {\n color: red;\n}\n"
|
||||||
|
);
|
||||||
|
@ -197,3 +197,11 @@ test!(
|
|||||||
"a {\n color: (a: b)==(a: c);\n}\n",
|
"a {\n color: (a: b)==(a: c);\n}\n",
|
||||||
"a {\n color: false;\n}\n"
|
"a {\n color: false;\n}\n"
|
||||||
);
|
);
|
||||||
|
test!(
|
||||||
|
empty_with_single_line_comments,
|
||||||
|
"$foo: (\n \n // :/a.b\n \n );
|
||||||
|
a {
|
||||||
|
color: inspect($foo);
|
||||||
|
}",
|
||||||
|
"a {\n color: ();\n}\n"
|
||||||
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user