diff --git a/src/atrule/mod.rs b/src/atrule/mod.rs index 4fcf237..0ab2c53 100644 --- a/src/atrule/mod.rs +++ b/src/atrule/mod.rs @@ -181,7 +181,7 @@ impl AtRule { let mut scope = scope.clone(); if from < to { for i in from..(to + through) { - scope.insert_var(&var, Value::Dimension(Number::from(i), Unit::None)); + scope.insert_var(&var, Value::Dimension(Number::from(i), Unit::None))?; stmts.extend(eat_unknown_atrule_body( &mut body.clone().into_iter().peekable(), &scope, @@ -190,7 +190,7 @@ impl AtRule { } } else if from > to { for i in ((to - through)..(from + 1)).skip(1).rev() { - scope.insert_var(&var, Value::Dimension(Number::from(i), Unit::None)); + scope.insert_var(&var, Value::Dimension(Number::from(i), Unit::None))?; stmts.extend(eat_unknown_atrule_body( &mut body.clone().into_iter().peekable(), &scope, @@ -283,7 +283,7 @@ fn eat_unknown_atrule_body>( })); } Expr::VariableDecl(name, val) => { - scope.insert_var(&name, *val); + scope.insert_var(&name, *val)?; } Expr::MultilineComment(s) => stmts.push(Stmt::MultilineComment(s)), } diff --git a/src/common.rs b/src/common.rs index 9132e43..a8bae90 100644 --- a/src/common.rs +++ b/src/common.rs @@ -377,8 +377,8 @@ impl Scope { } } - pub fn insert_var(&mut self, s: &str, v: Value) -> Option { - self.vars.insert(s.replace('_', "-"), v) + pub fn insert_var(&mut self, s: &str, v: Value) -> SassResult> { + Ok(self.vars.insert(s.replace('_', "-"), v.eval()?)) } pub fn var_exists(&self, v: &str) -> bool { diff --git a/src/function.rs b/src/function.rs index 9c624ed..cf1f325 100644 --- a/src/function.rs +++ b/src/function.rs @@ -78,7 +78,7 @@ impl Function { }, }, }; - self.scope.insert_var(&arg.name, val); + self.scope.insert_var(&arg.name, val)?; } Ok(self) } diff --git a/src/lib.rs b/src/lib.rs index 3b65f94..2e7c686 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -391,7 +391,7 @@ impl<'a> StyleSheetParser<'a> { let VariableDecl { val, default } = eat_variable_value(&mut self.lexer, &self.global_scope)?; if !default || self.global_scope.get_var(&name).is_err() { - self.global_scope.insert_var(&name, val); + self.global_scope.insert_var(&name, val)?; } } TokenKind::MultilineComment(_) => { @@ -524,10 +524,10 @@ impl<'a> StyleSheetParser<'a> { } Expr::VariableDecl(name, val) => { if self.scope == 0 { - scope.insert_var(&name, *val.clone()); - self.global_scope.insert_var(&name, *val); + scope.insert_var(&name, *val.clone())?; + self.global_scope.insert_var(&name, *val)?; } else { - scope.insert_var(&name, *val); + scope.insert_var(&name, *val)?; } } Expr::Include(rules) => stmts.extend(rules), diff --git a/src/mixin.rs b/src/mixin.rs index 94fa44c..abcc0ce 100644 --- a/src/mixin.rs +++ b/src/mixin.rs @@ -81,7 +81,7 @@ impl Mixin { }, }, }; - self.scope.insert_var(&arg.name, val); + self.scope.insert_var(&arg.name, val)?; } Ok(self) } @@ -114,7 +114,7 @@ impl Mixin { })); } Expr::VariableDecl(name, val) => { - self.scope.insert_var(&name, *val); + self.scope.insert_var(&name, *val)?; } Expr::MultilineComment(s) => stmts.push(Stmt::MultilineComment(s)), }