simplify Scope::get_var
This commit is contained in:
parent
ef25481420
commit
33f81f5bbe
@ -524,15 +524,13 @@ impl<'a> Parser<'a> {
|
||||
Ok(v) => v.map_node(|i| i.into()),
|
||||
Err(e) => return Some(Err(e)),
|
||||
};
|
||||
let span = val.span;
|
||||
IntermediateValue::Value(HigherIntermediateValue::Literal(
|
||||
match self.scopes.last().get_var(&val, self.global_scope) {
|
||||
Ok(v) => v,
|
||||
Ok(v) => v.clone(),
|
||||
Err(e) => return Some(Err(e)),
|
||||
}
|
||||
.node,
|
||||
},
|
||||
))
|
||||
.span(span)
|
||||
.span(val.span)
|
||||
}
|
||||
'+' => {
|
||||
let span = self.toks.next().unwrap().pos();
|
||||
|
15
src/scope.rs
15
src/scope.rs
@ -17,7 +17,6 @@ pub(crate) struct Scope {
|
||||
functions: HashMap<Identifier, Function>,
|
||||
}
|
||||
|
||||
// todo: separate struct for global scope?
|
||||
impl Scope {
|
||||
#[must_use]
|
||||
pub fn new() -> Self {
|
||||
@ -28,20 +27,20 @@ impl Scope {
|
||||
}
|
||||
}
|
||||
|
||||
fn get_var_no_global(&self, name: &Spanned<Identifier>) -> SassResult<Spanned<Value>> {
|
||||
fn get_var_no_global(&self, name: &Spanned<Identifier>) -> SassResult<&Value> {
|
||||
match self.vars.get(&name.node) {
|
||||
Some(v) => Ok(v.clone()),
|
||||
Some(v) => Ok(&v.node),
|
||||
None => Err(("Undefined variable.", name.span).into()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_var(
|
||||
&self,
|
||||
pub fn get_var<'a>(
|
||||
&'a self,
|
||||
name: &Spanned<Identifier>,
|
||||
global_scope: &Scope,
|
||||
) -> SassResult<Spanned<Value>> {
|
||||
global_scope: &'a Scope,
|
||||
) -> SassResult<&Value> {
|
||||
match self.vars.get(&name.node) {
|
||||
Some(v) => Ok(v.clone()),
|
||||
Some(v) => Ok(&v.node),
|
||||
None => global_scope.get_var_no_global(name),
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user