(&mut self, node: Node<'t>)
| 1289 | // --- function-as-value refs (CSHARP_SPEC, function-ref.ts:250) -------------- |
| 1290 | |
| 1291 | fn maybe_capture_fn_refs(&mut self, node: Node<'t>) { |
| 1292 | #[derive(PartialEq)] |
| 1293 | enum Mode { |
| 1294 | Args, |
| 1295 | Rhs, |
| 1296 | List, |
| 1297 | Varinit, |
| 1298 | } |
| 1299 | let mode = match node.kind() { |
| 1300 | "argument_list" => Mode::Args, |
| 1301 | "assignment_expression" => Mode::Rhs, // covers `+=` event subscription |
| 1302 | "initializer_expression" => Mode::List, |
| 1303 | "variable_declarator" => Mode::Varinit, |
| 1304 | _ => return, |
| 1305 | }; |
| 1306 | if self.stack.is_empty() { |
| 1307 | return; |
| 1308 | } |
| 1309 | let from = self.top_row(); |
| 1310 | |
| 1311 | let mut values: Vec<Node> = Vec::new(); |
| 1312 | match mode { |
| 1313 | Mode::Args | Mode::List => { |
| 1314 | for i in 0..node.named_child_count() { |
| 1315 | if let Some(c) = node.named_child(i) { |
| 1316 | values.push(c); |
| 1317 | } |
| 1318 | } |
| 1319 | } |
| 1320 | Mode::Rhs => { |
| 1321 | if let Some(rhs) = node.child_by_field_name("right") { |
| 1322 | // Param-storage skip: `this.status = status`. |
| 1323 | let lhs = node |
| 1324 | .child_by_field_name("left") |
| 1325 | .or_else(|| node.child_by_field_name("lhs")) |
| 1326 | .or_else(|| node.child_by_field_name("target")) |
| 1327 | .or_else(|| { |
| 1328 | if node.named_child_count() >= 2 { node.named_child(0) } else { None } |
| 1329 | }); |
| 1330 | let lhs_text = lhs.map(|l| self.text(l)).unwrap_or(""); |
| 1331 | let lhs_last = util::lhs_last_name() |
| 1332 | .captures(lhs_text) |
| 1333 | .and_then(|c| c.get(1)) |
| 1334 | .map(|m| m.as_str()); |
| 1335 | let rhs_text = self.text(rhs).trim(); |
| 1336 | if !(lhs_last.is_some() && lhs_last == Some(rhs_text)) { |
| 1337 | values.push(rhs); |
| 1338 | } |
| 1339 | } |
| 1340 | } |
| 1341 | Mode::Varinit => { |
| 1342 | // No `value` field on C# variable_declarator: the initializer |
| 1343 | // is the LAST named child — but an initializer-less declarator |
| 1344 | // has its NAME there. Require ≥2 named children and never pick |
| 1345 | // the name child. (Destructuring pattern gate never matches C#.) |
| 1346 | let name_child = node |
| 1347 | .child_by_field_name("name") |
| 1348 | .or_else(|| node.child_by_field_name("pattern")); |
no test coverage detected