Content-Length: 284493 | pFad | http://redirect.github.com/babel/babel/issues/17190

6D Babel incorrectly transpiles BigInt exponentiation (`**`) into `Math.pow()`, causing a TypeError · Issue #17190 · babel/babel · GitHub
Skip to content

Babel incorrectly transpiles BigInt exponentiation (**) into Math.pow(), causing a TypeError #17190

@Yeaseen

Description

@Yeaseen

💻

  • 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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









      ApplySandwichStrip

      pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


      --- a PPN by Garber Painting Akron. With Image Size Reduction included!

      Fetched URL: http://redirect.github.com/babel/babel/issues/17190

      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy