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

Bug: Not taking into account conversion between Number and BigInt for Math.pow usage #1050

Open
badghee1937 opened this issue Feb 10, 2025 · 2 comments

Comments

@badghee1937
Copy link

badghee1937 commented Feb 10, 2025

Webpack Version:
"webpack": "^6.0.1",

Babel Core Version:
"@babel/preset-env": "^7.26.7",

Babel Loader Version:
9.1.3

I have this small code-snippet:

console.log(Number(2n**53n));

After bundling it with the following configuration:

const path = require('path');
module.exports = {
    entry: './try_math_pow.js',
    output: {
        path: path.resolve(__dirname, './'),
        filename: 'bundle.js',
      },
      module: {
        rules: [
          {
            test: /\.js$/,
            exclude: /node_modules/, 
            use: {
              loader: 'babel-loader',
              options: {
                presets: ['@babel/preset-env'], 
              },
            },
          },
        ],
      },
  };

The bundled file has:
console.log(Number(Math.pow(2n,53n)));

However Math.pow doesn't take BigInt parameters, hence the parameters should be fixed accordingly to the use of Math.pow or use simply exponent arithmetic operator.

@JLHwung
Copy link
Contributor

JLHwung commented Feb 10, 2025

As a workaround, if your compilation targets already supported exponent arithmetic operator, please specify the targets option so that preset-env will not enable the exponent transform, for example, you can specify last 3 versions of every current browsers:

{
  use: {
              loader: 'babel-loader',
              options: {
                presets: ['@babel/preset-env'], 
                targets: "last 3 versions"
              },
            },
}

@nicolo-ribaudo
Copy link
Member

If you are using bigints, to avoid changing which browsers you support you could configure Babel's target to be "all browsers supporting bigint":

{
  use: {
              loader: 'babel-loader',
              options: {
                presets: ['@babel/preset-env'], 
                targets: "supports bigint"
              },
            },
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants