respect $module
argument passed to function-exists
This commit is contained in:
parent
f60fb26ca0
commit
28a0a33d85
@ -173,16 +173,38 @@ pub(crate) fn mixin_exists(mut args: CallArgs, parser: &mut Parser<'_>) -> SassR
|
||||
|
||||
pub(crate) fn function_exists(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
args.max_args(2)?;
|
||||
match args.get_err(0, "name")? {
|
||||
Value::String(s, _) => Ok(Value::bool(
|
||||
parser.scopes.fn_exists(s.into(), parser.global_scope),
|
||||
)),
|
||||
v => Err((
|
||||
format!("$name: {} is not a string.", v.inspect(args.span())?),
|
||||
args.span(),
|
||||
)
|
||||
.into()),
|
||||
}
|
||||
|
||||
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())?
|
||||
.fn_exists(name)
|
||||
} else {
|
||||
parser.scopes.fn_exists(name, parser.global_scope)
|
||||
}))
|
||||
}
|
||||
|
||||
pub(crate) fn get_function(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult<Value> {
|
||||
|
@ -191,6 +191,10 @@ impl Module {
|
||||
!name.as_str().starts_with('-') && self.scope.mixin_exists(name)
|
||||
}
|
||||
|
||||
pub fn fn_exists(&self, name: Identifier) -> bool {
|
||||
!name.as_str().starts_with('-') && self.scope.fn_exists(name)
|
||||
}
|
||||
|
||||
pub fn insert_builtin(
|
||||
&mut self,
|
||||
name: &'static str,
|
||||
|
@ -67,7 +67,7 @@ impl Scope {
|
||||
self.functions.insert(s, v)
|
||||
}
|
||||
|
||||
fn fn_exists(&self, name: Identifier) -> bool {
|
||||
pub fn fn_exists(&self, name: Identifier) -> bool {
|
||||
if self.functions.is_empty() {
|
||||
return false;
|
||||
}
|
||||
|
@ -18,6 +18,16 @@ test!(
|
||||
"@use 'sass:math';\na {\n color: global-variable-exists(pi, $module: math);\n}\n",
|
||||
"a {\n color: true;\n}\n"
|
||||
);
|
||||
test!(
|
||||
fn_exists_builtin,
|
||||
"@use 'sass:math';\na {\n color: function-exists(acos, $module: math);\n}\n",
|
||||
"a {\n color: true;\n}\n"
|
||||
);
|
||||
error!(
|
||||
fn_exists_module_dne,
|
||||
"a {\n color: function-exists(c, d);\n}\n",
|
||||
"Error: There is no module with the namespace \"d\"."
|
||||
);
|
||||
|
||||
#[test]
|
||||
fn mixin_exists_module() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user