Skip to content

Commit

Permalink
Fix perfer-const
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 committed Jan 30, 2024
1 parent 4e01616 commit c58349f
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions crates/swc_ecma_lints/src/rules/prefer_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,15 @@ impl Visit for PreferConst {

fn visit_assign_expr(&mut self, assign_expr: &AssignExpr) {
if let op!("=") = assign_expr.op {
if let AssignTarget::Pat(pat) = &assign_expr.left {
match pat {
match &assign_expr.left {
AssignTarget::Simple(SimpleAssignTarget::Ident(l)) => {
self.consider_mutation_for_ident(l, false);
}

AssignTarget::Pat(pat) => match pat {
AssignTargetPat::Array(ArrayPat { elems, .. }) => {
elems.iter().flatten().for_each(|elem| {
self.consider_mutation(elem, false);
self.consider_mutation(elem, true);
})
}
AssignTargetPat::Object(ObjectPat { props, .. }) => {
Expand All @@ -254,7 +258,8 @@ impl Visit for PreferConst {
});
}
AssignTargetPat::Invalid(_) => {}
}
},
_ => (),
}
}

Expand Down

0 comments on commit c58349f

Please sign in to comment.