Skip to content

Commit fde4f87

Browse files
feat(biome-js-analyze): add is_meaningful_read to semantic class reads
1 parent 6e05104 commit fde4f87

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

crates/biome_js_analyze/src/services/semantic_class.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ fn is_within_scope_without_shadowing(
874874

875875
/// Checks if the given node is used in an expression context
876876
/// (e.g., return, call arguments, conditionals, binary expressions).
877-
/// NOt limited to `this` references. Can be used for any node.
877+
/// NOt limited to `this` references. Can be used for any node, but requires more work e.g.
878878
/// Returns `true` if the read is meaningful, `false` otherwise.
879879
fn is_used_in_expression_context(node: &AnyCandidateForUsedInExpressionNode) -> bool {
880880
let mut current: JsSyntaxNode =
@@ -1272,8 +1272,10 @@ mod tests {
12721272
for descendant in root.descendants() {
12731273
// 1) Skip the identifier that is the class name (e.g. `Test` in `class Test {}`)
12741274
if AnyJsIdentifierBinding::can_cast(descendant.kind())
1275-
&& let Some(parent) = descendant.parent() && JsClassDeclaration::can_cast(parent.kind()) {
1276-
continue;
1275+
&& let Some(parent) = descendant.parent()
1276+
&& JsClassDeclaration::can_cast(parent.kind())
1277+
{
1278+
continue;
12771279
}
12781280

12791281
// Try to cast the node itself
@@ -1317,14 +1319,6 @@ mod tests {
13171319
case.description
13181320
);
13191321

1320-
println!(
1321-
"nodes found: {:?}",
1322-
nodes
1323-
.iter()
1324-
.map(|n| n.to_trimmed_text())
1325-
.collect::<Vec<_>>()
1326-
);
1327-
13281322
// Ensure the number of nodes matches expected
13291323
assert_eq!(
13301324
nodes.len(),
@@ -1436,6 +1430,21 @@ mod tests {
14361430
code: r#"class Test { method() { const sum = this.a + this.b; } }"#,
14371431
expected: vec![("sum", false), ("this.a", true), ("this.b", true)],
14381432
},
1433+
TestCase {
1434+
description: "binary expression nested parenthesis",
1435+
code: r#"class Test { method() { const sum = (((this.a + ((this.b * 2))))); } }"#,
1436+
expected: vec![("sum", false), ("this.a", true), ("this.b", true)],
1437+
},
1438+
TestCase {
1439+
description: "nested logical and conditional expressions",
1440+
code: r#"class Test { method() { const val = foo(this.a && (this.b ? this.c : 7)); } }"#,
1441+
expected: vec![
1442+
("val", false),
1443+
("this.a", true),
1444+
("this.b", true),
1445+
("this.c", true),
1446+
],
1447+
},
14391448
];
14401449

14411450
run_test_cases(&cases);

0 commit comments

Comments
 (0)