diff --git a/crates/swc/tests/errors/lints/const-assign/1/input.js b/crates/swc/tests/errors/lints/const-assign/1/input.js index 6efcb5c6d91..7c2340f27e7 100644 --- a/crates/swc/tests/errors/lints/const-assign/1/input.js +++ b/crates/swc/tests/errors/lints/const-assign/1/input.js @@ -31,3 +31,8 @@ b &&= 10; c ||= 10; d ??= 10; + +const fn = () => { + const e = 100; + e = 200; +}; diff --git a/crates/swc/tests/errors/lints/const-assign/1/output.swc-stderr b/crates/swc/tests/errors/lints/const-assign/1/output.swc-stderr index af085d34d2a..b90dd14c012 100644 --- a/crates/swc/tests/errors/lints/const-assign/1/output.swc-stderr +++ b/crates/swc/tests/errors/lints/const-assign/1/output.swc-stderr @@ -518,3 +518,13 @@ : | : `-- cannot reassign `---- + + x cannot reassign to a variable declared with `const` + ,-[36:3] + 36 | const e = 100; + : | + : `-- const variable was declared here + 37 | e = 200; + : | + : `-- cannot reassign + `---- diff --git a/crates/swc_ecma_lints/src/rules/const_assign.rs b/crates/swc_ecma_lints/src/rules/const_assign.rs index 22caf8473b0..22a36fea900 100644 --- a/crates/swc_ecma_lints/src/rules/const_assign.rs +++ b/crates/swc_ecma_lints/src/rules/const_assign.rs @@ -108,11 +108,13 @@ impl Visit for ConstAssign { program.visit_children_with(self); } - fn visit_var_decl(&mut self, var_decl: &VarDecl) { + fn visit_var_declarator(&mut self, var_declarator: &VarDeclarator) { let old_is_pat_decl = self.is_pat_decl; self.is_pat_decl = true; - var_decl.visit_children_with(self); + var_declarator.name.visit_with(self); self.is_pat_decl = old_is_pat_decl; + + var_declarator.init.visit_with(self); } }