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

Helper _objectSpread is not imported when using transform runtime with helpers #10334

Closed
csvn opened this issue Aug 13, 2019 · 2 comments
Closed
Labels
i: bug i: needs triage outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@csvn
Copy link

csvn commented Aug 13, 2019

Bug Report

Current Behavior
A __objectSpread function is created locally, and not imported, with @babel/plugin-transform-runtime and helpers: true.

import _defineProperty from "@babel/runtime/helpers/esm/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 a = {
  foo: '1'
};

var b = _objectSpread({}, a, {
  bar: '2'
});

console.log(b);

Input Code

const a = { foo: '1' };
const b = { ...a, bar: '2' };
console.log(b);

Expected behavior/code
__objectSpread should be imported when using @babel/plugin-transform-runtime and helpers: true.

import _objectSpread from "@babel/runtime/helpers/esm/objectSpread";

var a = {
  foo: '1'
};

var b = _objectSpread({}, a, {
  bar: '2'
});

console.log(b);

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

// babel.config.js
module.exports = {
  presets: [
    ['@babel/preset-env', {
      targets: 'IE 11',
      modules: false
    }]
  ],
  plugins: [
    ['@babel/plugin-transform-runtime', {
      helpers: true,
      useESModules: true
    }]
  ]
};
{
  "scripts": {
    "start": "babel src --out-dir dist"
  },
  "private": true,
  "license": "UNLICENSED",
  "dependencies": {
    "@babel/runtime": "^7.5.5"
  },
  "devDependencies": {
    "@babel/cli": "^7.5.5",
    "@babel/core": "^7.5.5",
    "@babel/plugin-transform-runtime": "^7.5.5",
    "@babel/preset-env": "^7.5.5"
  }
}
npm run start
# or
npx babel src--out-dir dist

Environment

  • Babel version(s): 7.5.5
  • Node/npm version: 12.3.1 / 6.9.0
  • OS: Windows 10
  • Monorepo: no
  • How you are using Babel: cli

Possible Solution

Additional context/Screenshots
The reproduction is a trimmed down version of our project, that is using Webpack. I noticed when creating a minimal reproduction project that the issue can be seen by simply using the @babel/cli.

@babel-bot
Copy link
Collaborator

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

@csvn
Copy link
Author

csvn commented Aug 13, 2019

Wow, sorry! I found #10261 just after I created this issue. I couldn't find it when I searched earlier on google, so I missed it.

@csvn csvn closed this as completed Aug 13, 2019
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Nov 12, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Nov 12, 2019
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

No branches or pull requests

2 participants