MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / maybe_capture_fn_refs

Method maybe_capture_fn_refs

codegraph-kernel/src/dart.rs:1276–1346  ·  view source on GitHub ↗
(&mut self, node: Node<'t>)

Source from the content-addressed store, hash-verified

1274 // --- function-as-value capture (#756) — DART_SPEC ---------------------
1275
1276 fn maybe_capture_fn_refs(&mut self, node: Node<'t>) {
1277 let (mode, field): (&str, &str) = match node.kind() {
1278 "arguments" => ("args", ""),
1279 "assignment_expression" => ("rhs", "right"),
1280 "pair" => ("value", "value"),
1281 "list_literal" => ("list", ""),
1282 "static_final_declaration" => ("varinit", ""),
1283 _ => return,
1284 };
1285 if self.stack.is_empty() {
1286 return;
1287 }
1288 let from = self.top_row();
1289
1290 let mut values: Vec<Node<'t>> = Vec::new();
1291 match mode {
1292 "args" | "list" => {
1293 let mut cursor = node.walk();
1294 for c in node.named_children(&mut cursor) {
1295 values.push(c);
1296 }
1297 }
1298 "rhs" => {
1299 if let Some(rhs) = node.child_by_field_name(field) {
1300 let lhs = node
1301 .child_by_field_name("left")
1302 .or_else(|| node.child_by_field_name("lhs"))
1303 .or_else(|| node.child_by_field_name("target"))
1304 .or_else(|| {
1305 if node.named_child_count() >= 2 {
1306 node.named_child(0)
1307 } else {
1308 None
1309 }
1310 });
1311 let lhs_text = lhs.map(|l| self.text(l)).unwrap_or("");
1312 let lhs_last = util::lhs_last_name()
1313 .captures(lhs_text)
1314 .and_then(|c| c.get(1))
1315 .map(|m| m.as_str());
1316 if !(lhs_last.is_some() && lhs_last == Some(self.text(rhs).trim())) {
1317 values.push(rhs);
1318 }
1319 }
1320 }
1321 "value" => {
1322 let v = node.child_by_field_name(field).or_else(|| {
1323 let count = node.named_child_count();
1324 if count > 0 { node.named_child(count - 1) } else { None }
1325 });
1326 if let Some(v) = v {
1327 values.push(v);
1328 }
1329 }
1330 _ => {
1331 // varinit, NO field (function-ref.ts:471-487): the last named
1332 // child, requiring ≥2 named children; the name-field guard is
1333 // inert (static_final_declaration has no name/pattern field).

Callers 3

visitMethod · 0.45
visit_bodyMethod · 0.45
scan_fn_ref_subtreeMethod · 0.45

Calls 4

getMethod · 0.65
top_rowMethod · 0.45
textMethod · 0.45

Tested by

no test coverage detected