Repository: swc-project/swc (rust)

Issue:
Wrong typescript mixed enum code generation
### Describe the bug

There seems to be a bug while generating code for mixed enums in typescript. TS and Babel agree on the code generation, but SWC differs.

### Input code

```typescript
enum A {
    X1,
    X15 = "x15",
    X2 = 6,
}
```


### Config

```json
N/A I just used the playground
```


### Playground link

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

### Expected behavior

[TS playground](https://www.typescriptlang.org/play?#code/KYOwrgtgBAglDeAoKKoA0CMAaZrMFYoBeKAIgA8N9SdV0AmYqANhwF9Eg) and [babel playground](https://babeljs.io/repl#?browsers=defaults%2C%20not%20ie%2011%2C%20not%20ie_mob%2011&build=&builtIns=false&corejs=3.21&spec=false&loose=false&code_lz=KYOwrgtgBAglDeAoKKoA0CMAaZrMFYoBeKAIgA8N9SdV0AmYqANhwF9Eg&debug=false&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=env%2Creact%2Cstage-2%2Ctypescript&prettier=false&targets=&version=7.17.6&externalPlugins=&assumptions=%7B%7D) agree on this generated code:
```
var A;

(function (A) {
  A[A["X1"] = 0] = "X1";
  A["X15"] = "x15";
  A[A["X2"] = 6] = "X2";
})(A || (A = {}));
```


### Actual behavior

but SWC instead generates:
```
var A;
(function(A) {
    A[A["X1"] = 0] = "X1";
    A[A["X15"] = "x15"] = "x15";
    A[A["X2"] = 6] = 6;
})(A || (A = {}));
```

note in particular the generation of the string enum part, `A["X15"] = "x15";` vs `A[A["X15"] = "x15"] = "x15";`

### Version

1.2.144

### Additional context

_No response_

Pull request:
fix(es/typescript): support heterogeneous enums
<!-- 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:**

<!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? -->

**BREAKING CHANGE:**

<!--
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):**
- fix #3711 

Patch:
diff --git a/crates/swc_ecma_transforms_typescript/src/strip.rs b/crates/swc_ecma_transforms_typescript/src/strip.rs
index 8f0d4d3b48..4e4e3d69d4 100644
--- a/crates/swc_ecma_transforms_typescript/src/strip.rs
+++ b/crates/swc_ecma_transforms_typescript/src/strip.rs
@@ -988,18 +988,6 @@ where
             .collect::<Result<Vec<_>, _>>()
             .unwrap_or_else(|_| panic!("invalid value for enum is detected"));
 
