respect $module
argument to global-variable-exists
This commit is contained in:
parent
cfd2e00ebb
commit
a8046b0d83
@ -99,15 +99,39 @@ pub(crate) fn global_variable_exists(
|
||||
mut args: CallArgs,
|
||||
parser: &mut Parser<'_>,
|
||||
) -> SassResult<Value> {
|
||||
args.max_args(1)?;
|
||||
match args.get_err(0, "name")? {
|
||||
Value::String(s, _) => Ok(Value::bool(parser.global_scope.var_exists(s.into()))),
|
||||
v => Err((
|
||||
format!("$name: {} is not a string.", v.inspect(args.span())?),
|
||||
args.span(),
|
||||
)
|
||||
.into()),
|
||||
}
|
||||
args.max_args(2)?;
|
||||
|
||||
let name: Identifier = match args.get_err(0, "name")? {
|
||||
Value::String(s, _) => s.into(),
|
||||
v => {
|
||||
return Err((
|
||||
format!("$name: {} is not a string.", v.inspect(args.span())?),
|
||||
args.span(),
|
||||
)
|
||||
.into())
|
||||
}
|
||||
};
|
||||
|
||||
let module = match args.default_arg(1, "module", Value::Null)? {
|
||||
Value::String(s, _) => Some(s),
|
||||
Value::Null => None,
|
||||
v => {
|
||||
return Err((
|
||||
format!("$module: {} is not a string.", v.inspect(args.span())?),
|
||||
args.span(),
|
||||
)
|
||||
.into())
|
||||
}
|
||||
};
|
||||
|
||||
Ok(Value::bool(if let Some(module_name) = module {
|
||||
parser
|
||||
.modules
|
||||
.get(module_name.into(), args.span())?
|
||||
.var_exists(name)
|
||||
} else {
|
||||
parser.global_scope.var_exists(name)
|
||||
}))
|
||||
}
|
||||
|
||||
pub(crate) fn mixin_exists(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
|
@ -65,6 +65,10 @@ impl Module {
|
||||
self.0.functions.get(&name).cloned()
|
||||
}
|
||||
|
||||
pub fn var_exists(&self, name: Identifier) -> bool {
|
||||
self.0.var_exists(name)
|
||||
}
|
||||
|
||||
pub fn mixin_exists(&self, name: Identifier) -> bool {
|
||||
self.0.mixin_exists(name)
|
||||
}
|
||||
|
@ -15,6 +15,11 @@ test!(
|
||||
"@use 'sass:meta';\n@use 'sass:math';\na {\n color: inspect(meta.module-variables(math));\n}\n",
|
||||
"a {\n color: (\"e\": 2.7182818285, \"pi\": 3.1415926536);\n}\n"
|
||||
);
|
||||
test!(
|
||||
global_var_exists_module,
|
||||
"@use 'sass:math';\na {\n color: global-variable-exists(pi, $module: math);\n}\n",
|
||||
"a {\n color: true;\n}\n"
|
||||
);
|
||||
|
||||
#[test]
|
||||
fn mixin_exists_module() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user