-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Closed
Labels
Has PRSpec: Object Rest/SpreadoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issueA closed issue/PR that is archived due to age. Recommended to make a new issue
Description
Choose one: is this a bug report or feature request?
Bug.
babel-plugin-transform-object-rest-spreadis not properly transforming code in some circumstances when deeply nested.
Input Code
function test([{ ...payload }]) {
console.dir(payload);
}
test([{}]);Babel Configuration (.babelrc, package.json, cli command)
.babelrc:
{
"presets": [
["env", { targets: { node: 6 } }]
],
"plugins": ["transform-object-rest-spread"]
}Expected Behavior
I would have expected output along the lines of:
"use strict";
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
function test(_ref) {
let payload = _objectWithoutProperties(_ref[0], []);
console.dir(payload);
}
test([{}]);Current Behavior
This transforms to:
"use strict";
function test([{ ...payload }]) {
console.dir(payload);
}
test([{}]);Possible Solution
I was using babel-preset-env alongside, and setting it's target to include node v4 or lower, or any browser version results in working code. Alternatively, you can add the following to the env config block in .babelrc:
include: [
"transform-es2015-parameters",
"transform-es2015-destructuring",
],Context
I was trying to roll context forward in a Promise chain, so I was using Promise.all(), each .then() clause was destructuring to get its needed information... That gave the magic combination of destructuring an object arg, in an array, in function args.
Your Environment
| software | version(s) |
|---|---|
| Babel | 6.24.1 |
babel-preset-env |
1.4.0 |
babel-plugin-transform-object-rest-spread |
6.23.0 |
| node | 6.10.0 |
| npm | 3.10.10 |
| Operating System | MacOS 10.12.3 |
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Has PRSpec: Object Rest/SpreadoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issueA closed issue/PR that is archived due to age. Recommended to make a new issue