eval args to zip
This commit is contained in:
parent
2b784f273a
commit
409fa3a1dd
@ -4,6 +4,7 @@ use num_traits::{One, Signed, ToPrimitive, Zero};
|
|||||||
|
|
||||||
use super::Builtin;
|
use super::Builtin;
|
||||||
use crate::common::{Brackets, ListSeparator, QuoteKind};
|
use crate::common::{Brackets, ListSeparator, QuoteKind};
|
||||||
|
use crate::error::SassResult;
|
||||||
use crate::unit::Unit;
|
use crate::unit::Unit;
|
||||||
use crate::value::{Number, Value};
|
use crate::value::{Number, Value};
|
||||||
|
|
||||||
@ -294,15 +295,18 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
f.insert(
|
f.insert(
|
||||||
"zip".to_owned(),
|
"zip".to_owned(),
|
||||||
Builtin::new(|args, scope, super_selector| {
|
Builtin::new(|args, scope, super_selector| {
|
||||||
|
let span = args.span();
|
||||||
let lists = args
|
let lists = args
|
||||||
.get_variadic(scope, super_selector)?
|
.get_variadic(scope, super_selector)?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|x| match x.node {
|
.map(|x| {
|
||||||
|
Ok(match x.node.eval(span)?.node {
|
||||||
Value::List(v, ..) => v,
|
Value::List(v, ..) => v,
|
||||||
Value::Map(m) => m.entries(),
|
Value::Map(m) => m.entries(),
|
||||||
v => vec![v],
|
v => vec![v],
|
||||||
})
|
})
|
||||||
.collect::<Vec<Vec<Value>>>();
|
})
|
||||||
|
.collect::<SassResult<Vec<Vec<Value>>>>()?;
|
||||||
|
|
||||||
let len = lists.iter().map(|l| l.len()).min().unwrap_or(0);
|
let len = lists.iter().map(|l| l.len()).min().unwrap_or(0);
|
||||||
|
|
||||||
|
@ -303,3 +303,13 @@ test!(
|
|||||||
"a {\n color: zip(1px 1px 3px, solid dashed solid, red green blue);\n}\n",
|
"a {\n color: zip(1px 1px 3px, solid dashed solid, red green blue);\n}\n",
|
||||||
"a {\n color: 1px solid red, 1px dashed green, 3px solid blue;\n}\n"
|
"a {\n color: 1px solid red, 1px dashed green, 3px solid blue;\n}\n"
|
||||||
);
|
);
|
||||||
|
test!(
|
||||||
|
zip_parens,
|
||||||
|
"a {\n color: zip((a, b, c));\n}\n",
|
||||||
|
"a {\n color: a, b, c;\n}\n"
|
||||||
|
);
|
||||||
|
test!(
|
||||||
|
zip_parens_length,
|
||||||
|
"a {\n color: length(zip((a, b, c)));\n}\n",
|
||||||
|
"a {\n color: 3;\n}\n"
|
||||||
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user