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

@babel/plugin-proposal-object-rest-spread outputs verbose code as 7.5.0 #10423

Closed
peter-mouland opened this issue Sep 9, 2019 · 3 comments
Closed
Labels
i: bug i: duplicate outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@peter-mouland
Copy link

peter-mouland commented Sep 9, 2019

Bug Report

Current Behavior
as of 7.5.0 the output of my distributed code has become more verbose. I'm not sure if it's a bug or intended side-effect of another change. If it's intended, I haven't worked out how to reduce the output again.

Basically a single-line babel-helper has been replaced at the top of the file with multi in-line functions

Input Code

const test = { t: 'test' };
const { t } = test;
const foo = (...args) => args;

const a = ['a', 'b', 'c'];
const b = [...a, 'foo'];
const c = foo(...a);

export const es6a = foo;
export const es6b = { ...test, t, a, b, c };

output

import _defineProperty from "@babel/runtime/helpers/defineProperty";

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

var test = {
  t: 'test'
};
var t = test.t;

var foo = function foo() {
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
    args[_key] = arguments[_key];
  }

  return args;
};

var a = ['a', 'b', 'c'];
var b = [].concat(a, ['foo']);
var c = foo.apply(void 0, a);
export var es6a = foo;
export var es6b = _objectSpread({}, test, {
  t: t,
  a: a,
  b: b,
  c: c
});

Expected behavior/code
previously, 7.4.4, output included a helper and much less code.

output

import _objectSpread from "@babel/runtime/helpers/objectSpread";
var test = {
  t: 'test'
};
var t = test.t;

var foo = function foo() {
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
    args[_key] = arguments[_key];
  }

  return args;
};

var a = ['a', 'b', 'c'];
var b = [].concat(a, ['foo']);
var c = foo.apply(void 0, a);
export var es6a = foo;
export var es6b = _objectSpread({}, test, {
  t: t,
  a: a,
  b: b,
  c: c
});

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

module.exports = function babelConfig(api) {
    api.cache(true);

    return {
        presets: [
            [
                require('@babel/preset-env'),
                {
                    modules: false,
                },
            ],
        ],
        plugins: [
            require('@babel/plugin-transform-runtime'),
            require('@babel/plugin-proposal-object-rest-spread'),
        ],
    };
};

Environment

  • Babel version(s): 7.6.0
  • Node/npm version: v10.16.0
  • OS: OSX 10.14.6
  • Monorepo: yes, but reproduce-able in 2 files (js + config)
  • How you are using Babel: cli for reproducable example (but found change via node api)

Possible Solution
🤔

playing with the browser targets gives a desired output.

targets: {
        browsers: [ 'Chrome >= 61', 'Firefox >= 60', 'Opera >= 48' ],
},

has there been an update to the spec which these browsers no longer support?
is there another plugin or way that i can fill this gap rather than adding this code at the top of the file?

Additional context/Screenshots
none

@babel-bot
Copy link
Collaborator

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

@JLHwung
Copy link
Contributor

JLHwung commented Sep 10, 2019

It is intended for spec compliance. I notice that some of the helpers is not transformed to helper imports, in this case one may specify a helper version to transform-runtime. See #10261 (comment).

@JLHwung
Copy link
Contributor

JLHwung commented Sep 10, 2019

Close as it duplicates #10261

@JLHwung JLHwung closed this as completed Sep 10, 2019
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Dec 10, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Dec 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: bug i: duplicate outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

3 participants