Repository: swc-project/swc (rust)

Issue:
`const` reassignment works in arrow function
### Describe the bug

`const` reassignment works in arrow function, while it is supposed to throw error. 

It throws error if we use a normal function like this , but doesn't while using arrow function
```javascript 
 function click() {
  const hello = "hi";
  hello = "hi"
}
```

### Input code

```typescript
const click = () => {
  const hello = "hi";
  hello = "hi"
}
```


### Config

```json
{
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "jsx": false
    },
    "target": "es3",
    "loose": false,
    "minify": {
      "compress": false,
      "mangle": false
    }
  },
  "module": {
    "type": "commonjs"
  },
  "minify": false,
  "isModule": false
}
```


### Playground link

https://play.swc.rs/?version=1.3.10&code=H4sIAAAAAAAAA0vOzysuUUjOyUzOVrBV0NBUsLVTqOZSUEgGi2ek5uTkA8WVMjKVrIGiyHyuWgD%2BEONwPAAAAA%3D%3D&config=H4sIAAAAAAAAA0WMSwrDMAxE76K1d93lDj2EcJXg4B8eB2KM716ZumQlMe%2FNdDphaeuUuUDK%2FNBi5Zs2EhsYtrhcyaim0c4eMgxVLofUqeClzKcEWdRQcNHtbS7ZFHIR4EEcD%2F83hw6F9Llm0Km2rHdWQoonaDxDq%2BzwXvav%2FgVSbmzluwAAAA%3D%3D

### Expected behavior

```sh
  x cannot reassign to a variable declared with `const`
   ,-[input.js:2:3]
 2 | const hello = "hi";
   :       ^^|^^
   :         `-- const variable was declared here
 3 |   hello = "hi"
   :   ^^|^^
   :     `-- cannot reassign
   `----
```

### Actual behavior

```javascript
var click = function() {
    var hello = "hi";
    hello = "hi";
};
```

### Version

1.3.10

### Additional context

_No response_

Pull request:
Fix const-assign in function expressions
<!-- Note: CI script will automatically rebase your PR so please do not rebase unless required -->

<!-- Thanks for submitting a pull request! Please provide enough information so that others can review your pull request. -->

**Description:**

`is_pat_decl` was previously set to `true` while visiting all children of a variable declaration, meaning function expressions would not be checked. Fixed by only setting `is_pat_decl` while visiting the initialization of the variable declarator.

<!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? -->

**BREAKING CHANGE:**

No

<!--
If this PR introduces a breaking change, it must contain a notice for it to be included in the CHANGELOG. Add description or remove entirely if not breaking.

You may need to update `MIGRATION.md` for the breaking changes.
-->

**Related issue (if exists):**

Fixes #6252


Patch:
diff --git a/crates/swc_ecma_lints/src/rules/const_assign.rs b/crates/swc_ecma_lints/src/rules/const_assign.rs
index 22caf8473b..22a36fea90 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);
     }
 }
 


Test patch:
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 6efcb5c6d9..7c2340f27e 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 af085d34d2..b90dd14c01 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
+    `----