/// Evaluate a single argument
///
/// Only used by the `if` function, which is the only sass
/// function that evaluates its arguments lazily.
Evaluate a single argument
Only used by the `if` function, which is the only sass
function that evaluates its arguments lazily.
Evaluate a single argument Only used by the ` if ` function which is the only sass function that evaluates its arguments lazily .
pub fn evaluate_single(
        &self,
        scope: ScopeRef,
        name: Name,
        num: usize,
    ) -> Result<css::Value, Error> {
        // TODO: Error if both name and posinal exists?
        if let Some(v) = self.named.get(&name) {
            return v.do_evaluate(scope, true);
        }
        let mut i = 0;
        for a in &self.positional {
            match is_splat(a) {
                Some([one]) => match one.do_evaluate(scope.clone(), true)? {
                    css::Value::ArgList(args) => {
                        if let Some(v) = args
                            .named
                            .get(&name)
                            .or_else(|| args.positional.get(num - i))
                        {
                            return Ok(v.clone());
                        }
                        i += if args.named.is_empty() {
                            args.len()
                        } else {
                            num + 1
                        };
                    }
                    css::Value::Map(map) => {
                        if let Some(v) = map.get(&name.to_string().into()) {
                            return Ok(v.clone());
                        }
                        i += num + 1;
                    }
                    css::Value::List(items, ..) => {
                        if let Some(v) = items.get(num - i) {
                            return Ok(v.clone());
                        } else {
                            i += items.len();
                        }
                    }
                    css::Value::Null => (),
                    v => {
                        if i == num {
                            return Ok(v);
                        } else {
                            i += 1;
                        }
                    }
                },
                Some(splat) => {
                    if let Some(v) = splat.get(num - i) {
                        return v.do_evaluate(scope, true);
                    } else {
                        i += splat.len();
                    }
                }
                None => {
                    if i == num {
                        return a.do_evaluate(scope, true);
                    } else {
                        i += 1;
                    }
                }
            }
        }
        Ok(css::Value::Null)
    }
pub fn evaluate_single ( & self , scope : ScopeRef , name : Name , num : usize , ) -> Result < css :: Value , Error > { // TODO: Error if both name and posinal exists? if let Some ( v ) = self . named . get ( & name ) { return v . do_evaluate ( scope , true ) ; } let mut i = 0 ; for a in & self . positional { match is_splat ( a ) { Some ( [ one ] ) => match one . do_evaluate ( scope . clone ( ) , true ) ? { css :: Value :: ArgList ( args ) => { if let Some ( v ) = args . named . get ( & name ) . or_else ( | | args . positional . get ( num - i ) ) { return Ok ( v . clone ( ) ) ; } i += if args . named . is_empty ( ) { args . len ( ) } else { num + 1 } ; } css :: Value :: Map ( map ) => { if let Some ( v ) = map . get ( & name . to_string ( ) . into ( ) ) { return Ok ( v . clone ( ) ) ; } i += num + 1 ; } css :: Value :: List ( items , .. ) => { if let Some ( v ) = items . get ( num - i ) { return Ok ( v . clone ( ) ) ; } else { i += items . len ( ) ; } } css :: Value :: Null => ( ) , v => { if i == num { return Ok ( v ) ; } else { i += 1 ; } } } , Some ( splat ) => { if let Some ( v ) = splat . get ( num - i ) { return v . do_evaluate ( scope , true ) ; } else { i += splat . len ( ) ; } } None => { if i == num { return a . do_evaluate ( scope , true ) ; } else { i += 1 ; } } } } Ok ( css :: Value :: Null ) }
Evaluate a single argument
Only used by the `if` function, which is the only sass
function that evaluates its arguments lazily.
Evaluate a single argument Only used by the ` if ` function which is the only sass function that evaluates its arguments lazily .
&self
scope
ScopeRef
name
Name
num
usize