Skip to content

Commit e720083

Browse files
committed
fix(native): compute complexity/cfg for prototype method definitions
`emit_js_prototype_method` and `extract_js_prototype_object_literal` were emitting `complexity: None` / `cfg: None` for every function- expression and method_definition RHS, unlike every other method/ function handler in the Rust extractor. Call `compute_all_metrics` and `build_function_cfg` at both sites. Add assertions to the 3 affected prototype unit tests to guard this. Closes #1340
1 parent 5baf98c commit e720083

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,8 @@ fn emit_js_prototype_method(class_name: &str, method_name: &str, rhs: &Node, sou
368368
line: start_line(rhs),
369369
end_line: Some(end_line(rhs)),
370370
decorators: None,
371-
complexity: None,
372-
cfg: None,
371+
complexity: compute_all_metrics(rhs, source, "javascript"),
372+
cfg: build_function_cfg(rhs, "javascript", source),
373373
children: None,
374374
});
375375
}
@@ -398,8 +398,8 @@ fn extract_js_prototype_object_literal(class_name: &str, obj_node: &Node, source
398398
line: start_line(&child),
399399
end_line: Some(end_line(&child)),
400400
decorators: None,
401-
complexity: None,
402-
cfg: None,
401+
complexity: compute_all_metrics(&child, source, "javascript"),
402+
cfg: build_function_cfg(&child, "javascript", source),
403403
children: None,
404404
});
405405
}
@@ -2448,7 +2448,10 @@ mod tests {
24482448
);
24492449
let def = s.definitions.iter().find(|d| d.name == "C.foo");
24502450
assert!(def.is_some(), "C.foo definition missing; got: {:?}", s.definitions.iter().map(|d| &d.name).collect::<Vec<_>>());
2451-
assert_eq!(def.unwrap().kind, "method");
2451+
let def = def.unwrap();
2452+
assert_eq!(def.kind, "method");
2453+
assert!(def.complexity.is_some(), "C.foo should have complexity metrics");
2454+
assert!(def.cfg.is_some(), "C.foo should have a CFG");
24522455
}
24532456

24542457
#[test]
@@ -2475,7 +2478,10 @@ mod tests {
24752478
let foo = s.definitions.iter().find(|d| d.name == "C.foo");
24762479
let bar = s.definitions.iter().find(|d| d.name == "C.bar");
24772480
assert!(foo.is_some(), "C.foo missing");
2478-
assert_eq!(foo.unwrap().kind, "method");
2481+
let foo = foo.unwrap();
2482+
assert_eq!(foo.kind, "method");
2483+
assert!(foo.complexity.is_some(), "C.foo should have complexity metrics");
2484+
assert!(foo.cfg.is_some(), "C.foo should have a CFG");
24792485
assert!(bar.is_some(), "C.bar missing");
24802486
}
24812487

@@ -2489,7 +2495,10 @@ mod tests {
24892495
);
24902496
let def = s.definitions.iter().find(|d| d.name == "C.greet");
24912497
assert!(def.is_some(), "C.greet definition missing; got: {:?}", s.definitions.iter().map(|d| &d.name).collect::<Vec<_>>());
2492-
assert_eq!(def.unwrap().kind, "method");
2498+
let def = def.unwrap();
2499+
assert_eq!(def.kind, "method");
2500+
assert!(def.complexity.is_some(), "C.greet should have complexity metrics");
2501+
assert!(def.cfg.is_some(), "C.greet should have a CFG");
24932502
}
24942503

24952504
#[test]

0 commit comments

Comments
 (0)