Skip to content

[Bug]: @babel/plugin-transform-runtime not transform Object.hasOwn correctly #15572

@Ashiria7

Description

@Ashiria7

💻

  • Would you like to work on a fix?

How are you using Babel?

@babel/cli

Input code

const _ = function () {
    const obj = { a: 1}
    console.log(Object.hasOwn(obj, "b"));
    [].includes(1)
      
    const a = new Promise()
    return a
}
export default  _

console.log(_())

Configuration file name

babel.config.json

Configuration

{
  "plugins": [
    [
      "@babel/plugin-transform-runtime",
      {
        "corejs": 3
      }
    ]
  ]
}

Current and expected behavior

I used @babel/cli directly with the command ./node_modules/.bin/babel index.js --out-dir lib. This is the output:

import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
import _Promise from "@babel/runtime-corejs3/core-js-stable/promise";
const _ = function () {
  var _context;
  const obj = {
    a: 1
  };
  console.log(Object.hasOwn(obj, "b"));
  _includesInstanceProperty(_context = []).call(_context, 1);
  const a = new _Promise();
  return a;
};
export default _;
console.log(_());

The Promise and Array.includes are replace with @babel/runtime-corejs3 correctly. But Object.hasOwn not. And I find the @babel/runtime-corejs3/core-js-stable didn't exist the polyfill of Object.hasOwn which is realized in corejs. I have read the doc about @babel/plugin-transform-runtime, but I haven't found anything about this. So this behavior is designed so? Or I have missed some informations?

Environment

  System:
    OS: macOS 13.2
  Binaries:
    Node: 16.19.1 - ~/.nvm/versions/node/v16.19.1/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v16.19.1/bin/yarn
    npm: 8.19.3 - ~/.nvm/versions/node/v16.19.1/bin/npm
  npmPackages:
    @babel/cli: ^7.21.0 => 7.21.0
    @babel/core: ^7.21.4 => 7.21.4
    @babel/plugin-transform-runtime: ^7.21.4 => 7.21.4
    @babel/preset-env: ^7.21.4 => 7.21.4
    @babel/runtime: ^7.21.0 => 7.21.0
    @babel/runtime-corejs3: ^7.21.0 => 7.21.0

Possible solution

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    i: needs triageoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions