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