@@ -43,14 +43,44 @@ impl Getter for MozjsCode {
43
43
44
44
let typ = node. kind_id ( ) ;
45
45
match typ. into ( ) {
46
- Function | GeneratorFunction | FunctionDeclaration | GeneratorFunctionDeclaration => {
47
- NodeKind :: Function
48
- }
46
+ Function
47
+ | MethodDefinition
48
+ | GeneratorFunction
49
+ | FunctionDeclaration
50
+ | GeneratorFunctionDeclaration => NodeKind :: Function ,
49
51
Class | ClassDeclaration => NodeKind :: Class ,
50
52
Program => NodeKind :: Unit ,
51
53
_ => NodeKind :: Unknown ,
52
54
}
53
55
}
56
+
57
+ fn get_func_space_name < ' a > ( node : & Node , code : & ' a [ u8 ] ) -> Option < & ' a str > {
58
+ if let Some ( name) = node. child_by_field_name ( "name" ) {
59
+ let code = & code[ name. start_byte ( ) ..name. end_byte ( ) ] ;
60
+ std:: str:: from_utf8 ( code) . ok ( )
61
+ } else {
62
+ // We can be in a pair: foo: function() {}
63
+ // Or in a variable declaration: var aFun = function() {}
64
+ if let Some ( parent) = node. parent ( ) {
65
+ match parent. kind_id ( ) . into ( ) {
66
+ Mozjs :: Pair => {
67
+ if let Some ( name) = parent. child_by_field_name ( "key" ) {
68
+ let code = & code[ name. start_byte ( ) ..name. end_byte ( ) ] ;
69
+ return std:: str:: from_utf8 ( code) . ok ( ) ;
70
+ }
71
+ }
72
+ Mozjs :: VariableDeclarator => {
73
+ if let Some ( name) = parent. child_by_field_name ( "name" ) {
74
+ let code = & code[ name. start_byte ( ) ..name. end_byte ( ) ] ;
75
+ return std:: str:: from_utf8 ( code) . ok ( ) ;
76
+ }
77
+ }
78
+ _ => { }
79
+ }
80
+ }
81
+ Some ( "<anonymous>" )
82
+ }
83
+ }
54
84
}
55
85
56
86
impl Getter for JavascriptCode {
@@ -59,14 +89,44 @@ impl Getter for JavascriptCode {
59
89
60
90
let typ = node. kind_id ( ) ;
61
91
match typ. into ( ) {
62
- Function | GeneratorFunction | FunctionDeclaration | GeneratorFunctionDeclaration => {
63
- NodeKind :: Function
64
- }
92
+ Function
93
+ | MethodDefinition
94
+ | GeneratorFunction
95
+ | FunctionDeclaration
96
+ | GeneratorFunctionDeclaration => NodeKind :: Function ,
65
97
Class | ClassDeclaration => NodeKind :: Class ,
66
98
Program => NodeKind :: Unit ,
67
99
_ => NodeKind :: Unknown ,
68
100
}
69
101
}
102
+
103
+ fn get_func_space_name < ' a > ( node : & Node , code : & ' a [ u8 ] ) -> Option < & ' a str > {
104
+ if let Some ( name) = node. child_by_field_name ( "name" ) {
105
+ let code = & code[ name. start_byte ( ) ..name. end_byte ( ) ] ;
106
+ std:: str:: from_utf8 ( code) . ok ( )
107
+ } else {
108
+ // We can be in a pair: foo: function() {}
109
+ // Or in a variable declaration: var aFun = function() {}
110
+ if let Some ( parent) = node. parent ( ) {
111
+ match parent. kind_id ( ) . into ( ) {
112
+ Mozjs :: Pair => {
113
+ if let Some ( name) = parent. child_by_field_name ( "key" ) {
114
+ let code = & code[ name. start_byte ( ) ..name. end_byte ( ) ] ;
115
+ return std:: str:: from_utf8 ( code) . ok ( ) ;
116
+ }
117
+ }
118
+ Mozjs :: VariableDeclarator => {
119
+ if let Some ( name) = parent. child_by_field_name ( "name" ) {
120
+ let code = & code[ name. start_byte ( ) ..name. end_byte ( ) ] ;
121
+ return std:: str:: from_utf8 ( code) . ok ( ) ;
122
+ }
123
+ }
124
+ _ => { }
125
+ }
126
+ }
127
+ Some ( "<anonymous>" )
128
+ }
129
+ }
70
130
}
71
131
72
132
impl Getter for TypescriptCode {
@@ -75,14 +135,44 @@ impl Getter for TypescriptCode {
75
135
76
136
let typ = node. kind_id ( ) ;
77
137
match typ. into ( ) {
78
- Function | GeneratorFunction | FunctionDeclaration | GeneratorFunctionDeclaration => {
79
- NodeKind :: Function
80
- }
138
+ Function
139
+ | MethodDefinition
140
+ | GeneratorFunction
141
+ | FunctionDeclaration
142
+ | GeneratorFunctionDeclaration => NodeKind :: Function ,
81
143
Class | ClassDeclaration => NodeKind :: Class ,
82
144
Program => NodeKind :: Unit ,
83
145
_ => NodeKind :: Unknown ,
84
146
}
85
147
}
148
+
149
+ fn get_func_space_name < ' a > ( node : & Node , code : & ' a [ u8 ] ) -> Option < & ' a str > {
150
+ if let Some ( name) = node. child_by_field_name ( "name" ) {
151
+ let code = & code[ name. start_byte ( ) ..name. end_byte ( ) ] ;
152
+ std:: str:: from_utf8 ( code) . ok ( )
153
+ } else {
154
+ // We can be in a pair: foo: function() {}
155
+ // Or in a variable declaration: var aFun = function() {}
156
+ if let Some ( parent) = node. parent ( ) {
157
+ match parent. kind_id ( ) . into ( ) {
158
+ Mozjs :: Pair => {
159
+ if let Some ( name) = parent. child_by_field_name ( "key" ) {
160
+ let code = & code[ name. start_byte ( ) ..name. end_byte ( ) ] ;
161
+ return std:: str:: from_utf8 ( code) . ok ( ) ;
162
+ }
163
+ }
164
+ Mozjs :: VariableDeclarator => {
165
+ if let Some ( name) = parent. child_by_field_name ( "name" ) {
166
+ let code = & code[ name. start_byte ( ) ..name. end_byte ( ) ] ;
167
+ return std:: str:: from_utf8 ( code) . ok ( ) ;
168
+ }
169
+ }
170
+ _ => { }
171
+ }
172
+ }
173
+ Some ( "<anonymous>" )
174
+ }
175
+ }
86
176
}
87
177
88
178
impl Getter for TsxCode {
@@ -91,14 +181,44 @@ impl Getter for TsxCode {
91
181
92
182
let typ = node. kind_id ( ) ;
93
183
match typ. into ( ) {
94
- Function | GeneratorFunction | FunctionDeclaration | GeneratorFunctionDeclaration => {
95
- NodeKind :: Function
96
- }
184
+ Function
185
+ | MethodDefinition
186
+ | GeneratorFunction
187
+ | FunctionDeclaration
188
+ | GeneratorFunctionDeclaration => NodeKind :: Function ,
97
189
Class | ClassDeclaration => NodeKind :: Class ,
98
190
Program => NodeKind :: Unit ,
99
191
_ => NodeKind :: Unknown ,
100
192
}
101
193
}
194
+
195
+ fn get_func_space_name < ' a > ( node : & Node , code : & ' a [ u8 ] ) -> Option < & ' a str > {
196
+ if let Some ( name) = node. child_by_field_name ( "name" ) {
197
+ let code = & code[ name. start_byte ( ) ..name. end_byte ( ) ] ;
198
+ std:: str:: from_utf8 ( code) . ok ( )
199
+ } else {
200
+ // We can be in a pair: foo: function() {}
201
+ // Or in a variable declaration: var aFun = function() {}
202
+ if let Some ( parent) = node. parent ( ) {
203
+ match parent. kind_id ( ) . into ( ) {
204
+ Mozjs :: Pair => {
205
+ if let Some ( name) = parent. child_by_field_name ( "key" ) {
206
+ let code = & code[ name. start_byte ( ) ..name. end_byte ( ) ] ;
207
+ return std:: str:: from_utf8 ( code) . ok ( ) ;
208
+ }
209
+ }
210
+ Mozjs :: VariableDeclarator => {
211
+ if let Some ( name) = parent. child_by_field_name ( "name" ) {
212
+ let code = & code[ name. start_byte ( ) ..name. end_byte ( ) ] ;
213
+ return std:: str:: from_utf8 ( code) . ok ( ) ;
214
+ }
215
+ }
216
+ _ => { }
217
+ }
218
+ }
219
+ Some ( "<anonymous>" )
220
+ }
221
+ }
102
222
}
103
223
104
224
impl Getter for RustCode {
0 commit comments