Repository: swc-project/swc (rust)

Issue:
Typescript namespaces: destructured properties not exported correctly
### Describe the bug

````ts
namespace n {
  export const {a} = {a: 1}
}
````

The above is transpiled to:

````js
var n;
(function(n) {
    a = ({
        a: 1
    }).a;
})(n || (n = {
}));
````

Resulting in a runtime error:
````
Uncaught ReferenceError: a is not defined
`````

### Input code

_No response_

### Config

_No response_

### Playground link

https://play.swc.rs/?version=1.2.121&code=H4sIAAAAAAAAA%2BPlykvMTS0uSExOVchTqOblUlBIrSjILypRSM7PKy5RqE6sVbAFklYKhrW8XLUACRP5Gy8AAAA%3D&config=H4sIAAAAAAAAA0WNSwrDMAxE76J1ts0id%2BghjKsEF%2F%2FQKBBjfPfawSU7aebpqdIXlrZK2QhYxoQS1Vy0kZbMsOKy0kKKHu3Gg1tfjBysHWG8eudTAs92oeCi28sw2RSyMPBUJh7%2BT7YuCulzjqDez27hSu1xzDuH9wRVTm4%2FOkwQUrUAAAA%3D

### Expected behavior

It should be transpiled to:

<pre>
var n;
(function(n) {
    <b><u>n.</u></b>a = ({
        a: 1
    }).a;
})(n || (n = {
}));
</pre>

### Version

1.2.121

### Additional context

_No response_

Pull request:
fix(ecma/transform): export destructured properties in TypeScript namespace
**Related issue (if exists):**
fix #3073 

Patch:
diff --git a/crates/swc_ecma_transforms_typescript/src/strip.rs b/crates/swc_ecma_transforms_typescript/src/strip.rs
index dd49708269..96c8789649 100644
--- a/crates/swc_ecma_transforms_typescript/src/strip.rs
+++ b/crates/swc_ecma_transforms_typescript/src/strip.rs
@@ -2699,7 +2699,15 @@ fn create_prop_pat(obj: &Ident, pat: Pat) -> Pat {
                         value: Box::new(create_prop_pat(obj, *kv.value)),
                         ..kv
                     }),
-                    ObjectPatProp::Assign(..) => prop,
+                    ObjectPatProp::Assign(assign) => ObjectPatProp::KeyValue(KeyValuePatProp {
+                        key: PropName::Ident(assign.key.clone()),
+                        value: Box::new(Pat::Expr(Box::new(Expr::Member(MemberExpr {
+                            span: DUMMY_SP,
+                            obj: ExprOrSuper::Expr(Box::new(Expr::Ident(obj.clone()))),
+                            prop: Box::new(Expr::Ident(assign.key.into())),
+                            computed: false,
+                        })))),
+                    }),
                     ObjectPatProp::Rest(_) => {
                         todo!("Rest pattern property in an exported variable from namespace")
                     }


Test patch:
diff --git a/crates/swc/tests/fixture/issue-3073/1/input/.swcrc b/crates/swc/tests/fixture/issue-3073/1/input/.swcrc
new file mode 100644
index 0000000000..15e604fde5
--- /dev/null
+++ b/crates/swc/tests/fixture/issue-3073/1/input/.swcrc
@@ -0,0 +1,18 @@
+{
+    "jsc": {
+        "parser": {
+            "syntax": "typescript",
+            "tsx": false
+        },
+        "target": "es5",
+        "loose": false,
+        "minify": {
+            "compress": false,
+            "mangle": false
+        }
+    },
+    "module": {
+        "type": "es6"
+    },
+    "minify": false
+}
diff --git a/crates/swc/tests/fixture/issue-3073/1/input/index.ts b/crates/swc/tests/fixture/issue-3073/1/input/index.ts
new file mode 100644
index 0000000000..d9944d2e47
--- /dev/null
+++ b/crates/swc/tests/fixture/issue-3073/1/input/index.ts
@@ -0,0 +1,3 @@
+namespace n {
+    export const { a } = { a: 1 };
+}
diff --git a/crates/swc/tests/fixture/issue-3073/1/output/index.ts b/crates/swc/tests/fixture/issue-3073/1/output/index.ts
new file mode 100644
index 0000000000..4f4eb927ff
--- /dev/null
+++ b/crates/swc/tests/fixture/issue-3073/1/output/index.ts
@@ -0,0 +1,8 @@
+var n;
+(function(n1) {
+    var ref;
+    ref = {
+        a: 1
+    }, n1.a = ref.a, ref;
+})(n || (n = {
+}));
diff --git a/crates/swc/tests/fixture/issue-3073/2/input/.swcrc b/crates/swc/tests/fixture/issue-3073/2/input/.swcrc
new file mode 100644
index 0000000000..15e604fde5
--- /dev/null
+++ b/crates/swc/tests/fixture/issue-3073/2/input/.swcrc
@@ -0,0 +1,18 @@
+{
+    "jsc": {
+        "parser": {
+            "syntax": "typescript",
+            "tsx": false
+        },
+        "target": "es5",
+        "loose": false,
+        "minify": {
+            "compress": false,
+            "mangle": false
+        }
+    },
+    "module": {
+        "type": "es6"
+    },
+    "minify": false
+}
diff --git a/crates/swc/tests/fixture/issue-3073/2/input/index.ts b/crates/swc/tests/fixture/issue-3073/2/input/index.ts
new file mode 100644
index 0000000000..d50fd032d4
--- /dev/null
+++ b/crates/swc/tests/fixture/issue-3073/2/input/index.ts
@@ -0,0 +1,3 @@
+namespace Foo {
+    export const { a: A, b: B } = { a: 1, b: 2 };
+}
diff --git a/crates/swc/tests/fixture/issue-3073/2/output/index.ts b/crates/swc/tests/fixture/issue-3073/2/output/index.ts
new file mode 100644
index 0000000000..0d743301a5
--- /dev/null
+++ b/crates/swc/tests/fixture/issue-3073/2/output/index.ts
@@ -0,0 +1,9 @@
+var Foo;
+(function(Foo1) {
+    var ref;
+    ref = {
+        a: 1,
+        b: 2
+    }, Foo1.A = ref.a, Foo1.B = ref.b, ref;
+})(Foo || (Foo = {
+}));
diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/issue-3073/1/input.ts b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-3073/1/input.ts
new file mode 100644
index 0000000000..3221cc953d
--- /dev/null
+++ b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-3073/1/input.ts
@@ -0,0 +1,3 @@
+namespace Foo {
+    export const { a } = { a: 1 };
+}
diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/issue-3073/1/output.js b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-3073/1/output.js
new file mode 100644
index 0000000000..4368529907
--- /dev/null
+++ b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-3073/1/output.js
@@ -0,0 +1,7 @@
+var Foo;
+(function(Foo1) {
+    ({ a: Foo1.a  } = {
+        a: 1
+    });
+})(Foo || (Foo = {
+}));
diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/issue-3073/2/input.ts b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-3073/2/input.ts
new file mode 100644
index 0000000000..67e78360e2
--- /dev/null
+++ b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-3073/2/input.ts
@@ -0,0 +1,3 @@
+namespace Bar {
+    export const { a, b } = { a: 1, b: 2 };
+}
diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/issue-3073/2/output.js b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-3073/2/output.js
new file mode 100644
index 0000000000..4156f58975
--- /dev/null
+++ b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-3073/2/output.js
@@ -0,0 +1,8 @@
+var Bar;
+(function(Bar1) {
+    ({ a: Bar1.a , b: Bar1.b  } = {
+        a: 1,
+        b: 2
+    });
+})(Bar || (Bar = {
+}));
diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/issue-3073/3/input.ts b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-3073/3/input.ts
new file mode 100644
index 0000000000..f45c257ee1
--- /dev/null
+++ b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-3073/3/input.ts
@@ -0,0 +1,3 @@
+namespace Baz {
+    export const baz = { a: 1, b: 2 };
+}
diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/issue-3073/3/output.js b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-3073/3/output.js
new file mode 100644
index 0000000000..2729796f53
--- /dev/null
+++ b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-3073/3/output.js
@@ -0,0 +1,8 @@
+var Baz;
+(function(Baz1) {
+    Baz1.baz = {
+        a: 1,
+        b: 2
+    };
+})(Baz || (Baz = {
+}));
diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/issue-3073/4/input.ts b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-3073/4/input.ts
new file mode 100644
index 0000000000..c428274ef3
--- /dev/null
+++ b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-3073/4/input.ts
@@ -0,0 +1,12 @@
+module A {
+    const a = 1;
+    const b = 2;
+    export const { a: A } = { a };
+    export const { b: B } = { b };
+}
+namespace A {
+    const c = 3;
+    const d = 4;
+    export const { c: C } = { c: c };
+    export const { d: D } = { d: d };
+}
diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/issue-3073/4/output.js b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-3073/4/output.js
new file mode 100644
index 0000000000..a2a0d815a3
--- /dev/null
+++ b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-3073/4/output.js
@@ -0,0 +1,23 @@
+var A;
+(function(A1) {
+    const a = 1;
+    const b = 2;
+    ({ a: A1.A  } = {
+        a
+    });
+    ({ b: A1.B  } = {
+        b
+    });
+})(A || (A = {
+}));
+(function(A2) {
+    const c = 3;
+    const d = 4;
+    ({ c: A2.C  } = {
+        c: c
+    });
+    ({ d: A2.D  } = {
+        d: d
+    });
+})(A || (A = {
+}));