eval args to zip

This commit is contained in:
ConnorSkees 2020-04-13 12:28:40 -04:00
parent 2b784f273a
commit 409fa3a1dd
2 changed files with 19 additions and 5 deletions

View File

@ -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| {
Value::List(v, ..) => v, Ok(match x.node.eval(span)?.node {
Value::Map(m) => m.entries(), Value::List(v, ..) => v,
v => vec![v], Value::Map(m) => m.entries(),
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);

View File

@ -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"
);