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

Function normalize

codegraph-kernel/src/tsjs/fnref.rs:121–136  ·  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

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

Callers 1

captureFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected