Skip to content

Commit 41d7811

Browse files
committed
fix(native): strip one surrounding quote pair in prototype object-literal key
`trim_matches` was stripping ALL quote chars (e.g. `"it's"` became `its`). Replace with strip_prefix + strip_suffix to remove exactly the outermost matching quote pair.
1 parent 0c26030 commit 41d7811

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

crates/codegraph-core/src/extractors/javascript.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -417,13 +417,19 @@ fn extract_js_prototype_object_literal(class_name: &str, obj_node: &Node, source
417417
let key_node = child.child_by_field_name("key");
418418
let value_node = child.child_by_field_name("value");
419419
if let (Some(key_node), Some(value_node)) = (key_node, value_node) {
420-
let method_name = if key_node.kind() == "string" {
421-
node_text(&key_node, source).replace(['\'', '"'], "")
420+
let method_name: &str = if key_node.kind() == "string" {
421+
let s = node_text(&key_node, source);
422+
// Strip exactly one matching pair of surrounding quote characters.
423+
// `trim_matches` would also strip embedded quotes; we only want the
424+
// outermost delimiter pair so `"it's"` stays `it's`.
425+
s.strip_prefix('"').and_then(|s| s.strip_suffix('"'))
426+
.or_else(|| s.strip_prefix('\'').and_then(|s| s.strip_suffix('\'')))
427+
.unwrap_or(s)
422428
} else {
423-
node_text(&key_node, source).to_string()
429+
node_text(&key_node, source)
424430
};
425431
if method_name.is_empty() { continue; }
426-
emit_js_prototype_method(class_name, &method_name, &value_node, source, symbols);
432+
emit_js_prototype_method(class_name, method_name, &value_node, source, symbols);
427433
}
428434
}
429435
_ => {}

0 commit comments

Comments
 (0)