(sqls: &mut Vec<SQL>, decl: &Decl, import_alias: &String)
| 105 | } |
| 106 | |
| 107 | pub fn process_decl(sqls: &mut Vec<SQL>, decl: &Decl, import_alias: &String) -> Result<()> { |
| 108 | match decl { |
| 109 | Decl::Class(class) => { |
| 110 | process_class_decl(sqls, class, import_alias)?; |
| 111 | } |
| 112 | Decl::Fn(fun) => { |
| 113 | if let Some(body) = &fun.function.body { |
| 114 | for stmt in &body.stmts { |
| 115 | recurse_and_find_sql(sqls, stmt, import_alias)?; |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | Decl::Var(var) => { |
| 120 | for var_decl in &var.decls { |
| 121 | let span: MultiSpan = var.span.into(); |
| 122 | let new_sqls = get_sql_from_var_decl(var_decl, &span, import_alias); |
| 123 | let num_new_sqls = new_sqls.len(); |
| 124 | |
| 125 | sqls.extend(new_sqls); |
| 126 | |
| 127 | // We've already found the sqls based on the variable name, we should skip processing further |
| 128 | if num_new_sqls > 0 { |
| 129 | continue; |
| 130 | } |
| 131 | // Try to retrieve name of the variable |
| 132 | let name = var_decl.name.as_ident().map(|ident| ident.sym.to_string()); |
| 133 | // this is when the variable name is not found due to syntax like |
| 134 | // const [rows, i] = await connection.execute.... |
| 135 | if let Some(init) = &var_decl.init { |
| 136 | let expr = *init.clone(); |
| 137 | get_sql_from_expr(sqls, &name, &expr, &span, import_alias); |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 | Decl::TsInterface(_) => {} |
| 142 | Decl::TsTypeAlias(_) => {} |
| 143 | Decl::TsEnum(_) => {} |
| 144 | Decl::TsModule(module) => { |
| 145 | if let Some(stmt) = &module.body { |
| 146 | if let Some(block) = &stmt.as_ts_module_block() { |
| 147 | for body in &block.body { |
| 148 | let stmt = &body.clone().stmt(); |
| 149 | if let Some(stmt) = stmt { |
| 150 | recurse_and_find_sql(sqls, stmt, import_alias)?; |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | } |
| 156 | Decl::Using(using) => { |
| 157 | for decl in &using.decls { |
| 158 | let init = &decl.init; |
| 159 | if let Some(expr) = init { |
| 160 | let span: &MultiSpan = &using.span.into(); |
| 161 | get_sql_from_expr(sqls, &None, expr, span, import_alias); |
| 162 | } |
| 163 | } |
| 164 | } |
no test coverage detected