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

Method common_js_export_name

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

143 /// other assignment. The node must be the assignment's whole right-hand
144 /// side. Mirrors TreeSitterExtractor.commonJsExportName.
145 fn common_js_export_name(&self, assignment: Node<'t>, value: Node<'t>) -> Option<String> {
146 let right = assignment.child_by_field_name("right")?;
147 if right.start_byte() != value.start_byte() || right.end_byte() != value.end_byte() {
148 return None;
149 }
150 let left = assignment.child_by_field_name("left")?;
151 if !matches!(left.kind(), "member_expression" | "subscript_expression") {
152 return None;
153 }
154 let object = left.child_by_field_name("object")?;
155 if !matches!(self.text(object), "exports" | "module.exports") {
156 return None;
157 }
158 if left.kind() == "subscript_expression" {
159 return self.quoted_identifier(left.child_by_field_name("index")?).map(str::to_string);
160 }
161 let property = left.child_by_field_name("property")?;
162 if property.kind() != "property_identifier" {
163 return None;
164 }
165 Some(self.text(property).to_string())
166 }
167
168 /// The name a string literal spells when it is a plain identifier: `'svc'`
169 /// or `"getItems"` → the text between the quotes. None for anything else,

Callers 1

extract_functionMethod · 0.80

Calls 3

mapMethod · 0.80
quoted_identifierMethod · 0.80
textMethod · 0.65

Tested by

no test coverage detected