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

plugin-transform-runtime doesn't honor preset-env targets when corejs option is set #9363

Closed
blicksky opened this issue Jan 18, 2019 · 3 comments
Labels
i: bug i: needs triage outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@blicksky
Copy link

Bug Report

I've observed that plugin-transform-runtime does not conditionally transform a feature based on preset-env's configured targets when the corejs option is set. The specific example I ran into was when using Object.entries, which is supported on Node 8, but not supported on Node 6.

Current Behavior
When preset-env is configured with { targets: { node: 6 }, useBuiltIns: 'usage' }, then an Object.entires polyfill is included in the transpiled output. If the node version is changed to 8, then this polyfill is no longer included. If plugin-transform-runtime is configured with { corejs: 2 }, then corejs's Object.entries implementation is included in the transpiled output when the node version is set to 6 or 8.

Input Code

Object.entries({foo: 'bar'});

See https://repl.it/@blicksky/babel-transform-runtime-tests for a set of test cases that reproduces this scenario.

Expected behavior/code
When preset-env is configured with { targets: { node: 8 }, useBuiltIns: 'usage' } and plugin-transform-runtime is configured with { corejs: 2 }, then usages of Object.entries in the input code should not be replaced with corejs's implementation in the transpiled output.

Babel Configuration (.babelrc, package.json, cli command)

{
    babelrc: false,
    presets: [
        ['@babel/preset-env', {
            targets: { node: 8 },
            useBuiltIns: 'usage'
        }]
    ],
    plugins: [
        ['@babel/plugin-transform-runtime', {
            corejs: 2
        }]
    ]
}

Environment

  • Babel version(s):
    • @babel/core: 7.2.2,
    • @babel/preset-env: 7.2.3,
    • @babel/plugin-transform-runtime: 7.2.0
    • @babel/runtime-corejs2: 7.2.0
  • Node/npm version: Node 9.7.1
  • OS: observed behavior on both Linux and MacOS
  • Monorepo: N/A
  • How you are using Babel: observed behavior via both the CLI and API
@babel-bot
Copy link
Collaborator

Hey @blicksky! 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.

@rjgotten
Copy link

Same issue here. This is a web-performance deal-breaker for me.

Even on a trivial script bundle which only uses the when-dom-ready package, this makes a difference between 227 KB using corejs : 3 and 2 KB with corejs : false.

@nicolo-ribaudo
Copy link
Member

This has been implemented in the new babel-polyfills repository.

You can now install babel-plugin-polyfill-corejs2, and configure it like this:

{
  "plugins": [
    ["polyfill-corejs2", {
      "method": "usage-pure",
      "targets": { "node": 8 }
    }]
  ]
}

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Aug 29, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: bug i: needs triage outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants