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

Method maybe_capture_fn_refs

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

Source from the content-addressed store, hash-verified

2327 // --- function-as-value capture (#756) — DART_SPEC ---------------------
2328
2329 fn maybe_capture_fn_refs(&mut self, node: Node<'t>) {
2330 let (mode, field): (&str, &str) = match node.kind() {
2331 "arguments" => ("args", ""),
2332 "assignment_expression" => ("rhs", "right"),
2333 "pair" => ("value", "value"),
2334 "list_literal" => ("list", ""),
2335 "static_final_declaration" => ("varinit", ""),
2336 _ => return,
2337 };
2338 if self.stack.is_empty() {
2339 return;
2340 }
2341 let from = self.top_row();
2342
2343 let mut values: Vec<Node<'t>> = Vec::new();
2344 match mode {
2345 "args" | "list" => {
2346 let mut cursor = node.walk();
2347 for c in node.named_children(&mut cursor) {
2348 values.push(c);
2349 }
2350 }
2351 "rhs" => {
2352 if let Some(rhs) = node.child_by_field_name(field) {
2353 let lhs = node
2354 .child_by_field_name("left")
2355 .or_else(|| node.child_by_field_name("lhs"))
2356 .or_else(|| node.child_by_field_name("target"))
2357 .or_else(|| {
2358 if node.named_child_count() >= 2 {
2359 node.named_child(0)
2360 } else {
2361 None
2362 }
2363 });
2364 let lhs_text = lhs.map(|l| self.text(l)).unwrap_or("");
2365 let lhs_last = util::lhs_last_name()
2366 .captures(lhs_text)
2367 .and_then(|c| c.get(1))
2368 .map(|m| m.as_str());
2369 if !(lhs_last.is_some() && lhs_last == Some(self.text(rhs).trim())) {
2370 values.push(rhs);
2371 }
2372 }
2373 }
2374 "value" => {
2375 let v = node.child_by_field_name(field).or_else(|| {
2376 let count = node.named_child_count();
2377 if count > 0 { node.named_child(count - 1) } else { None }
2378 });
2379 if let Some(v) = v {
2380 values.push(v);
2381 }
2382 }
2383 _ => {
2384 // varinit, NO field (function-ref.ts:471-487): the last named
2385 // child, requiring ≥2 named children; the name-field guard is
2386 // 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 7

walkMethod · 0.80
pushMethod · 0.80
mapMethod · 0.80
textMethod · 0.65
getMethod · 0.65
top_rowMethod · 0.45

Tested by

no test coverage detected