(&mut self, node: Node<'t>)
| 1420 | // --- function-as-value refs (CSHARP_SPEC, function-ref.ts:250) -------------- |
| 1421 | |
| 1422 | fn maybe_capture_fn_refs(&mut self, node: Node<'t>) { |
| 1423 | #[derive(PartialEq)] |
| 1424 | enum Mode { |
| 1425 | Args, |
| 1426 | Rhs, |
| 1427 | List, |
| 1428 | Varinit, |
| 1429 | } |
| 1430 | let mode = match node.kind() { |
| 1431 | "argument_list" => Mode::Args, |
| 1432 | "assignment_expression" => Mode::Rhs, // covers `+=` event subscription |
| 1433 | "initializer_expression" => Mode::List, |
| 1434 | "variable_declarator" => Mode::Varinit, |
| 1435 | _ => return, |
| 1436 | }; |
| 1437 | if self.stack.is_empty() { |
| 1438 | return; |
| 1439 | } |
| 1440 | let from = self.top_row(); |
| 1441 | |
| 1442 | let mut values: Vec<Node> = Vec::new(); |
| 1443 | match mode { |
| 1444 | Mode::Args | Mode::List => { |
| 1445 | for i in 0..node.named_child_count() { |
| 1446 | if let Some(c) = node.named_child(i) { |
| 1447 | values.push(c); |
| 1448 | } |
| 1449 | } |
| 1450 | } |
| 1451 | Mode::Rhs => { |
| 1452 | if let Some(rhs) = node.child_by_field_name("right") { |
| 1453 | // Param-storage skip: `this.status = status`. |
| 1454 | let lhs = node |
| 1455 | .child_by_field_name("left") |
| 1456 | .or_else(|| node.child_by_field_name("lhs")) |
| 1457 | .or_else(|| node.child_by_field_name("target")) |
| 1458 | .or_else(|| { |
| 1459 | if node.named_child_count() >= 2 { node.named_child(0) } else { None } |
| 1460 | }); |
| 1461 | let lhs_text = lhs.map(|l| self.text(l)).unwrap_or(""); |
| 1462 | let lhs_last = util::lhs_last_name() |
| 1463 | .captures(lhs_text) |
| 1464 | .and_then(|c| c.get(1)) |
| 1465 | .map(|m| m.as_str()); |
| 1466 | let rhs_text = self.text(rhs).trim(); |
| 1467 | if !(lhs_last.is_some() && lhs_last == Some(rhs_text)) { |
| 1468 | values.push(rhs); |
| 1469 | } |
| 1470 | } |
| 1471 | } |
| 1472 | Mode::Varinit => { |
| 1473 | // No `value` field on C# variable_declarator: the initializer |
| 1474 | // is the LAST named child — but an initializer-less declarator |
| 1475 | // has its NAME there. Require ≥2 named children and never pick |
| 1476 | // the name child. (Destructuring pattern gate never matches C#.) |
| 1477 | let name_child = node |
| 1478 | .child_by_field_name("name") |
| 1479 | .or_else(|| node.child_by_field_name("pattern")); |
no test coverage detected