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