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

Method quoted_identifier

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

The name a string literal spells when it is a plain identifier: `'svc'` or `"getItems"` → the text between the quotes. None for anything else, including a string with an escape or a character no identifier can hold. Mirrors quotedIdentifier in tree-sitter.ts.

(&self, node: Node<'t>)

Source from the content-addressed store, hash-verified

266 /// including a string with an escape or a character no identifier can
267 /// hold. Mirrors quotedIdentifier in tree-sitter.ts.
268 fn quoted_identifier(&self, node: Node<'t>) -> Option<&'t str> {
269 if node.kind() != "string" {
270 return None;
271 }
272 let text = self.text(node);
273 let quoted = text.len() >= 2
274 && (text.starts_with('\'') || text.starts_with('"'))
275 && text.ends_with(&text[..1]);
276 if !quoted {
277 return None;
278 }
279 let key = &text[1..text.len() - 1];
280 let mut chars = key.chars();
281 let first = chars.next()?;
282 if !(first.is_ascii_alphabetic() || first == '_' || first == '$')
283 || !chars.all(|c| c.is_ascii_alphanumeric() || c == '_' || c == '$')
284 {
285 return None;
286 }
287 Some(key)
288 }
289
290 // --- reactComponentHoc / extractReactComponentNode (#841) --------------------
291

Callers 2

common_js_export_nameMethod · 0.80
this_subscript_ofMethod · 0.80

Calls 4

lenMethod · 0.80
nextMethod · 0.80
textMethod · 0.65
allMethod · 0.65

Tested by

no test coverage detected