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

Method common_js_export_name

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

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