(&mut self, node: Node<'t>)
| 1304 | // --- function-as-value refs (SWIFT_SPEC, function-ref.ts:288) ------------------- |
| 1305 | |
| 1306 | fn maybe_capture_fn_refs(&mut self, node: Node<'t>) { |
| 1307 | enum Mode { |
| 1308 | Args, |
| 1309 | Rhs, |
| 1310 | List, |
| 1311 | Varinit, |
| 1312 | } |
| 1313 | let mode = match node.kind() { |
| 1314 | "value_arguments" => Mode::Args, |
| 1315 | "assignment" => Mode::Rhs, // field 'result' |
| 1316 | "array_literal" => Mode::List, |
| 1317 | "property_declaration" => Mode::Varinit, // field 'value' |
| 1318 | _ => return, |
| 1319 | }; |
| 1320 | if self.stack.is_empty() { |
| 1321 | return; |
| 1322 | } |
| 1323 | let from = self.top_row(); |
| 1324 | |
| 1325 | let mut values: Vec<Node> = Vec::new(); |
| 1326 | match mode { |
| 1327 | Mode::Args | Mode::List => { |
| 1328 | for c in node.named_children(&mut node.walk()) { |
| 1329 | values.push(c); |
| 1330 | } |
| 1331 | } |
| 1332 | Mode::Rhs => { |
| 1333 | if let Some(rhs) = node.child_by_field_name("result") { |
| 1334 | // Param-storage skip — swift's LHS field is `target`. |
| 1335 | let lhs = node |
| 1336 | .child_by_field_name("left") |
| 1337 | .or_else(|| node.child_by_field_name("lhs")) |
| 1338 | .or_else(|| node.child_by_field_name("target")) |
| 1339 | .or_else(|| { |
| 1340 | if node.named_child_count() >= 2 { node.named_child(0) } else { None } |
| 1341 | }); |
| 1342 | let lhs_text = lhs.map(|l| self.text(l)).unwrap_or(""); |
| 1343 | let lhs_last = util::lhs_last_name() |
| 1344 | .captures(lhs_text) |
| 1345 | .and_then(|c| c.get(1)) |
| 1346 | .map(|m| m.as_str()); |
| 1347 | let rhs_text = self.text(rhs).trim(); |
| 1348 | if !(lhs_last.is_some() && lhs_last == Some(rhs_text)) { |
| 1349 | values.push(rhs); |
| 1350 | } |
| 1351 | } |
| 1352 | } |
| 1353 | Mode::Varinit => { |
| 1354 | // Destructuring gate: swift's name field is a `pattern` node — |
| 1355 | // never in the pattern-kind set → never skipped. |
| 1356 | let name_child = node |
| 1357 | .child_by_field_name("name") |
| 1358 | .or_else(|| node.child_by_field_name("pattern")); |
| 1359 | let is_destructuring = name_child |
| 1360 | .map(|nc| { |
| 1361 | matches!( |
| 1362 | nc.kind(), |
| 1363 | "object_pattern" | "array_pattern" | "tuple_pattern" | "struct_pattern" |
no test coverage detected