MCPcopy Create free account
hub / github.com/JasonShin/sqlx-ts / process_decl

Function process_decl

src/parser/decl.rs:107–167  ·  view source on GitHub ↗
(sqls: &mut Vec<SQL>, decl: &Decl, import_alias: &String)

Source from the content-addressed store, hash-verified

105}
106
107pub 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 }

Callers 2

recurse_and_find_sqlFunction · 0.85
parse_js_fileFunction · 0.85

Calls 5

process_class_declFunction · 0.85
recurse_and_find_sqlFunction · 0.85
get_sql_from_var_declFunction · 0.85
get_sql_from_exprFunction · 0.85
mapMethod · 0.80

Tested by

no test coverage detected