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

Method maybe_capture_fn_refs

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

Source from the content-addressed store, hash-verified

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

textMethod · 0.65
getMethod · 0.65
top_rowMethod · 0.45

Tested by

no test coverage detected