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

Function normalize

codegraph-kernel/src/tsjs/fnref.rs:123–138  ·  view source on GitHub ↗

normalizeValue for the TS/JS spec: bare identifiers, plus the `this. ` member_expression special form (object EXACTLY `this`).

(node: Node<'t>, src: &str)

Source from the content-addressed store, hash-verified

121/// normalizeValue for the TS/JS spec: bare identifiers, plus the
122/// `this.<member>` member_expression special form (object EXACTLY `this`).
123fn normalize<'t>(node: Node<'t>, src: &str) -> Vec<(String, Node<'t>)> {
124 match node.kind() {
125 "identifier" | "shorthand_property_identifier" => vec![(src[node.byte_range()].to_string(), node)],
126 "member_expression" => {
127 let obj = node.child_by_field_name("object");
128 let prop = node.child_by_field_name("property");
129 if let (Some(o), Some(p)) = (obj, prop) {
130 if o.kind() == "this" && p.kind() == "property_identifier" {
131 return vec![(format!("this.{}", &src[p.byte_range()]), p)];
132 }
133 }
134 vec![]
135 }
136 _ => vec![],
137 }
138}

Callers 1

captureFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected