handle self referential default args
This commit is contained in:
parent
f6fd0e9af5
commit
f1b60019a1
@ -68,26 +68,28 @@ impl Function {
|
|||||||
scope: &Scope,
|
scope: &Scope,
|
||||||
super_selector: &Selector,
|
super_selector: &Selector,
|
||||||
) -> SassResult<()> {
|
) -> SassResult<()> {
|
||||||
|
let mut scope = scope.clone();
|
||||||
for (idx, arg) in self.args.0.iter().enumerate() {
|
for (idx, arg) in self.args.0.iter().enumerate() {
|
||||||
if arg.is_variadic {
|
if arg.is_variadic {
|
||||||
let span = args.span();
|
let span = args.span();
|
||||||
self.scope.insert_var(
|
let arg_list = Value::ArgList(args.get_variadic(&mut scope, super_selector)?);
|
||||||
|
scope.insert_var(
|
||||||
&arg.name,
|
&arg.name,
|
||||||
Spanned {
|
Spanned {
|
||||||
node: Value::ArgList(args.get_variadic(scope, super_selector)?),
|
node: arg_list,
|
||||||
span,
|
span,
|
||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
let val = match args.get_positional(idx, scope, super_selector) {
|
let val = match args.get_positional(idx, &mut scope, super_selector) {
|
||||||
Some(v) => v?,
|
Some(v) => v?,
|
||||||
None => match args.get_named(arg.name.clone(), scope, super_selector) {
|
None => match args.get_named(arg.name.clone(), &mut scope, super_selector) {
|
||||||
Some(v) => v?,
|
Some(v) => v?,
|
||||||
None => match &arg.default {
|
None => match &arg.default {
|
||||||
Some(v) => Value::from_tokens(
|
Some(v) => Value::from_tokens(
|
||||||
&mut v.iter().cloned().peekmore(),
|
&mut v.iter().cloned().peekmore(),
|
||||||
scope,
|
&mut scope,
|
||||||
super_selector,
|
super_selector,
|
||||||
)?,
|
)?,
|
||||||
None => {
|
None => {
|
||||||
@ -98,8 +100,9 @@ impl Function {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
self.scope.insert_var(&arg.name, val)?;
|
scope.insert_var(&arg.name, val)?;
|
||||||
}
|
}
|
||||||
|
self.scope.extend(scope);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,7 +261,7 @@ impl StyleSheet {
|
|||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
#[cfg(not(feature = "wasm"))]
|
#[cfg(not(feature = "wasm"))]
|
||||||
pub fn from_path<P: AsRef<Path> + Into<String> + Clone>(p: &P) -> SassResult<String> {
|
pub fn from_path(p: &str) -> SassResult<String> {
|
||||||
let mut map = CodeMap::new();
|
let mut map = CodeMap::new();
|
||||||
let file = map.add_file(p.clone().into(), String::from_utf8(fs::read(p.clone())?)?);
|
let file = map.add_file(p.clone().into(), String::from_utf8(fs::read(p.clone())?)?);
|
||||||
Css::from_stylesheet(StyleSheet(
|
Css::from_stylesheet(StyleSheet(
|
||||||
|
@ -40,3 +40,8 @@ test!(
|
|||||||
"@function foo($arg1: bar()) {\n @return true;\n}\n\na {\n color: foo();\n}\n",
|
"@function foo($arg1: bar()) {\n @return true;\n}\n\na {\n color: foo();\n}\n",
|
||||||
"a {\n color: true;\n}\n"
|
"a {\n color: true;\n}\n"
|
||||||
);
|
);
|
||||||
|
test!(
|
||||||
|
self_referential_default_arg_value,
|
||||||
|
"@function foo($a, $b: $a) {\n @return $b;\n}\n\na {\n color: foo(2);\n}\n",
|
||||||
|
"a {\n color: 2;\n}\n"
|
||||||
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user