aboutsummaryrefslogtreecommitdiffstats
path: root/askama_shared/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--askama_shared/src/generator.rs80
1 files changed, 42 insertions, 38 deletions
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) = &param.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) = &param.1 {
+ buf.write(":");
+ self.visit_match_param(buf, param);
+ }
+ }
+ buf.write("}");
+ }
+ }
+ }
+
fn visit_filter(
&mut self,
buf: &mut Buffer,