catch variables only used in plural selection

This commit is contained in:
Damien Elmes 2021-03-26 14:20:44 +10:00
parent 0c338bfd53
commit 8294b18c68

View File

@ -95,21 +95,26 @@ impl Visitor {
} }
} }
fn visit_inline_expression(&mut self, expr: &InlineExpression<&str>) {
match expr {
InlineExpression::VariableReference { id } => {
write!(self.text, "${}", id.name).unwrap();
self.variables.insert(id.name.to_string());
}
InlineExpression::Placeable { expression } => {
self.visit_expression(expression);
}
_ => {}
}
}
fn visit_expression(&mut self, expression: &Expression<&str>) { fn visit_expression(&mut self, expression: &Expression<&str>) {
match expression { match expression {
Expression::SelectExpression { variants, .. } => { Expression::SelectExpression { selector, variants } => {
self.visit_inline_expression(&selector);
self.visit_pattern(&variants.last().unwrap().value) self.visit_pattern(&variants.last().unwrap().value)
} }
Expression::InlineExpression(expr) => match expr { Expression::InlineExpression(expr) => self.visit_inline_expression(expr),
InlineExpression::VariableReference { id } => {
write!(self.text, "${}", id.name).unwrap();
self.variables.insert(id.name.to_string());
}
InlineExpression::Placeable { expression } => {
self.visit_expression(expression);
}
_ => {}
},
} }
} }
} }