@@ -21,33 +21,6 @@ import {
2121} from "../util/nodeSelectors" ;
2222import { elseExtractor , elseIfExtractor } from "./elseIfExtractor" ;
2323
24- // Generated by the following command:
25- // `curl https://raw.githubusercontent.com/tree-sitter/tree-sitter-rust/36ae187ed6dd3803a8a89dbb54f3124c8ee74662/src/node-types.STATEMENT_TYPES | jq '[.[] | select(.type == "_declaration_statement") | .subtypes[].type, "expression_statement"]'`
26- const STATEMENT_TYPES = [
27- "associated_type" ,
28- "attribute_item" ,
29- "const_item" ,
30- "empty_statement" ,
31- "enum_item" ,
32- "extern_crate_declaration" ,
33- "foreign_mod_item" ,
34- "impl_item" ,
35- "inner_attribute_item" ,
36- "let_declaration" ,
37- "macro_definition" ,
38- "macro_invocation" ,
39- "function_item" ,
40- "function_signature_item" ,
41- "mod_item" ,
42- "static_item" ,
43- "struct_item" ,
44- "trait_item" ,
45- "type_item" ,
46- "union_item" ,
47- "use_declaration" ,
48- "expression_statement" ,
49- ] ;
50-
5124/**
5225 * Returns "impl_item[type]" node higher in the chain
5326 * @param node The node which we will start our search from
@@ -78,60 +51,6 @@ function traitBoundExtractor(
7851 } ;
7952}
8053
81- /**
82- * Returns the return value node for a given block if we are in a block that has
83- * a return value. If the return value expression uses the return keyword then
84- * we return the value itself otherwise we just return the expression
85- * @param node The node which we might match
86- * @returns The return value node
87- */
88- function returnValueFinder ( node : Node ) {
89- if ( node . type !== "block" ) {
90- return null ;
91- }
92-
93- const { lastNamedChild } = node ;
94-
95- // The return expression will always be the last statement or expression in
96- // the block
97- if ( lastNamedChild == null ) {
98- return null ;
99- }
100-
101- // If the final name child is an expression statement not a raw expression
102- // then we only treat it as a return value if it is a return expression.
103- // Otherwise it is just a normal statement that doesn't return anything
104- if ( lastNamedChild . type === "expression_statement" ) {
105- const expression = lastNamedChild . child ( 0 ) ! ;
106-
107- if ( expression . type === "return_expression" ) {
108- return expression . child ( 1 ) ;
109- }
110-
111- return null ;
112- }
113-
114- // Any other type of statement is not a return statement so we should not
115- // match it
116- if ( STATEMENT_TYPES . includes ( lastNamedChild . type ) ) {
117- return null ;
118- }
119-
120- // NB: At this point we have now excluded all statement types of the only other
121- // possible node is an expression node
122-
123- // If it is a return expression then we zoom down to the actual value of the
124- // return expression. This happens when they say `return foo` with no
125- // trailing semicolon
126- if ( lastNamedChild . type === "return_expression" ) {
127- return lastNamedChild . child ( 1 ) ;
128- }
129-
130- // At this point it is an expression which is not a return expression so we
131- // just return it as the return value of the block
132- return lastNamedChild ;
133- }
134-
13554const nodeMatchers : Partial <
13655 Record < SimpleScopeTypeType , NodeMatcherAlternative >
13756> = {
@@ -196,15 +115,6 @@ const nodeMatchers: Partial<
196115 ) ,
197116 trailingMatcher ( [ "field_initializer[name]" , "field_pattern[name]" ] , [ ":" ] ) ,
198117 ) ,
199- value : cascadingMatcher (
200- leadingMatcher ( [ "let_declaration[value]" ] , [ "=" ] ) ,
201- leadingMatcher (
202- [ "field_initializer[value]" , "field_pattern[pattern]" ] ,
203- [ ":" ] ,
204- ) ,
205- patternMatcher ( "meta_item[value]" , "const_item[value]" ) ,
206- matcher ( returnValueFinder ) ,
207- ) ,
208118 branch : cascadingMatcher (
209119 patternMatcher ( "match_arm" ) ,
210120 matcher ( patternFinder ( "else_clause" ) , elseExtractor ( "if_expression" ) ) ,
0 commit comments