Skip to content

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

@blicksky

Description

@blicksky

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

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