handle _ and - args interchangably

This commit is contained in:
ConnorSkees 2020-03-31 01:22:41 -04:00
parent 5bbf070b95
commit 75b896fe3d
2 changed files with 10 additions and 5 deletions

View File

@ -77,7 +77,7 @@ pub(crate) fn eat_func_args<I: Iterator<Item = Token>>(
',' => {
toks.next();
args.push(FuncArg {
name,
name: name.replace('_', "-"),
default: Some(Value::from_tokens(
&mut default.into_iter().peekable(),
scope,
@ -88,7 +88,7 @@ pub(crate) fn eat_func_args<I: Iterator<Item = Token>>(
}
')' => {
args.push(FuncArg {
name,
name: name.replace('_', "-"),
default: Some(Value::from_tokens(
&mut default.into_iter().peekable(),
scope,
@ -107,7 +107,7 @@ pub(crate) fn eat_func_args<I: Iterator<Item = Token>>(
'.' => todo!("handle varargs"),
')' => {
args.push(FuncArg {
name,
name: name.replace('_', "-"),
default: if default.is_empty() {
None
} else {
@ -121,7 +121,7 @@ pub(crate) fn eat_func_args<I: Iterator<Item = Token>>(
break;
}
',' => args.push(FuncArg {
name,
name: name.replace('_', "-"),
default: None,
}),
_ => {}

View File

@ -190,7 +190,12 @@ test!(
"a {\n color: red;\n}\n"
);
test!(
args_interchangable_hypen_underscore,
args_hyphen_arg_allows_underscore,
"@mixin foo($a-b) {\n color: $a-b;\n color: $a_b;\n}\na {\n @include foo($a_b: a);\n @include foo($a-b: a);\n}\n",
"a {\n color: a;\n color: a;\n color: a;\n color: a;\n}\n"
);
test!(
args_underscore_arg_allows_hyphen,
"@mixin foo($a_b) {\n color: $a-b;\n color: $a_b;\n}\na {\n @include foo($a_b: a);\n @include foo($a-b: a);\n}\n",
"a {\n color: a;\n color: a;\n color: a;\n color: a;\n}\n"
);