Repository: swc-project/swc (rust)

Issue:
(Reopening) Cannot reassign to a variable declared with const" error with destructured function arguments in Typescript
### Describe the bug

This issue https://github.com/swc-project/swc/issues/3929 was closed as fixed but it's still failing in 1.2.152.


### Input code

```typescript
function fn1({x,y}: {x: string, y: string}): string {
    return x + y
}

function fn2({x,y}: {x: string, y: string}): string {
   const fn3: ({x,y}: {x: string, y: string}) => string = fn1
   return fn3({x,y})
}
```


### Config

_No response_

### Playground link

https://play.swc.rs/?version=1.2.152&code=H4sIAAAAAAAAA42OsQqAIBRF9%2FcVd0xqqTahfkYyXJ5gBor47ykhjnWnu5zD0TcrbyxD8zykMMUskYLE5Z3hc0JsN4v2kAhl7vC3YwSMiJSJdDct1YTfKmX58gVbJT4SsO2N3Gox9Y6Cv7Cg%2FADW9e751QAAAA%3D%3D&config=H4sIAAAAAAAAA0WNSwrDMAxE76J1ts0id%2BghjKsEF%2F%2FQKBBjfPfawSU7aebpqdIXlrZK2QhYxoQS1Vy0kZbMsOKy0kKKHu3Gg1tfjBysHWG8eudTAs92oeCi28sw2RSyMPBUJh7%2BT7YuCulzjqDez27hSu1xzDuH9wRVTm4%2FOkwQUrUAAAA%3D

### Expected behavior

```
function fn1({ x, y }) {
  return x + y;
}
function fn2({ x, y }) {
  const fn3 = fn1;
  return fn3({ x, y });
}
```

### Actual behavior

```
error: Cannot reassign to a variable declared with `const`
 --> input.ts:5:15
  |
5 | function fn2({x, y}: {x: string, y: string}): string {
  |               ^
  |
note: x was declared here
 --> input.ts:6:17
  |
6 |    const fn3: ({x,y}: {x: string, y: string}) => string = fn1
  |                 ^

error: Cannot reassign to a variable declared with `const`
 --> input.ts:5:18
  |
5 | function fn2({x, y}: {x: string, y: string}): string {
  |                  ^
  |
note: y was declared here
 --> input.ts:6:19
  |
6 |    const fn3: ({x,y}: {x: string, y: string}) => string = fn1
  |                   ^
```

### Version

1.2.152

### Additional context

_No response_

Pull request description:
fix(es/lints): Don't visit types while collecting `const`
**Description:**


**Related issue (if exists):**


 - Closes #3956

Patch:
diff --git a/crates/swc_ecma_lints/src/rules/const_assign.rs b/crates/swc_ecma_lints/src/rules/const_assign.rs
index 9ec91847d8..f6de7c2fa8 100644
--- a/crates/swc_ecma_lints/src/rules/const_assign.rs
+++ b/crates/swc_ecma_lints/src/rules/const_assign.rs
@@ -92,6 +92,8 @@ struct Collector<'a> {
 }
 
 impl Visit for Collector<'_> {
+    noop_visit_type!();
+
     fn visit_assign_pat_prop(&mut self, p: &AssignPatProp) {
         p.visit_children_with(self);
 


Test patch:
diff --git a/crates/swc_css_codegen/tests/fixture.rs b/crates/swc_css_codegen/tests/fixture.rs
index 34c1d08dac..a18d892ac9 100644
--- a/crates/swc_css_codegen/tests/fixture.rs
+++ b/crates/swc_css_codegen/tests/fixture.rs
@@ -405,7 +405,7 @@ fn linefeed_lf(input: PathBuf) {
 
         let fm_output = cm.load_file(&output).unwrap();
 
-        assert_eq!(false, css_str.contains("\r\n"));
+        assert!(!css_str.contains("\r\n"));
 
         NormalizedOutput::from(css_str)
             .compare_to_file(output)
@@ -484,7 +484,7 @@ fn linefeed_crlf(input: PathBuf) {
 
         let fm_output = cm.load_file(&output).unwrap();
 
-        assert_eq!(true, css_str.contains("\r\n"));
+        assert!(css_str.contains("\r\n"));
 
         NormalizedOutput::from(css_str)
             .compare_to_file(output)
diff --git a/crates/swc_ecma_lints/tests/pass/issue-3956/1/input.ts b/crates/swc_ecma_lints/tests/pass/issue-3956/1/input.ts
new file mode 100644
index 0000000000..d08b8d05a6
--- /dev/null
+++ b/crates/swc_ecma_lints/tests/pass/issue-3956/1/input.ts
@@ -0,0 +1,8 @@
+function fn1({ x, y }: { x: string, y: string }): string {
+    return x + y
+}
+
+function fn2({ x, y }: { x: string, y: string }): string {
+    const fn3: ({ x, y }: { x: string, y: string }) => string = fn1
+    return fn3({ x, y })
+}
\ No newline at end of file