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

Method common_js_export_name

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

The property a CommonJS export assignment binds a function to — `exports.NAME = ` / `module.exports.NAME = `, or the same with the name in quotes, `exports["NAME"] = ` — or None for any other assignment. The node must be the assignment's whole right-hand side. Mirrors TreeSitterExtractor.commonJsExportName.

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

Source from the content-addressed store, hash-verified

164 /// other assignment. The node must be the assignment's whole right-hand
165 /// side. Mirrors TreeSitterExtractor.commonJsExportName.
166 fn common_js_export_name(&self, assignment: Node<'t>, value: Node<'t>) -> Option<String> {
167 let right = assignment.child_by_field_name("right")?;
168 if right.start_byte() != value.start_byte() || right.end_byte() != value.end_byte() {
169 return None;
170 }
171 let left = assignment.child_by_field_name("left")?;
172 if !matches!(left.kind(), "member_expression" | "subscript_expression") {
173 return None;
174 }
175 let object = left.child_by_field_name("object")?;
176 if !matches!(self.text(object), "exports" | "module.exports") {
177 return None;
178 }
179 if left.kind() == "subscript_expression" {
180 return self.quoted_identifier(left.child_by_field_name("index")?).map(str::to_string);
181 }
182 let property = left.child_by_field_name("property")?;
183 if property.kind() != "property_identifier" {
184 return None;
185 }
186 Some(self.text(property).to_string())
187 }
188
189 /// The constructor (or class) a function assigned to `Ctor.prototype.m` or
190 /// `Ctor.m` is a method of, when `Ctor` is a function or class declared in

Callers 1

extract_functionMethod · 0.80

Calls 3

mapMethod · 0.80
quoted_identifierMethod · 0.80
textMethod · 0.65

Tested by

no test coverage detected