-        let is_all_str = members
-            .iter()
-            .all(|(_, v)| matches!(v, Expr::Lit(Lit::Str(..))));
-        let no_init_required = is_all_str;
-        let rhs_should_be_name = members.iter().all(|(m, v): &(TsEnumMember, Expr)| match v {
-            Expr::Lit(Lit::Str(s)) => match &m.id {
-                TsEnumMemberId::Ident(i) => i.sym == s.value,
-                TsEnumMemberId::Str(s2) => s2.value == s.value,
-            },
-            _ => true,
-        });
-
         let init = CallExpr {
             span: DUMMY_SP,
             callee: FnExpr {
@@ -1021,6 +1009,15 @@ where
                             .into_iter()
                             .enumerate()
                             .map(|(_, (m, val))| {
+                                let no_init_required = matches!(val, Expr::Lit(Lit::Str(..)));
+                                let rhs_should_be_name = match &val {
+                                    Expr::Lit(Lit::Str(s)) => match &m.id {
+                                        TsEnumMemberId::Ident(i) => i.sym == s.value,
+                                        TsEnumMemberId::Str(s2) => s2.value == s.value,
+                                    },
+                                    _ => true,
+                                };
+
                                 let value = match m.id {
                                     TsEnumMemberId::Str(s) => s,
                                     TsEnumMemberId::Ident(i) => Str {


Test patch:
diff --git a/crates/swc/tests/tsc-references/enumClassification_es2015.1.normal.js b/crates/swc/tests/tsc-references/enumClassification_es2015.1.normal.js
index eff862a715..0746a59a16 100644
--- a/crates/swc/tests/tsc-references/enumClassification_es2015.1.normal.js
+++ b/crates/swc/tests/tsc-references/enumClassification_es2015.1.normal.js
@@ -38,18 +38,18 @@ var E07;
 (function(E07) {
     E07[E07["A"] = 0] = "A";
     E07[E07["B"] = 1] = "B";
-    E07[E07["C"] = "hi"] = "hi";
-    E07[E07["D"] = 10] = 10;
+    E07["C"] = "hi";
+    E07[E07["D"] = 10] = "D";
     E07[E07["E"] = 11] = "E";
-    E07[E07["F"] = "bye"] = "bye";
+    E07["F"] = "bye";
 })(E07 || (E07 = {}));
 var E08;
 (function(E08) {
-    E08[E08["A"] = 10] = 10;
-    E08[E08["B"] = "hello"] = "hello";
-    E08[E08["C"] = 10] = 10;
-    E08[E08["D"] = "hello"] = "hello";
-    E08[E08["E"] = 10] = 10;
+    E08[E08["A"] = 10] = "A";
+    E08["B"] = "hello";
+    E08[E08["C"] = 10] = "C";
+    E08["D"] = "hello";
+    E08[E08["E"] = 10] = "E";
 })(E08 || (E08 = {}));
 var // Examples of numeric enum types with only constant members
 E10;
diff --git a/crates/swc/tests/tsc-references/enumClassification_es2015.2.minified.js b/crates/swc/tests/tsc-references/enumClassification_es2015.2.minified.js
index 60e96a8392..cc361563ba 100644
--- a/crates/swc/tests/tsc-references/enumClassification_es2015.2.minified.js
+++ b/crates/swc/tests/tsc-references/enumClassification_es2015.2.minified.js
@@ -12,9 +12,9 @@ var E01, E02, E03, E04, E05, E06, E07, E08, E11, E12, E20;
 })(E05 || (E05 = {})), (function(E06) {
     E06.A = "one", E06.B = "two", E06.C = "three";
 })(E06 || (E06 = {})), (function(E07) {
-    E07[E07.A = 0] = "A", E07[E07.B = 1] = "B", E07[E07.C = "hi"] = "hi", E07[E07.D = 10] = 10, E07[E07.E = 11] = "E", E07[E07.F = "bye"] = "bye";
+    E07[E07.A = 0] = "A", E07[E07.B = 1] = "B", E07.C = "hi", E07[E07.D = 10] = "D", E07[E07.E = 11] = "E", E07.F = "bye";
 })(E07 || (E07 = {})), (function(E08) {
-    E08[E08.A = 10] = 10, E08[E08.B = "hello"] = "hello", E08[E08.C = 10] = 10, E08[E08.D = "hello"] = "hello", E08[E08.E = 10] = 10;
+    E08[E08.A = 10] = "A", E08.B = "hello", E08[E08.C = 10] = "C", E08.D = "hello", E08[E08.E = 10] = "E";
 })(E08 || (E08 = {})), (function(E11) {
     E11[E11.A = 0] = "A", E11[E11.B = 1] = "B", E11[E11.C = 2] = "C";
 })(E11 || (E11 = {})), (function(E12) {
diff --git a/crates/swc/tests/tsc-references/enumClassification_es5.1.normal.js b/crates/swc/tests/tsc-references/enumClassification_es5.1.normal.js
index eff862a715..0746a59a16 100644
--- a/crates/swc/tests/tsc-references/enumClassification_es5.1.normal.js
+++ b/crates/swc/tests/tsc-references/enumClassification_es5.1.normal.js
@@ -38,18 +38,18 @@ var E07;
 (function(E07) {
     E07[E07["A"] = 0] = "A";
     E07[E07["B"] = 1] = "B";
-    E07[E07["C"] = "hi"] = "hi";
-    E07[E07["D"] = 10] = 10;
+    E07["C"] = "hi";
+    E07[E07["D"] = 10] = "D";
     E07[E07["E"] = 11] = "E";
-    E07[E07["F"] = "bye"] = "bye";
+    E07["F"] = "bye";
 })(E07 || (E07 = {}));
 var E08;
 (function(E08) {
-    E08[E08["A"] = 10] = 10;
-    E08[E08["B"] = "hello"] = "hello";
-    E08[E08["C"] = 10] = 10;
-    E08[E08["D"] = "hello"] = "hello";
-    E08[E08["E"] = 10] = 10;
+    E08[E08["A"] = 10] = "A";
+    E08["B"] = "hello";
+    E08[E08["C"] = 10] = "C";
+    E08["D"] = "hello";
+    E08[E08["E"] = 10] = "E";
 })(E08 || (E08 = {}));
 var // Examples of numeric enum types with only constant members
 E10;
diff --git a/crates/swc/tests/tsc-references/enumClassification_es5.2.minified.js b/crates/swc/tests/tsc-references/enumClassification_es5.2.minified.js
index 60e96a8392..cc361563ba 100644
--- a/crates/swc/tests/tsc-references/enumClassification_es5.2.minified.js
+++ b/crates/swc/tests/tsc-references/enumClassification_es5.2.minified.js
@@ -12,9 +12,9 @@ var E01, E02, E03, E04, E05, E06, E07, E08, E11, E12, E20;
 })(E05 || (E05 = {})), (function(E06) {
     E06.A = "one", E06.B = "two", E06.C = "three";
 })(E06 || (E06 = {})), (function(E07) {
-    E07[E07.A = 0] = "A", E07[E07.B = 1] = "B", E07[E07.C = "hi"] = "hi", E07[E07.D = 10] = 10, E07[E07.E = 11] = "E", E07[E07.F = "bye"] = "bye";
+    E07[E07.A = 0] = "A", E07[E07.B = 1] = "B", E07.C = "hi", E07[E07.D = 10] = "D", E07[E07.E = 11] = "E", E07.F = "bye";
 })(E07 || (E07 = {})), (function(E08) {
-    E08[E08.A = 10] = 10, E08[E08.B = "hello"] = "hello", E08[E08.C = 10] = 10, E08[E08.D = "hello"] = "hello", E08[E08.E = 10] = 10;
+    E08[E08.A = 10] = "A", E08.B = "hello", E08[E08.C = 10] = "C", E08.D = "hello", E08[E08.E = 10] = "E";
 })(E08 || (E08 = {})), (function(E11) {
     E11[E11.A = 0] = "A", E11[E11.B = 1] = "B", E11[E11.C = 2] = "C";
 })(E11 || (E11 = {})), (function(E12) {
diff --git a/crates/swc/tests/tsc-references/enumConstantMemberWithString_es2015.1.normal.js b/crates/swc/tests/tsc-references/enumConstantMemberWithString_es2015.1.normal.js
index f1504cc4a5..132c3d7341 100644
--- a/crates/swc/tests/tsc-references/enumConstantMemberWithString_es2015.1.normal.js
+++ b/crates/swc/tests/tsc-references/enumConstantMemberWithString_es2015.1.normal.js
@@ -1,10 +1,10 @@
 var T1;
 (function(T1) {
-    T1[T1["a"] = "1"] = "1";
-    T1[T1["b"] = "12"] = "12";
-    T1[T1["c"] = "123"] = "123";
-    T1[T1["d"] = "a" - "a"] = "a" - "a";
-    T1[T1["e"] = "a1"] = "a1";
+    T1["a"] = "1";
+    T1["b"] = "12";
+    T1["c"] = "123";
+    T1[T1["d"] = "a" - "a"] = "d";
+    T1["e"] = "a1";
 })(T1 || (T1 = {}));
 var T2;
 (function(T2) {
@@ -13,10 +13,10 @@ var T2;
 })(T2 || (T2 = {}));
 var T3;
 (function(T3) {
-    T3[T3["a"] = "1"] = "1";
-    T3[T3["b"] = "12"] = "12";
-    T3[T3["c"] = 1] = 1;
-    T3[T3["d"] = 3] = 3;
+    T3["a"] = "1";
+    T3["b"] = "12";
+    T3[T3["c"] = 1] = "c";
+    T3[T3["d"] = 3] = "d";
 })(T3 || (T3 = {}));
 var T4;
 (function(T4) {
diff --git a/crates/swc/tests/tsc-references/enumConstantMemberWithString_es2015.2.minified.js b/crates/swc/tests/tsc-references/enumConstantMemberWithString_es2015.2.minified.js
index 275d793d0f..d677e2042b 100644
--- a/crates/swc/tests/tsc-references/enumConstantMemberWithString_es2015.2.minified.js
+++ b/crates/swc/tests/tsc-references/enumConstantMemberWithString_es2015.2.minified.js
@@ -1,10 +1,10 @@
 var T1, T2, T3, T4, T5, T6;
 !function(T1) {
-    T1[T1.a = "1"] = "1", T1[T1.b = "12"] = "12", T1[T1.c = "123"] = "123", T1[T1.d = "a" - "a"] = "a" - "a", T1[T1.e = "a1"] = "a1";
+    T1.a = "1", T1.b = "12", T1.c = "123", T1[T1.d = "a" - "a"] = "d", T1.e = "a1";
 }(T1 || (T1 = {})), (function(T2) {
     T2.a = "1", T2.b = "12";
 })(T2 || (T2 = {})), (function(T3) {
-    T3[T3.a = "1"] = "1", T3[T3.b = "12"] = "12", T3[T3.c = 1] = 1, T3[T3.d = 3] = 3;
+    T3.a = "1", T3.b = "12", T3[T3.c = 1] = "c", T3[T3.d = 3] = "d";
 })(T3 || (T3 = {})), (function(T4) {
     T4.a = "1";
 })(T4 || (T4 = {})), (function(T5) {
diff --git a/crates/swc/tests/tsc-references/enumConstantMemberWithString_es5.1.normal.js b/crates/swc/tests/tsc-references/enumConstantMemberWithString_es5.1.normal.js
index f1504cc4a5..132c3d7341 100644
--- a/crates/swc/tests/tsc-references/enumConstantMemberWithString_es5.1.normal.js
+++ b/crates/swc/tests/tsc-references/enumConstantMemberWithString_es5.1.normal.js
@@ -1,10 +1,10 @@
 var T1;
 (function(T1) {
-    T1[T1["a"] = "1"] = "1";
-    T1[T1["b"] = "12"] = "12";
-    T1[T1["c"] = "123"] = "123";
-    T1[T1["d"] = "a" - "a"] = "a" - "a";
-    T1[T1["e"] = "a1"] = "a1";
+    T1["a"] = "1";
+    T1["b"] = "12";
+    T1["c"] = "123";
+    T1[T1["d"] = "a" - "a"] = "d";
+    T1["e"] = "a1";
 })(T1 || (T1 = {}));
 var T2;
 (function(T2) {
@@ -13,10 +13,10 @@ var T2;
 })(T2 || (T2 = {}));
 var T3;
 (function(T3) {
-    T3[T3["a"] = "1"] = "1";
-    T3[T3["b"] = "12"] = "12";
-    T3[T3["c"] = 1] = 1;
-    T3[T3["d"] = 3] = 3;
+    T3["a"] = "1";
+    T3["b"] = "12";
+    T3[T3["c"] = 1] = "c";
+    T3[T3["d"] = 3] = "d";
 })(T3 || (T3 = {}));
 var T4;
 (function(T4) {
diff --git a/crates/swc/tests/tsc-references/enumConstantMemberWithString_es5.2.minified.js b/crates/swc/tests/tsc-references/enumConstantMemberWithString_es5.2.minified.js
index 275d793d0f..d677e2042b 100644
--- a/crates/swc/tests/tsc-references/enumConstantMemberWithString_es5.2.minified.js
+++ b/crates/swc/tests/tsc-references/enumConstantMemberWithString_es5.2.minified.js
@@ -1,10 +1,10 @@
 var T1, T2, T3, T4, T5, T6;
 !function(T1) {
-    T1[T1.a = "1"] = "1", T1[T1.b = "12"] = "12", T1[T1.c = "123"] = "123", T1[T1.d = "a" - "a"] = "a" - "a", T1[T1.e = "a1"] = "a1";
+    T1.a = "1", T1.b = "12", T1.c = "123", T1[T1.d = "a" - "a"] = "d", T1.e = "a1";
 }(T1 || (T1 = {})), (function(T2) {
     T2.a = "1", T2.b = "12";
 })(T2 || (T2 = {})), (function(T3) {
-    T3[T3.a = "1"] = "1", T3[T3.b = "12"] = "12", T3[T3.c = 1] = 1, T3[T3.d = 3] = 3;
+    T3.a = "1", T3.b = "12", T3[T3.c = 1] = "c", T3[T3.d = 3] = "d";
 })(T3 || (T3 = {})), (function(T4) {
     T4.a = "1";
 })(T4 || (T4 = {})), (function(T5) {
diff --git a/crates/swc/tests/tsc-references/enumConstantMemberWithTemplateLiteralsEmitDeclaration_es2015.1.normal.js b/crates/swc/tests/tsc-references/enumConstantMemberWithTemplateLiteralsEmitDeclaration_es2015.1.normal.js
index 39ab0f62b7..f94219c791 100644
--- a/crates/swc/tests/tsc-references/enumConstantMemberWithTemplateLiteralsEmitDeclaration_es2015.1.normal.js
+++ b/crates/swc/tests/tsc-references/enumConstantMemberWithTemplateLiteralsEmitDeclaration_es2015.1.normal.js
@@ -5,9 +5,9 @@ T1;
 })(T1 || (T1 = {}));
 var T2;
 (function(T2) {
-    T2[T2["a"] = "1"] = "1";
-    T2[T2["b"] = "2"] = "2";
-    T2[T2["c"] = 3] = 3;
+    T2["a"] = "1";
+    T2["b"] = "2";
+    T2[T2["c"] = 3] = "c";
 })(T2 || (T2 = {}));
 var T3;
 (function(T3) {
@@ -23,10 +23,10 @@ var T4;
 })(T4 || (T4 = {}));
 var T5;
 (function(T5) {
-    T5[T5["a"] = "1"] = "1";
-    T5[T5["b"] = "12"] = "12";
-    T5[T5["c"] = "123"] = "123";
-    T5[T5["d"] = 1] = 1;
+    T5["a"] = "1";
+    T5["b"] = "12";
+    T5["c"] = "123";
+    T5[T5["d"] = 1] = "d";
 })(T5 || (T5 = {}));
 var T6;
 (function(T6) {
diff --git a/crates/swc/tests/tsc-references/enumConstantMemberWithTemplateLiteralsEmitDeclaration_es2015.2.minified.js b/crates/swc/tests/tsc-references/enumConstantMemberWithTemplateLiteralsEmitDeclaration_es2015.2.minified.js
index 17043815a2..69f6000869 100644
--- a/crates/swc/tests/tsc-references/enumConstantMemberWithTemplateLiteralsEmitDeclaration_es2015.2.minified.js
+++ b/crates/swc/tests/tsc-references/enumConstantMemberWithTemplateLiteralsEmitDeclaration_es2015.2.minified.js
@@ -2,13 +2,13 @@ var T1, T2, T3, T4, T5, T6, T7;
 !function(T1) {
     T1.a = "1";
 }(T1 || (T1 = {})), (function(T2) {
-    T2[T2.a = "1"] = "1", T2[T2.b = "2"] = "2", T2[T2.c = 3] = 3;
+    T2.a = "1", T2.b = "2", T2[T2.c = 3] = "c";
 })(T2 || (T2 = {})), (function(T3) {
     T3.a = "11";
 })(T3 || (T3 = {})), (function(T4) {
     T4.a = "1", T4.b = "11", T4.c = "12", T4.d = "21", T4.e = "211";
 })(T4 || (T4 = {})), (function(T5) {
-    T5[T5.a = "1"] = "1", T5[T5.b = "12"] = "12", T5[T5.c = "123"] = "123", T5[T5.d = 1] = 1;
+    T5.a = "1", T5.b = "12", T5.c = "123", T5[T5.d = 1] = "d";
 })(T5 || (T5 = {})), (function(T6) {
     T6[T6.a = 1] = "a", T6[T6.b = 2] = "b";
 })(T6 || (T6 = {})), (function(T7) {
diff --git a/crates/swc/tests/tsc-references/enumConstantMemberWithTemplateLiteralsEmitDeclaration_es5.1.normal.js b/crates/swc/tests/tsc-references/enumConstantMemberWithTemplateLiteralsEmitDeclaration_es5.1.normal.js
index a1544ed302..d6e2170273 100644
--- a/crates/swc/tests/tsc-references/enumConstantMemberWithTemplateLiteralsEmitDeclaration_es5.1.normal.js
+++ b/crates/swc/tests/tsc-references/enumConstantMemberWithTemplateLiteralsEmitDeclaration_es5.1.normal.js
@@ -5,9 +5,9 @@ T1;
 })(T1 || (T1 = {}));
 var T2;
 (function(T2) {
-    T2[T2["a"] = "1"] = "1";
-    T2[T2["b"] = "2"] = "2";
-    T2[T2["c"] = 3] = 3;
+    T2["a"] = "1";
+    T2["b"] = "2";
+    T2[T2["c"] = 3] = "c";
 })(T2 || (T2 = {}));
 var T3;
 (function(T3) {
@@ -23,10 +23,10 @@ var T4;
 })(T4 || (T4 = {}));
 var T5;
 (function(T5) {
-    T5[T5["a"] = "1"] = "1";
-    T5[T5["b"] = "12"] = "12";
-    T5[T5["c"] = "123"] = "123";
-    T5[T5["d"] = 1] = 1;
+    T5["a"] = "1";
+    T5["b"] = "12";
+    T5["c"] = "123";
+    T5[T5["d"] = 1] = "d";
 })(T5 || (T5 = {}));
 var T6;
 (function(T6) {
diff --git a/crates/swc/tests/tsc-references/enumConstantMemberWithTemplateLiteralsEmitDeclaration_es5.2.minified.js b/crates/swc/tests/tsc-references/enumConstantMemberWithTemplateLiteralsEmitDeclaration_es5.2.minified.js
index 17043815a2..69f6000869 100644
--- a/crates/swc/tests/tsc-references/enumConstantMemberWithTemplateLiteralsEmitDeclaration_es5.2.minified.js
+++ b/crates/swc/tests/tsc-references/enumConstantMemberWithTemplateLiteralsEmitDeclaration_es5.2.minified.js
@@ -2,13 +2,13 @@ var T1, T2, T3, T4, T5, T6, T7;
 !function(T1) {
     T1.a = "1";
 }(T1 || (T1 = {})), (function(T2) {
-    T2[T2.a = "1"] = "1", T2[T2.b = "2"] = "2", T2[T2.c = 3] = 3;
+    T2.a = "1", T2.b = "2", T2[T2.c = 3] = "c";
 })(T2 || (T2 = {})), (function(T3) {
     T3.a = "11";
 })(T3 || (T3 = {})), (function(T4) {
     T4.a = "1", T4.b = "11", T4.c = "12", T4.d = "21", T4.e = "211";
 })(T4 || (T4 = {})), (function(T5) {
-    T5[T5.a = "1"] = "1", T5[T5.b = "12"] = "12", T5[T5.c = "123"] = "123", T5[T5.d = 1] = 1;
+    T5.a = "1", T5.b = "12", T5.c = "123", T5[T5.d = 1] = "d";
 })(T5 || (T5 = {})), (function(T6) {
     T6[T6.a = 1] = "a", T6[T6.b = 2] = "b";
 })(T6 || (T6 = {})), (function(T7) {
diff --git a/crates/swc/tests/tsc-references/enumConstantMemberWithTemplateLiterals_es2015.1.normal.js b/crates/swc/tests/tsc-references/enumConstantMemberWithTemplateLiterals_es2015.1.normal.js
index 07c33b2ed4..51f1482c25 100644
--- a/crates/swc/tests/tsc-references/enumConstantMemberWithTemplateLiterals_es2015.1.normal.js
+++ b/crates/swc/tests/tsc-references/enumConstantMemberWithTemplateLiterals_es2015.1.normal.js
@@ -4,9 +4,9 @@ var T1;
 })(T1 || (T1 = {}));
 var T2;
 (function(T2) {
-    T2[T2["a"] = "1"] = "1";
-    T2[T2["b"] = "2"] = "2";
-    T2[T2["c"] = 3] = 3;
+    T2["a"] = "1";
+    T2["b"] = "2";
+    T2[T2["c"] = 3] = "c";
 })(T2 || (T2 = {}));
 var T3;
 (function(T3) {
@@ -22,14 +22,14 @@ var T4;
 })(T4 || (T4 = {}));
 var T5;
 (function(T5) {
-    T5[T5["a"] = "1"] = "1";
-    T5[T5["b"] = "12"] = "12";
-    T5[T5["c"] = "123"] = "123";
-    T5[T5["d"] = 1] = 1;
-    T5[T5["e"] = `1` - `1`] = `1` - `1`;
-    T5[T5["f"] = "11"] = "11";
-    T5[T5["g"] = `1${"2"}3`] = `1${"2"}3`;
-    T5[T5["h"] = `1`.length] = `1`.length;
+    T5["a"] = "1";
+    T5["b"] = "12";
+    T5["c"] = "123";
+    T5[T5["d"] = 1] = "d";
+    T5[T5["e"] = `1` - `1`] = "e";
+    T5["f"] = "11";
+    T5[T5["g"] = `1${"2"}3`] = "g";
+    T5[T5["h"] = `1`.length] = "h";
 })(T5 || (T5 = {}));
 var T6;
 (function(T6) {
diff --git a/crates/swc/tests/tsc-references/enumConstantMemberWithTemplateLiterals_es2015.2.minified.js b/crates/swc/tests/tsc-references/enumConstantMemberWithTemplateLiterals_es2015.2.minified.js
index 424b9b6a35..c3fdf69c87 100644
--- a/crates/swc/tests/tsc-references/enumConstantMemberWithTemplateLiterals_es2015.2.minified.js
+++ b/crates/swc/tests/tsc-references/enumConstantMemberWithTemplateLiterals_es2015.2.minified.js
@@ -2,13 +2,13 @@ var T1, T2, T3, T4, T5, T6, T7;
 !function(T1) {
     T1.a = "1";
 }(T1 || (T1 = {})), (function(T2) {
-    T2[T2.a = "1"] = "1", T2[T2.b = "2"] = "2", T2[T2.c = 3] = 3;
+    T2.a = "1", T2.b = "2", T2[T2.c = 3] = "c";
 })(T2 || (T2 = {})), (function(T3) {
     T3.a = "11";
 })(T3 || (T3 = {})), (function(T4) {
     T4.a = "1", T4.b = "11", T4.c = "12", T4.d = "21", T4.e = "211";
 })(T4 || (T4 = {})), (function(T5) {
-    T5[T5.a = "1"] = "1", T5[T5.b = "12"] = "12", T5[T5.c = "123"] = "123", T5[T5.d = 1] = 1, T5[T5.e = "1" - "1"] = "1" - "1", T5[T5.f = "11"] = "11", T5[T5.g = "123"] = "123", T5[T5.h = 1] = 1;
+    T5.a = "1", T5.b = "12", T5.c = "123", T5[T5.d = 1] = "d", T5[T5.e = "1" - "1"] = "e", T5.f = "11", T5[T5.g = "123"] = "g", T5[T5.h = 1] = "h";
 })(T5 || (T5 = {})), (function(T6) {
     T6[T6.a = 1] = "a", T6[T6.b = 2] = "b";
 })(T6 || (T6 = {})), (function(T7) {
diff --git a/crates/swc/tests/tsc-references/enumConstantMemberWithTemplateLiterals_es5.1.normal.js b/crates/swc/tests/tsc-references/enumConstantMemberWithTemplateLiterals_es5.1.normal.js
index e360a810ec..24b9fd95f1 100644
--- a/crates/swc/tests/tsc-references/enumConstantMemberWithTemplateLiterals_es5.1.normal.js
+++ b/crates/swc/tests/tsc-references/enumConstantMemberWithTemplateLiterals_es5.1.normal.js
@@ -4,9 +4,9 @@ var T1;
 })(T1 || (T1 = {}));
 var T2;
 (function(T2) {
-    T2[T2["a"] = "1"] = "1";
-    T2[T2["b"] = "2"] = "2";
-    T2[T2["c"] = 3] = 3;
+    T2["a"] = "1";
+    T2["b"] = "2";
+    T2[T2["c"] = 3] = "c";
 })(T2 || (T2 = {}));
 var T3;
 (function(T3) {
@@ -22,14 +22,14 @@ var T4;
 })(T4 || (T4 = {}));
 var T5;
 (function(T5) {
-    T5[T5["a"] = "1"] = "1";
-    T5[T5["b"] = "12"] = "12";
-    T5[T5["c"] = "123"] = "123";
-    T5[T5["d"] = 1] = 1;
-    T5[T5["e"] = "1" - "1"] = "1" - "1";
-    T5[T5["f"] = "11"] = "11";
-    T5[T5["g"] = "123"] = "123";
-    T5[T5["h"] = "1".length] = "1".length;
+    T5["a"] = "1";
+    T5["b"] = "12";
+    T5["c"] = "123";
+    T5[T5["d"] = 1] = "d";
+    T5[T5["e"] = "1" - "1"] = "e";
+    T5["f"] = "11";
+    T5[T5["g"] = "123"] = "g";
+    T5[T5["h"] = "1".length] = "h";
 })(T5 || (T5 = {}));
 var T6;
 (function(T6) {
diff --git a/crates/swc/tests/tsc-references/enumConstantMemberWithTemplateLiterals_es5.2.minified.js b/crates/swc/tests/tsc-references/enumConstantMemberWithTemplateLiterals_es5.2.minified.js
index 424b9b6a35..c3fdf69c87 100644
--- a/crates/swc/tests/tsc-references/enumConstantMemberWithTemplateLiterals_es5.2.minified.js
+++ b/crates/swc/tests/tsc-references/enumConstantMemberWithTemplateLiterals_es5.2.minified.js
@@ -2,13 +2,13 @@ var T1, T2, T3, T4, T5, T6, T7;
 !function(T1) {
     T1.a = "1";
 }(T1 || (T1 = {})), (function(T2) {
-    T2[T2.a = "1"] = "1", T2[T2.b = "2"] = "2", T2[T2.c = 3] = 3;
+    T2.a = "1", T2.b = "2", T2[T2.c = 3] = "c";
 })(T2 || (T2 = {})), (function(T3) {
     T3.a = "11";
 })(T3 || (T3 = {})), (function(T4) {
     T4.a = "1", T4.b = "11", T4.c = "12", T4.d = "21", T4.e = "211";
 })(T4 || (T4 = {})), (function(T5) {
-    T5[T5.a = "1"] = "1", T5[T5.b = "12"] = "12", T5[T5.c = "123"] = "123", T5[T5.d = 1] = 1, T5[T5.e = "1" - "1"] = "1" - "1", T5[T5.f = "11"] = "11", T5[T5.g = "123"] = "123", T5[T5.h = 1] = 1;
+    T5.a = "1", T5.b = "12", T5.c = "123", T5[T5.d = 1] = "d", T5[T5.e = "1" - "1"] = "e", T5.f = "11", T5[T5.g = "123"] = "g", T5[T5.h = 1] = "h";
 })(T5 || (T5 = {})), (function(T6) {
     T6[T6.a = 1] = "a", T6[T6.b = 2] = "b";
 })(T6 || (T6 = {})), (function(T7) {
diff --git a/crates/swc/tests/tsc-references/jsDeclarationsEnums_es2015.1.normal.js b/crates/swc/tests/tsc-references/jsDeclarationsEnums_es2015.1.normal.js
index 35cd69a22a..c19a408b60 100644
--- a/crates/swc/tests/tsc-references/jsDeclarationsEnums_es2015.1.normal.js
+++ b/crates/swc/tests/tsc-references/jsDeclarationsEnums_es2015.1.normal.js
@@ -29,8 +29,8 @@ export var H;
 })(H || (H = {}));
 export var I;
 (function(I) {
-    I[I["A"] = "a"] = "a";
-    I[I["B"] = 0] = 0;
+    I["A"] = "a";
+    I[I["B"] = 0] = "B";
     I[I["C"] = 1] = "C";
 })(I || (I = {}));
 export var J;
diff --git a/crates/swc/tests/tsc-references/jsDeclarationsEnums_es2015.2.minified.js b/crates/swc/tests/tsc-references/jsDeclarationsEnums_es2015.2.minified.js
index 67f2bf8c9e..86d10ec3f8 100644
--- a/crates/swc/tests/tsc-references/jsDeclarationsEnums_es2015.2.minified.js
+++ b/crates/swc/tests/tsc-references/jsDeclarationsEnums_es2015.2.minified.js
@@ -7,7 +7,7 @@ var B, C, DD, E, F, G, H, I, J, K, L;
 }(G || (G = {})), (function(H) {
     H.A = "a", H.B = "b";
 })(H || (H = {})), (function(I) {
-    I[I.A = "a"] = "a", I[I.B = 0] = 0, I[I.C = 1] = "C";
+    I.A = "a", I[I.B = 0] = "B", I[I.C = 1] = "C";
 })(I || (I = {})), (function(J) {
     J[J.A = 1] = "A", J[J.B = 2] = "B", J[J.C = 3] = "C";
 })(J || (J = {})), (function(K) {
diff --git a/crates/swc/tests/tsc-references/jsDeclarationsEnums_es5.1.normal.js b/crates/swc/tests/tsc-references/jsDeclarationsEnums_es5.1.normal.js
index 35cd69a22a..c19a408b60 100644
--- a/crates/swc/tests/tsc-references/jsDeclarationsEnums_es5.1.normal.js
+++ b/crates/swc/tests/tsc-references/jsDeclarationsEnums_es5.1.normal.js
@@ -29,8 +29,8 @@ export var H;
 })(H || (H = {}));
 export var I;
 (function(I) {
-    I[I["A"] = "a"] = "a";
-    I[I["B"] = 0] = 0;
+    I["A"] = "a";
+    I[I["B"] = 0] = "B";
     I[I["C"] = 1] = "C";
 })(I || (I = {}));
 export var J;
diff --git a/crates/swc/tests/tsc-references/jsDeclarationsEnums_es5.2.minified.js b/crates/swc/tests/tsc-references/jsDeclarationsEnums_es5.2.minified.js
index 67f2bf8c9e..86d10ec3f8 100644
--- a/crates/swc/tests/tsc-references/jsDeclarationsEnums_es5.2.minified.js
+++ b/crates/swc/tests/tsc-references/jsDeclarationsEnums_es5.2.minified.js
@@ -7,7 +7,7 @@ var B, C, DD, E, F, G, H, I, J, K, L;
 }(G || (G = {})), (function(H) {
     H.A = "a", H.B = "b";
 })(H || (H = {})), (function(I) {
-    I[I.A = "a"] = "a", I[I.B = 0] = 0, I[I.C = 1] = "C";
+    I.A = "a", I[I.B = 0] = "B", I[I.C = 1] = "C";
 })(I || (I = {})), (function(J) {
     J[J.A = 1] = "A", J[J.B = 2] = "B", J[J.C = 3] = "C";
 })(J || (J = {})), (function(K) {
diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/issue-3711/1/input.ts b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-3711/1/input.ts
new file mode 100644
index 0000000000..b3fff8bc3d
--- /dev/null
+++ b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-3711/1/input.ts
@@ -0,0 +1,5 @@
+enum A {
+    X1,
+    X15 = "x15",
+    X2 = 6,
+}
diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/issue-3711/1/output.js b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-3711/1/output.js
new file mode 100644
index 0000000000..9fe5e2e6f2
--- /dev/null
+++ b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-3711/1/output.js
@@ -0,0 +1,6 @@
+var A;
+(function(A) {
+    A[A["X1"] = 0] = "X1";
+    A["X15"] = "x15";
+    A[A["X2"] = 6] = "X2";
+})(A || (A = {}));