From 8294b18c685ddce352c37c35f0cae6f25925cef4 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 26 Mar 2021 14:20:44 +1000 Subject: [PATCH] catch variables only used in plural selection --- rslib/i18n/build/extract.rs | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/rslib/i18n/build/extract.rs b/rslib/i18n/build/extract.rs index 97b823de9..4ee298518 100644 --- a/rslib/i18n/build/extract.rs +++ b/rslib/i18n/build/extract.rs @@ -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>) { match expression { - Expression::SelectExpression { variants, .. } => { + Expression::SelectExpression { selector, variants } => { + self.visit_inline_expression(&selector); self.visit_pattern(&variants.last().unwrap().value) } - Expression::InlineExpression(expr) => 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); - } - _ => {} - }, + Expression::InlineExpression(expr) => self.visit_inline_expression(expr), } } }