diff --git a/src/parse/mod.rs b/src/parse/mod.rs index 2da005b..b996139 100644 --- a/src/parse/mod.rs +++ b/src/parse/mod.rs @@ -10,6 +10,7 @@ use crate::{ media::MediaRule, AtRuleKind, Content, SupportsRule, UnknownAtRule, }, + common::Identifier, error::SassResult, scope::Scope, selector::{ @@ -514,10 +515,12 @@ impl<'a> Parser<'a> { let mut scope = 0; while let Some(tok) = self.toks.next() { match tok.kind { - '}' => if scope == 0 { - break - } else { - scope -= 1; + '}' => { + if scope == 0 { + break; + } else { + scope -= 1; + } } '{' => scope += 1, _ => continue, @@ -640,8 +643,10 @@ impl<'a> Parser<'a> { .toks .next() .ok_or(("expected \"$\".", self.span_before))?; - let var = match next.kind { - '$' => self.parse_identifier_no_interpolation(false)?, + let var: Spanned = match next.kind { + '$' => self + .parse_identifier_no_interpolation(false)? + .map_node(|i| i.into()), _ => return Err(("expected \"$\".", self.span_before).into()), }; self.whitespace(); @@ -872,7 +877,7 @@ impl<'a> Parser<'a> { fn parse_each(&mut self) -> SassResult> { self.whitespace(); - let mut vars = Vec::new(); + let mut vars: Vec> = Vec::new(); loop { let next = self @@ -881,7 +886,7 @@ impl<'a> Parser<'a> { .ok_or(("expected \"$\".", self.span_before))?; match next.kind { - '$' => vars.push(self.parse_identifier()?), + '$' => vars.push(self.parse_identifier()?.map_node(|i| i.into())), _ => return Err(("expected \"$\".", next.pos()).into()), } self.whitespace(); @@ -919,7 +924,7 @@ impl<'a> Parser<'a> { for row in iter { if vars.len() == 1 { self.scopes.last_mut().insert_var( - &vars[0].node, + vars[0].node.clone(), Spanned { node: row, span: vars[0].span, @@ -932,7 +937,7 @@ impl<'a> Parser<'a> { .chain(std::iter::once(Value::Null).cycle()), ) { self.scopes.last_mut().insert_var( - &var.node, + var.node.clone(), Spanned { node: val, span: var.span, diff --git a/src/parse/value/parse.rs b/src/parse/value/parse.rs index 4fb8b44..1c482f2 100644 --- a/src/parse/value/parse.rs +++ b/src/parse/value/parse.rs @@ -521,12 +521,12 @@ impl<'a> Parser<'a> { '$' => { self.toks.next(); let val = match self.parse_identifier_no_interpolation(false) { - Ok(v) => v, + 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) { + match self.scopes.last().get_var(&val, self.global_scope) { Ok(v) => v, Err(e) => return Some(Err(e)), } diff --git a/src/scope.rs b/src/scope.rs index 6787283..c4f2ced 100644 --- a/src/scope.rs +++ b/src/scope.rs @@ -35,24 +35,19 @@ impl Scope { } } - pub fn get_var>( + pub fn get_var( &self, - name: Spanned, + name: &Spanned, global_scope: &Scope, ) -> SassResult> { - let name = name.map_node(Into::into); match self.vars.get(&name.node) { Some(v) => Ok(v.clone()), - None => global_scope.get_var_no_global(&name), + None => global_scope.get_var_no_global(name), } } - pub fn insert_var>( - &mut self, - s: T, - v: Spanned, - ) -> Option> { - self.vars.insert(s.into(), v) + pub fn insert_var(&mut self, s: Identifier, v: Spanned) -> Option> { + self.vars.insert(s, v) } pub fn var_exists_no_global(&self, name: &Identifier) -> bool {