Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(es/typescript): handle enum bit compute #7219

Merged
merged 1 commit into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions crates/swc/tests/fixture/issues-7xxx/7218/input/index.ts
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions crates/swc/tests/fixture/issues-7xxx/7218/output/index.ts
Original file line number Diff line number Diff line change
@@ -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
16 changes: 9 additions & 7 deletions crates/swc_ecma_transforms_typescript/src/strip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down