Repository: swc-project/swc (rust)

Issue:
Do not generate re-export for type imports
<!--
If you are using swc at work, please considering adding your company to https://swc.rs/users/
If then, your issue will be fixed more quickly.
-->

**Input code**

```ts
import type { TestInfo } from './config'

export { TestInfo }
```

**Config**

```json
{
  "target": "es2020",
  "module": "commonjs"
}
```

**Expected**

```js
"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});

...
```

**Actually**

```js
"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});

exports.TestInfo = void 0;
exports.TestInfo = TestInfo;
...
```

**Version**
The version of @swc/core:

`1.2.84`



Pull request:
fix: Fix simple bugs
swc_ecma_utils:
 - Don't panic on jsx.

swc_ecma_transforms_typescript:
 - Drop type-only reexports. (Closes #2219)

Patch:
diff --git a/Cargo.lock b/Cargo.lock
index 4b219c9b29..7ffd573cd4 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2922,7 +2922,7 @@ dependencies = [
 
 [[package]]
 name = "swc_ecma_transforms_typescript"
-version = "0.40.0"
+version = "0.40.1"
 dependencies = [
  "fxhash",
  "serde",
@@ -2944,7 +2944,7 @@ dependencies = [
 
 [[package]]
 name = "swc_ecma_utils"
-version = "0.44.0"
+version = "0.44.1"
 dependencies = [
  "once_cell",
  "scoped-tls",
diff --git a/ecmascript/transforms/typescript/Cargo.toml b/ecmascript/transforms/typescript/Cargo.toml
index 94bd2da0e7..6a4b8631e8 100644
--- a/ecmascript/transforms/typescript/Cargo.toml
+++ b/ecmascript/transforms/typescript/Cargo.toml
@@ -6,7 +6,7 @@ edition = "2018"
 license = "Apache-2.0/MIT"
 name = "swc_ecma_transforms_typescript"
 repository = "https://github.com/swc-project/swc.git"
-version = "0.40.0"
+version = "0.40.1"
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 
 [dependencies]
diff --git a/ecmascript/transforms/typescript/src/strip.rs b/ecmascript/transforms/typescript/src/strip.rs
index 91807c6978..324df61f01 100644
--- a/ecmascript/transforms/typescript/src/strip.rs
+++ b/ecmascript/transforms/typescript/src/strip.rs
@@ -1210,11 +1210,7 @@ impl Visit for Strip {
 
     fn visit_ident(&mut self, n: &Ident, _: &dyn Node) {
         let is_type_only_export = self.is_type_only_export;
-        let entry = self
-            .scope
-            .referenced_idents
-            .entry((n.sym.clone(), n.span.ctxt()))
-            .or_default();
+        let entry = self.scope.referenced_idents.entry(n.to_id()).or_default();
         entry.has_concrete |= !is_type_only_export;
 
         n.visit_children_with(self);
@@ -1227,6 +1223,9 @@ impl Visit for Strip {
                     .referenced_idents
                     .entry(($i.sym.clone(), $i.span.ctxt()))
                     .or_default();
+                if n.type_only {
+                    self.scope.decls.entry($i.to_id()).or_default().has_type = true;
+                }
             }};
         }
         for s in &n.specifiers {
@@ -1249,15 +1248,18 @@ impl Visit for Strip {
         let old = self.non_top_level;
         self.non_top_level = false;
         n.iter().for_each(|n| {
-            if let ModuleItem::ModuleDecl(ModuleDecl::ExportNamed(export)) = n {
-                self.is_type_only_export = export.type_only;
-            }
             n.visit_with(&Invalid { span: DUMMY_SP }, self);
-            self.is_type_only_export = false;
         });
         self.non_top_level = old;
     }
 
+    fn visit_named_export(&mut self, export: &NamedExport, _: &dyn Node) {
+        let old = self.is_type_only_export;
+        self.is_type_only_export = export.type_only;
+        export.visit_children_with(self);
+        self.is_type_only_export = old;
+    }
+
     fn visit_prop_name(&mut self, n: &PropName, _: &dyn Node) {
         match n {
             PropName::Computed(e) => e.visit_with(n, self),
@@ -1925,9 +1927,7 @@ impl VisitMut for Strip {
                     }
                     export.specifiers.retain(|s| match *s {
                         ExportSpecifier::Named(ExportNamedSpecifier { ref orig, .. }) => {
-                            if let Some(e) =
-                                self.scope.decls.get(&(orig.sym.clone(), orig.span.ctxt()))
-                            {
+                            if let Some(e) = self.scope.decls.get(&orig.to_id()) {
                                 e.has_concrete
                             } else {
                                 true
diff --git a/ecmascript/utils/Cargo.toml b/ecmascript/utils/Cargo.toml
index 2b9d855301..7b46939362 100644
--- a/ecmascript/utils/Cargo.toml
+++ b/ecmascript/utils/Cargo.toml
@@ -6,7 +6,7 @@ edition = "2018"
 license = "Apache-2.0/MIT"
 name = "swc_ecma_utils"
 repository = "https://github.com/swc-project/swc.git"
-version = "0.44.0"
+version = "0.44.1"
 
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 
diff --git a/ecmascript/utils/src/lib.rs b/ecmascript/utils/src/lib.rs
index 83564b1dbc..dd39288fce 100644
--- a/ecmascript/utils/src/lib.rs
+++ b/ecmascript/utils/src/lib.rs
@@ -1149,7 +1149,7 @@ pub trait ExprExt {
             | Expr::JSXNamespacedName(..)
             | Expr::JSXEmpty(..)
             | Expr::JSXElement(..)
-            | Expr::JSXFragment(..) => unreachable!("simplifying jsx"),
+            | Expr::JSXFragment(..) => true,
 
             Expr::TsAs(TsAsExpr { ref expr, .. })
             | Expr::TsNonNull(TsNonNullExpr { ref expr, .. })
@@ -2005,7 +2005,7 @@ pub fn extract_side_effects_to(to: &mut Vec<Box<Expr>>, expr: Box<Expr>) {
         | Expr::JSXNamespacedName(..)
         | Expr::JSXEmpty(..)
         | Expr::JSXElement(..)
-        | Expr::JSXFragment(..) => unreachable!("simplifying jsx"),
+        | Expr::JSXFragment(..) => to.push(Box::new(expr)),
 
         Expr::TsTypeAssertion(TsTypeAssertion { expr, .. })
         | Expr::TsNonNull(TsNonNullExpr { expr, .. })


Test patch:
diff --git a/ecmascript/transforms/typescript/tests/strip.rs b/ecmascript/transforms/typescript/tests/strip.rs
index fe8c0fcf96..24b71c909b 100644
--- a/ecmascript/transforms/typescript/tests/strip.rs
+++ b/ecmascript/transforms/typescript/tests/strip.rs
@@ -4065,3 +4065,15 @@ to!(
     }
     "
 );
+
+to!(
+    issue_2219,
+    "
+    import type { TestInfo } from './config'
+
+    export { TestInfo }
+    ",
+    "
+    
+    "
+);