oxc-project / oxc

⚓ A collection of JavaScript tools written in Rust.
https://oxc.rs
MIT License
12.42k stars 456 forks source link

transformer: `2n ** 32n` gets transformed into runtime error `Math.pow(2n, 32n)` #5822

Closed Boshen closed 6 days ago

Boshen commented 2 months ago

I think we need to bail in this case :-/

tsc and esbuild throws "BigInt literals are not available when targeting lower than ES2020."

overlookmotel commented 2 months ago

Background on why it's not feasible to support BigInt with a polyfill: https://github.com/evanw/esbuild/issues/732

It looks like we should bail on any BigInt literal, not just when used with **.

Side note: Math.pow with any BigInt values is a runtime error, they don't have to be big numbers. e.g. Math.pow(1n, 1n) is a runtime error.

Boshen commented 1 month ago

@Dunqing How do we determine whether https://babel.dev/docs/babel-plugin-syntax-bigint is enabled or not in our transformer?

Boshen commented 1 month ago

@Dunqing need to figure out whether bigint is targeted or not.