MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / constructor_member

Method constructor_member

codegraph-kernel/src/tsjs/extractors.rs:195–231  ·  view source on GitHub ↗

The constructor (or class) a function assigned to `Ctor.prototype.m` or `Ctor.m` is a method of, when `Ctor` is a function or class declared in the scope the assignment is written in (#2966). None for anything else: another target, a constructor declared elsewhere or later, a generated or minified bundle. The function must be the assignment's whole right-hand side. Mirrors TreeSitterExtractor.cons

(&self, assignment: Node<'t>, value: Node<'t>)

Source from the content-addressed store, hash-verified

193 /// or minified bundle. The function must be the assignment's whole
194 /// right-hand side. Mirrors TreeSitterExtractor.constructorMember.
195 pub(super) fn constructor_member(&self, assignment: Node<'t>, value: Node<'t>) -> Option<ConstructorMember> {
196 if !self.owns_object_literals() {
197 return None;
198 }
199 let right = assignment.child_by_field_name("right")?;
200 if right.start_byte() != value.start_byte() || right.end_byte() != value.end_byte() {
201 return None;
202 }
203 let left = assignment.child_by_field_name("left")?;
204 if left.kind() != "member_expression" {
205 return None;
206 }
207 let property = left.child_by_field_name("property")?;
208 if property.kind() != "property_identifier" {
209 return None;
210 }
211 let name = self.text(property);
212 if name == "prototype" {
213 return None;
214 }
215 let mut object = left.child_by_field_name("object")?;
216 let mut is_static = true;
217 if object.kind() == "member_expression" {
218 let link = object.child_by_field_name("property")?;
219 if link.kind() != "property_identifier" || self.text(link) != "prototype" {
220 return None;
221 }
222 object = object.child_by_field_name("object")?;
223 is_static = false;
224 }
225 if object.kind() != "identifier" {
226 return None;
227 }
228 let owner = self.text(object).to_string();
229 let &(row, kind) = self.scope_declarations.get(&(self.top_row(), owner.clone()))?;
230 Some(ConstructorMember { row, kind, owner, name: name.to_string(), is_static })
231 }
232
233 /// Extract a function assigned to `Ctor.prototype.m` / `Ctor.m` as method
234 /// `m` of `Ctor`: contained by it and qualified under it (`Ctor::m`), as a

Callers 2

extract_functionMethod · 0.80

Calls 4

owns_object_literalsMethod · 0.80
textMethod · 0.65
getMethod · 0.65
top_rowMethod · 0.45

Tested by

no test coverage detected