Repository: swc-project/swc (rust)

Issue:
Bitwise << left shift invalid result when in a TS Enum
### Describe the bug

When transpiling the input code below with @swc, the output for an enum with a left shift bitwise operation on it is not correctly calculated.

The result of `1 << 31` should be `-2147483648` but `@swc` transpiles this to right number, but as a positive value instead of a negative value.

Another example is the input `(1 << 30) | (1 << 31)` which should evaluate to `-1073741824` but with `@swc` evaluates to `3221225472`

`@swc` output:
```js
export var Test;
(function(Test) {
    Test[Test["A"] = 1073741824] = "A";
    Test[Test["B"] = 2147483648] = "B"; // <- incorrect evaluation
    Test[Test["C"] = 3221225472] = "C"; // <- incorrect evaluation
})(Test || (Test = {}));
var a = 1 << 30; // 1073741824
var b = 1 << 31; // -2147483648
var c = 1 << 30 | 1 << 31; // -1073741824
```

`tsc` output:
```js
export var Test;
(function (Test) {
    Test[Test["A"] = 1073741824] = "A";
    Test[Test["B"] = -2147483648] = "B";
    Test[Test["C"] = -1073741824] = "C";
})(Test || (Test = {}));
const a = 1 << 30; // 1073741824
const b = 1 << 31; // -2147483648
const c = (1 << 30) | (1 << 31); // -1073741824
```

`@babel` output:
```js
export var Test = /*#__PURE__*/function (Test) {
  Test[Test["A"] = 1073741824] = "A";
  Test[Test["B"] = -2147483648] = "B";
  Test[Test["C"] = -1073741824] = "C";
  return Test;
}({}); // -1073741824
var a = 1 << 30; // 1073741824
var b = 1 << 31; // -2147483648
var c = 1 << 30 | 1 << 31; // -1073741824
```

### Input code

```typescript
export enum Test {
  A = 1 << 30, // 1073741824
  B = 1 << 31, // -2147483648
  C = (1 << 30) | (1 << 31), // -1073741824
}

const a = 1 << 30; // 1073741824
const b = 1 << 31; // -2147483648
const c = (1 << 30) | (1 << 31); // -1073741824
```


### Config

```json
Default settings
```


### Playground link

https://play.swc.rs/?version=1.3.46&code=H4sIAAAAAAAAA0utKMgvKlFIzSvNVQhJLS5RqOZSUHBUsFUwVLCxUTA20FHQ11cwNDA3NjcxtDAyAUo6wSUNwZK6RoYm5iYWxmYmFkBZZ6CsBlSvpkINjG2oCVGLZFItF1dyfh7QxkSEbdZotkEUJCFstEa3EaIiGZet1ui2AgCgjfCL8AAAAA%3D%3D&config=H4sIAAAAAAAAA1VPOw7DIAzdOQXy3KFi6NA79BCIOhERAYQdqSjK3QsJpM1mv4%2Ff8yqkhIkMPOVaxrJEnQjTuReEsmf9KQhwjkgm2chw6yxTpQbtCHdoOxhgnUbk6kJSd6WaA1wIhN3RsNl6O%2BT%2FTBPmmJDoKqxS7UeH10TRUmEO72Un2y%2B179HgAT9RDzsPg6VXd3JaUGxfBMLf3xcBAAA%3D

### Expected behavior

I would expect the calculated output to match the correct values, as shown in `tsc` and `babel` examples.

### Actual behavior

_No response_

### Version

1.3.46

### Additional context

_No response_

Pull request:
fix(es/typescript): handle enum bit compute
<!-- 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 #7218 

Patch:
diff --git a/crates/swc_ecma_transforms_typescript/src/strip.rs b/crates/swc_ecma_transforms_typescript/src/strip.rs
index dba7254ed1..8a1ff60afb 100644
--- a/crates/swc_ecma_transforms_typescript/src/strip.rs
+++ b/crates/swc_ecma_transforms_typescript/src/strip.rs
@@ -541,14 +541,16 @@ where
                                 op!("/") => l / r,
 
                                 // TODO
-                                op!("&") => ((l.round() as i64) & (r.round() as i64)) as _,
-                                op!("|") => ((l.round() as i64) | (r.round() as i64)) as _,
-                                op!("^") => ((l.round() as i64) ^ (r.round() as i64)) as _,
-
-                                op!("<<") => ((l.round() as i64) << (r.round() as i64)) as _,
-                                op!(">>") => ((l.round() as i64) >> (r.round() as i64)) as _,
+                                op!("&") => ((l.trunc() as i32) & (r.trunc() as i32)) as _,
+                                op!("|") => ((l.trunc() as i32) | (r.trunc() as i32)) as _,
+                                op!("^") => ((l.trunc() as i32) ^ (r.trunc() as i32)) as _,
+                                op!("<<") => (l.trunc() as i32).wrapping_shl(r.trunc() as u32) as _,
+                                op!(">>") => (l.trunc() as i32).wrapping_shr(r.trunc() as u32) as _,
                                 // TODO: Verify this
-                                op!(">>>") => ((l.round() as u64) >> (r.round() as u64)) as _,
+                                op!(">>>") => {
+                                    (l.trunc() as u32).wrapping_shr(r.trunc() as u32) as _
+                                }
+
                                 _ => return Err(()),
                             },
                             raw: None,


Test patch:
diff --git a/crates/swc/tests/fixture/issues-7xxx/7218/input/index.ts b/crates/swc/tests/fixture/issues-7xxx/7218/input/index.ts
new file mode 100644
index 0000000000..7f58e0ec19
--- /dev/null
+++ b/crates/swc/tests/fixture/issues-7xxx/7218/input/index.ts
@@ -0,0 +1,9 @@
+export enum Test {
+  A = 1 << 30, // 1073741824
+  B = 1 << 31, // -2147483648
+  C = (1 << 30) | (1 << 31), // -1073741824
+}
+
+const a = 1 << 30; // 1073741824
+const b = 1 << 31; // -2147483648
+const c = (1 << 30) | (1 << 31); // -1073741824
diff --git a/crates/swc/tests/fixture/issues-7xxx/7218/output/index.ts b/crates/swc/tests/fixture/issues-7xxx/7218/output/index.ts
new file mode 100644
index 0000000000..57a97cb934
--- /dev/null
+++ b/crates/swc/tests/fixture/issues-7xxx/7218/output/index.ts
@@ -0,0 +1,9 @@
+export var Test;
+(function(Test) {
+    Test[Test["A"] = 1073741824] = "A";
+    Test[Test["B"] = -2147483648] = "B";
+    Test[Test["C"] = -1073741824] = "C";
+})(Test || (Test = {}));
+var a = 1 << 30; // 1073741824
+var b = 1 << 31; // -2147483648
+var c = 1 << 30 | 1 << 31; // -1073741824