better error messages in args when missing { after function decl

This commit is contained in:
ConnorSkees 2020-04-24 21:52:09 -04:00
parent cc881db254
commit 092cbe75bb
2 changed files with 13 additions and 7 deletions

View File

@ -199,12 +199,16 @@ pub(crate) fn eat_func_args<I: Iterator<Item = Token>>(
super_selector: &Selector, super_selector: &Selector,
) -> SassResult<FuncArgs> { ) -> SassResult<FuncArgs> {
let mut args: Vec<FuncArg> = Vec::new(); let mut args: Vec<FuncArg> = Vec::new();
let mut close_paren_span: Span = toks.peek().unwrap().pos();
devour_whitespace(toks); devour_whitespace(toks);
while let Some(Token { kind, .. }) = toks.next() { while let Some(Token { kind, pos }) = toks.next() {
let name = match kind { let name = match kind {
'$' => eat_ident(toks, scope, super_selector)?, '$' => eat_ident(toks, scope, super_selector)?,
')' => break, ')' => {
close_paren_span = pos;
break;
}
_ => todo!(), _ => todo!(),
}; };
let mut default: Vec<Token> = Vec::new(); let mut default: Vec<Token> = Vec::new();
@ -234,6 +238,7 @@ pub(crate) fn eat_func_args<I: Iterator<Item = Token>>(
default: Some(default), default: Some(default),
is_variadic, is_variadic,
}); });
close_paren_span = tok.pos();
break; break;
} }
_ => { _ => {
@ -268,6 +273,7 @@ pub(crate) fn eat_func_args<I: Iterator<Item = Token>>(
break; break;
} }
')' => { ')' => {
close_paren_span = span;
args.push(FuncArg { args.push(FuncArg {
name: name.replace('_', "-"), name: name.replace('_', "-"),
default: if default.is_empty() { default: if default.is_empty() {
@ -289,10 +295,10 @@ pub(crate) fn eat_func_args<I: Iterator<Item = Token>>(
devour_whitespace(toks); devour_whitespace(toks);
} }
devour_whitespace(toks); devour_whitespace(toks);
if let Some(Token { kind: '{', .. }) = toks.next() { match toks.next() {
} else { Some(v) if v.kind == '{' => {}
todo!("expected `{{` after args") Some(..) | None => return Err(("expected \"{\".", close_paren_span).into()),
} };
Ok(FuncArgs(args)) Ok(FuncArgs(args))
} }

View File

@ -169,7 +169,7 @@ impl Css {
._inner_pretty_print(buf, nesting + 1)?; ._inner_pretty_print(buf, nesting + 1)?;
writeln!(buf, "{}}}", padding)?; writeln!(buf, "{}}}", padding)?;
} }
_ => todo!("at-rule other than unknown at toplevel"), _ => todo!("at-rule other than unknown at toplevel: {:?}", r),
}, },
Toplevel::Style(s) => { Toplevel::Style(s) => {
writeln!(buf, "{}{}", padding, s.to_string()?)?; writeln!(buf, "{}{}", padding, s.to_string()?)?;