Skip to content

Commit f0ec6b2

Browse files
committed
fix(linter/no-unused-private-class-members): fix false positive in default param
1 parent 7c42ea0 commit f0ec6b2

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

crates/oxc_linter/src/rules/eslint/no_unused_private_class_members.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ fn is_value_context(kind: &AstNode, semantic: &Semantic<'_>) -> bool {
215215
| AstKind::UnaryExpression(_)
216216
| AstKind::IfStatement(_)
217217
| AstKind::SpreadElement(_)
218-
| AstKind::LogicalExpression(_) => true,
218+
| AstKind::LogicalExpression(_)
219+
| AstKind::AssignmentPattern(_) => true,
219220
AstKind::ExpressionStatement(_) => {
220221
let parent_node = semantic.nodes().parent_node(kind.id());
221222
if let AstKind::FunctionBody(_) = parent_node.kind()
@@ -458,6 +459,9 @@ fn test() {
458459
r"class C { #method() { return 42; } static { const obj = new C(); obj.#method(); } }",
459460
r"class C { #field = 1; static { const getField = obj => { return obj.#field; }; } }",
460461
r"export class Database<const S extends idb.DBSchema> { readonly #db: Promise<idb.IDBPDatabase<S>>; constructor(name: string, version: number, hooks: idb.OpenDBCallbacks<S>) { this.#db = idb.openDB<S>(name, version, hooks); } async read() { let db = await this.#db; } }",
462+
r"export class A { #x; constructor(x: number) { this.#x = x; } get(y = this.#x) { return y; } }",
463+
r"class B { #value = 42; method(param = this.#value) { return param * 2; } }",
464+
r"class C { #arr = [1, 2, 3]; process(items = this.#arr) { return items.map(x => x * 2); } }",
461465
];
462466

463467
let fail = vec![

0 commit comments

Comments
 (0)