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

Method maybe_capture_fn_refs

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

Source from the content-addressed store, hash-verified

2306 // --- function-as-value capture (#756) — DART_SPEC ---------------------
2307
2308 fn maybe_capture_fn_refs(&mut self, node: Node<'t>) {
2309 let (mode, field): (&str, &str) = match node.kind() {
2310 "arguments" => ("args", ""),
2311 "assignment_expression" => ("rhs", "right"),
2312 "pair" => ("value", "value"),
2313 "list_literal" => ("list", ""),
2314 "static_final_declaration" => ("varinit", ""),
2315 _ => return,
2316 };
2317 if self.stack.is_empty() {
2318 return;
2319 }
2320 let from = self.top_row();
2321
2322 let mut values: Vec<Node<'t>> = Vec::new();
2323 match mode {
2324 "args" | "list" => {
2325 let mut cursor = node.walk();
2326 for c in node.named_children(&mut cursor) {
2327 values.push(c);
2328 }
2329 }
2330 "rhs" => {
2331 if let Some(rhs) = node.child_by_field_name(field) {
2332 let lhs = node
2333 .child_by_field_name("left")
2334 .or_else(|| node.child_by_field_name("lhs"))
2335 .or_else(|| node.child_by_field_name("target"))
2336 .or_else(|| {
2337 if node.named_child_count() >= 2 {
2338 node.named_child(0)
2339 } else {
2340 None
2341 }
2342 });
2343 let lhs_text = lhs.map(|l| self.text(l)).unwrap_or("");
2344 let lhs_last = util::lhs_last_name()
2345 .captures(lhs_text)
2346 .and_then(|c| c.get(1))
2347 .map(|m| m.as_str());
2348 if !(lhs_last.is_some() && lhs_last == Some(self.text(rhs).trim())) {
2349 values.push(rhs);
2350 }
2351 }
2352 }
2353 "value" => {
2354 let v = node.child_by_field_name(field).or_else(|| {
2355 let count = node.named_child_count();
2356 if count > 0 { node.named_child(count - 1) } else { None }
2357 });
2358 if let Some(v) = v {
2359 values.push(v);
2360 }
2361 }
2362 _ => {
2363 // varinit, NO field (function-ref.ts:471-487): the last named
2364 // child, requiring ≥2 named children; the name-field guard is
2365 // 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

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

Tested by

no test coverage detected