Skip to content

Commit

Permalink
fmt + clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Heulitig committed Oct 27, 2023
1 parent 4ff085f commit 4e3ed23
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions fastn-js/src/to_js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1034,13 +1034,13 @@ impl ExpressionGenerator {
};

if node.operator().get_variable_identifier_read().is_some() && !no_getter {
let chain_dot_operator_count = value.matches(".").count();
let chain_dot_operator_count = value.matches('.').count();
// When there are chained dot operator value
// like person.name, person.meta.address
if chain_dot_operator_count > 1 {
return format!(
"fastn_utils.getStaticValue({})",
self.get_chained_getter_string(value.as_str())
get_chained_getter_string(value.as_str())
);
}

Expand All @@ -1051,22 +1051,6 @@ impl ExpressionGenerator {
}
}

pub fn get_chained_getter_string(&self, value: &str) -> String {
let chain_dot_operator_count = value.matches(".").count();
if chain_dot_operator_count >= 1 {
while chain_dot_operator_count != 1 {
if let Some((variable, key)) = value.rsplit_once('.') {
return format!(
"fastn_utils.getterByKey({}, \"{}\")",
self.get_chained_getter_string(variable),
key.replace("-", "_")
);
}
}
}
return value.to_string();
}

pub fn has_value(&self, operator: &fastn_grammar::evalexpr::Operator) -> Option<String> {
match operator {
fastn_grammar::evalexpr::Operator::Const { .. }
Expand Down Expand Up @@ -1135,6 +1119,20 @@ impl ExpressionGenerator {
}
}

pub fn get_chained_getter_string(value: &str) -> String {
let chain_dot_operator_count = value.matches('.').count();
if chain_dot_operator_count >= 1 {
if let Some((variable, key)) = value.rsplit_once('.') {
return format!(
"fastn_utils.getterByKey({}, \"{}\")",
get_chained_getter_string(variable),
key.replace('-', "_")
);
}
}
value.to_string()
}

#[cfg(test)]
#[track_caller]
pub fn e(f: fastn_js::Ast, s: &str) {
Expand Down

0 comments on commit 4e3ed23

Please sign in to comment.