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

Method object_owner_path

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

objectOwnerPath: an assignment target's links written as plain names (`dw_page` → [dw_page], `App.utils.dom` → [App, utils, dom], `module.exports`, the module's export object, #2966), or None for anything else — `this.x`, `a[k]`, a call, another CommonJS export target (`exports.x`, `module.exports.x`), or a prototype.

(&self, left: Option<Node<'t>>)

Source from the content-addressed store, hash-verified

1140 /// anything else — `this.x`, `a[k]`, a call, another CommonJS export
1141 /// target (`exports.x`, `module.exports.x`), or a prototype.
1142 fn object_owner_path(&self, left: Option<Node<'t>>) -> Option<Vec<String>> {
1143 let mut path: Vec<String> = Vec::new();
1144 let mut cur = left?;
1145 while cur.kind() == "member_expression" {
1146 let property = cur.child_by_field_name("property")?;
1147 if property.kind() != "property_identifier" {
1148 return None;
1149 }
1150 path.push(self.text(property).to_string());
1151 cur = cur.child_by_field_name("object")?;
1152 }
1153 if cur.kind() != "identifier" {
1154 return None;
1155 }
1156 let root = self.text(cur);
1157 // `path` holds the links last to first here.
1158 let export_object = root == "module" && path.len() == 1 && path[0] == "exports";
1159 if !export_object && (root == "module" || root == "exports" || path.iter().any(|p| p == "prototype")) {
1160 return None;
1161 }
1162 path.push(root.to_string());
1163 path.reverse();
1164 Some(path)
1165 }
1166
1167 // --- object-literal / store helpers -------------------------------------------------
1168

Callers 1

Calls 3

pushMethod · 0.80
lenMethod · 0.80
textMethod · 0.65

Tested by

no test coverage detected