check global scope for functions as well
This commit is contained in:
parent
d0b56c57d2
commit
785c824cd8
20
src/scope.rs
20
src/scope.rs
@ -14,6 +14,13 @@ pub(crate) fn get_global_var(s: &str) -> SassResult<Value> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn get_global_fn(s: &str) -> SassResult<Function> {
|
||||||
|
GLOBAL_SCOPE.with(|scope| match scope.borrow().functions().get(s) {
|
||||||
|
Some(v) => Ok(v.clone()),
|
||||||
|
None => Err("Undefined function.".into()),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn insert_global_var(s: &str, v: Value) -> SassResult<Option<Value>> {
|
pub(crate) fn insert_global_var(s: &str, v: Value) -> SassResult<Option<Value>> {
|
||||||
GLOBAL_SCOPE.with(|scope| scope.borrow_mut().insert_var(s, v))
|
GLOBAL_SCOPE.with(|scope| scope.borrow_mut().insert_var(s, v))
|
||||||
}
|
}
|
||||||
@ -39,6 +46,10 @@ impl Scope {
|
|||||||
&self.vars
|
&self.vars
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub const fn functions(&self) -> &HashMap<String, Function> {
|
||||||
|
&self.functions
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_var(&self, v: &str) -> SassResult<Value> {
|
pub fn get_var(&self, v: &str) -> SassResult<Value> {
|
||||||
let name = &v.replace('_', "-");
|
let name = &v.replace('_', "-");
|
||||||
match self.vars.get(name) {
|
match self.vars.get(name) {
|
||||||
@ -70,10 +81,11 @@ impl Scope {
|
|||||||
self.mixins.contains_key(&v.replace('_', "-"))
|
self.mixins.contains_key(&v.replace('_', "-"))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_fn(&self, v: &str) -> SassResult<&Function> {
|
pub fn get_fn(&self, v: &str) -> SassResult<Function> {
|
||||||
match self.functions.get(&v.replace('_', "-")) {
|
let name = &v.replace('_', "-");
|
||||||
Some(v) => Ok(v),
|
match self.functions.get(name) {
|
||||||
None => Err("Undefined function.".into()),
|
Some(v) => Ok(v.clone()),
|
||||||
|
None => get_global_fn(name),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,3 +63,8 @@ test!(
|
|||||||
"a {\n @function foo() {\n @return 3;\n }\n}\nb {\n color: foo();\n}\n",
|
"a {\n @function foo() {\n @return 3;\n }\n}\nb {\n color: foo();\n}\n",
|
||||||
"b {\n color: foo();\n}\n"
|
"b {\n color: foo();\n}\n"
|
||||||
);
|
);
|
||||||
|
test!(
|
||||||
|
global_function_in_scope,
|
||||||
|
"@function f() {\n @return g();\n}\n@function g() {\n @return false;\n}\na {\n color: f();\n color: g();\n}\n",
|
||||||
|
"a {\n color: false;\n color: false;\n}\n"
|
||||||
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user