| 1909 | // --- function-as-value capture (#756) — DART_SPEC --------------------- |
| 1910 | |
| 1911 | fn maybe_capture_fn_refs(&mut self, node: Node<'t>) { |
| 1912 | let (mode, field): (&str, &str) = match node.kind() { |
| 1913 | "arguments" => ("args", ""), |
| 1914 | "assignment_expression" => ("rhs", "right"), |
| 1915 | "pair" => ("value", "value"), |
| 1916 | "list_literal" => ("list", ""), |
| 1917 | "static_final_declaration" => ("varinit", ""), |
| 1918 | _ => return, |
| 1919 | }; |
| 1920 | if self.stack.is_empty() { |
| 1921 | return; |
| 1922 | } |
| 1923 | let from = self.top_row(); |
| 1924 | |
| 1925 | let mut values: Vec<Node<'t>> = Vec::new(); |
| 1926 | match mode { |
| 1927 | "args" | "list" => { |
| 1928 | let mut cursor = node.walk(); |
| 1929 | for c in node.named_children(&mut cursor) { |
| 1930 | values.push(c); |
| 1931 | } |
| 1932 | } |
| 1933 | "rhs" => { |
| 1934 | if let Some(rhs) = node.child_by_field_name(field) { |
| 1935 | let lhs = node |
| 1936 | .child_by_field_name("left") |
| 1937 | .or_else(|| node.child_by_field_name("lhs")) |
| 1938 | .or_else(|| node.child_by_field_name("target")) |
| 1939 | .or_else(|| { |
| 1940 | if node.named_child_count() >= 2 { |
| 1941 | node.named_child(0) |
| 1942 | } else { |
| 1943 | None |
| 1944 | } |
| 1945 | }); |
| 1946 | let lhs_text = lhs.map(|l| self.text(l)).unwrap_or(""); |
| 1947 | let lhs_last = util::lhs_last_name() |
| 1948 | .captures(lhs_text) |
| 1949 | .and_then(|c| c.get(1)) |
| 1950 | .map(|m| m.as_str()); |
| 1951 | if !(lhs_last.is_some() && lhs_last == Some(self.text(rhs).trim())) { |
| 1952 | values.push(rhs); |
| 1953 | } |
| 1954 | } |
| 1955 | } |
| 1956 | "value" => { |
| 1957 | let v = node.child_by_field_name(field).or_else(|| { |
| 1958 | let count = node.named_child_count(); |
| 1959 | if count > 0 { node.named_child(count - 1) } else { None } |
| 1960 | }); |
| 1961 | if let Some(v) = v { |
| 1962 | values.push(v); |
| 1963 | } |
| 1964 | } |
| 1965 | _ => { |
| 1966 | // varinit, NO field (function-ref.ts:471-487): the last named |
| 1967 | // child, requiring ≥2 named children; the name-field guard is |
| 1968 | // inert (static_final_declaration has no name/pattern field). |