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

Method constructor_member

codegraph-kernel/src/tsjs/extractors.rs:197–233  ·  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

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