diff --git a/src/builtin/meta.rs b/src/builtin/meta.rs index 46f3c17..30023fe 100644 --- a/src/builtin/meta.rs +++ b/src/builtin/meta.rs @@ -2,6 +2,7 @@ use std::collections::HashMap; use super::{Builtin, GLOBAL_FUNCTIONS}; use crate::common::QuoteKind; +use crate::scope::global_var_exists; use crate::unit::Unit; use crate::value::Value; @@ -89,6 +90,16 @@ pub(crate) fn register(f: &mut HashMap) { } }), ); + f.insert( + "global-variable-exists".to_owned(), + Box::new(|args, _| { + max_args!(args, 1); + match arg!(args, 0, "name") { + Value::Ident(s, _) => Ok(Value::bool(global_var_exists(&s))), + v => Err(format!("$name: {} is not a string.", v).into()), + } + }), + ); f.insert( "mixin-exists".to_owned(), Box::new(|args, scope| { diff --git a/src/scope.rs b/src/scope.rs index dc7e4f9..068b52a 100644 --- a/src/scope.rs +++ b/src/scope.rs @@ -14,6 +14,10 @@ pub(crate) fn get_global_var(s: &str) -> SassResult { }) } +pub fn global_var_exists(v: &str) -> bool { + GLOBAL_SCOPE.with(|scope| scope.borrow().var_exists(v)) +} + pub(crate) fn get_global_fn(s: &str) -> SassResult { GLOBAL_SCOPE.with(|scope| match scope.borrow().functions().get(s) { Some(v) => Ok(v.clone()),