Open
Description
💻
- Would you like to work on a fix?
How are you using Babel?
@babel/cli
Input code
console.log(42n ** 3n);
Output:
74088n
Configuration file name
babel.config.json
Configuration
{
"presets": ["@babel/preset-env"]
}
Current and expected behavior
Generated Code:
"use strict";
console.log(Math.pow(42n, 3n));
Babel incorrectly transforms the BigInt exponentiation operator (**) into Math.pow(), which does not support BigInt.
Output:
> babel_project@1.0.0 start
> node dist/app.js
babel_/babel_project/dist/app.js:3
console.log(Math.pow(42n, 3n));
^
TypeError: Cannot convert a BigInt value to a number
Expected Behavior:
Babel should preserve BigInt
exponentiation (**)
without replacing it with Math.pow()
.
Environment
System:
OS: Linux 6.8 Ubuntu 22.04.5 LTS 22.04.5 LTS (Jammy Jellyfish)
Binaries:
Node: 20.18.1 - /usr/bin/node
npm: 10.8.2 - /usr/bin/npm
npmPackages:
@babel/cli: ^7.26.4 => 7.26.4
@babel/core: ^7.26.10 => 7.26.10
@babel/preset-env: ^7.26.9 => 7.26.9
Possible solution
Preserve BigInt
exponentiation (**)
in the transpilation instead of converting it to Math.pow()
Additional context
No response
Metadata
Metadata
Assignees
Labels
No labels