babel-polyfills icon indicating copy to clipboard operation
babel-polyfills copied to clipboard

[Bug]: NodeList.prototype.forEach is not polyfilled in pure mode

Open fire332 opened this issue 3 years ago • 1 comments

💻

  • [ ] Would you like to work on a fix?

How are you using Babel?

babel-loader (webpack)

Input code

document.body.childNodes.forEach(x => {
  x;
})

Configuration file name

babel.config.js

Configuration

module.exports = (api) => {
  api.cache.never();

  return {
    sourceType: 'unambiguous',
    plugins: [
      // [
      //   'polyfill-corejs3',
      //   {
      //     method: 'usage-pure'
      //   }
      // ],
      [
        "@babel/plugin-transform-runtime",
        {
          "corejs": 3,
          "version": require('./package.json').dependencies['@babel/runtime-corejs3']
        }
      ]
    ]
  };
};

Current and expected behavior

There are no pollyfills whatsoever in the output. I expect there to be polyfills.

Environment

Node 17 on Windows. See minimal reproduction repo for tool versions.

Possible solution

No response

Additional context

This bug has already been filed in the core-js repo here and I've been told to file here.

Babel is not polyfilling NodeList.prototype.forEach when using @babel/plugin-transform-runtime or polyfill-corejs3 with method set to usage-pure. Babel polyfills correctly with method set to 'usage-global'. Additionally, [1].includes(1) is pollyfilled just fine with the same configs.

Minimal reproduction repo: polyfill-test.zip

Just run npm i && npx webpack.

fire332 avatar Jan 11 '22 17:01 fire332

Hey @fire332! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite.

babel-bot avatar Jan 11 '22 17:01 babel-bot

This looks to have been fixed.

liuxingbaoyu avatar Jan 24 '24 11:01 liuxingbaoyu