From c3e8b2cc724abc063f731ba5a222324b95b72042 Mon Sep 17 00:00:00 2001 From: RenĂ© Kijewski Date: Tue, 29 Jun 2021 14:57:20 +0200 Subject: Move visit_match_params into its own method --- askama_shared/src/generator.rs | 80 ++++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 38 deletions(-) (limited to 'askama_shared') diff --git a/askama_shared/src/generator.rs b/askama_shared/src/generator.rs index 0ce7df3..ddcc1d8 100644 --- a/askama_shared/src/generator.rs +++ b/askama_shared/src/generator.rs @@ -564,44 +564,7 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { None => buf.write("_"), }; - match params { - MatchParameters::Simple(params) => { - if !params.is_empty() { - buf.write("("); - for (i, param) in params.iter().enumerate() { - if let MatchParameter::Name(p) = *param { - self.locals.insert_with_default(p); - } - if i > 0 { - buf.write(", "); - } - self.visit_match_param(buf, param); - } - buf.write(")"); - } - } - MatchParameters::Named(params) => { - buf.write("{"); - for (i, param) in params.iter().enumerate() { - if let Some(MatchParameter::Name(p)) = param.1 { - let p = normalize_identifier(p); - self.locals.insert_with_default(p); - } else { - self.locals.insert_with_default(param.0); - } - - if i > 0 { - buf.write(", "); - } - buf.write(param.0); - if let Some(param) = ¶m.1 { - buf.write(":"); - self.visit_match_param(buf, param); - } - } - buf.write("}"); - } - } + self.visit_match_params(buf, params); buf.writeln(" => {")?; arm_size = self.handle(ctx, body, buf, AstLevel::Nested)?; @@ -1155,6 +1118,47 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { wrapped } + fn visit_match_params(&mut self, buf: &mut Buffer, params: &MatchParameters<'a>) { + match params { + MatchParameters::Simple(params) => { + if !params.is_empty() { + buf.write("("); + for (i, param) in params.iter().enumerate() { + if let MatchParameter::Name(p) = *param { + self.locals.insert_with_default(p); + } + if i > 0 { + buf.write(", "); + } + self.visit_match_param(buf, param); + } + buf.write(")"); + } + } + MatchParameters::Named(params) => { + buf.write("{"); + for (i, param) in params.iter().enumerate() { + if let Some(MatchParameter::Name(p)) = param.1 { + let p = normalize_identifier(p); + self.locals.insert_with_default(p); + } else { + self.locals.insert_with_default(param.0); + } + + if i > 0 { + buf.write(", "); + } + buf.write(param.0); + if let Some(param) = ¶m.1 { + buf.write(":"); + self.visit_match_param(buf, param); + } + } + buf.write("}"); + } + } + } + fn visit_filter( &mut self, buf: &mut Buffer, -- cgit