Fix destructuring in pipeline operator (#6515)

* Fix destructuring in pipeline operator

Fixes #6514.

* Run exec only on node 6
This commit is contained in:
Justin Ridgewell 2017-10-19 15:59:36 -04:00 committed by GitHub
parent 923fd4705e
commit 8d4674ca5a
5 changed files with 33 additions and 2 deletions

View File

@ -18,9 +18,9 @@ export default function({ types: t }) {
if (optimizeArrow) {
const { params } = right;
if (params.length === 1) {
if (params.length === 1 && t.isIdentifier(params[0])) {
param = params[0];
} else if (params.length > 1) {
} else if (params.length > 0) {
optimizeArrow = false;
}
} else if (t.isIdentifier(right, { name: "eval" })) {

View File

@ -0,0 +1,7 @@
// Array destructing
const result = [0] |> ([x]) => x;
assert.equal(result, 0);
// Object destructuring
const result2 = { y: 1, z: 2 } |> ({ y, z }) => y + z;
assert.equal(result, 3);

View File

@ -0,0 +1,7 @@
// Array destructing
const result = [0] |> ([x]) => x;
assert.equal(result, 0);
// Object destructuring
const result2 = { y: 1, z: 2 } |> ({ y, z }) => y + z;
assert.equal(result2, 3);

View File

@ -0,0 +1,14 @@
var _ref, _y$z;
// Array destructing
const result = (_ref = [0], (([x]) => x)(_ref));
assert.equal(result, 0); // Object destructuring
const result2 = (_y$z = {
y: 1,
z: 2
}, (({
y,
z
}) => y + z)(_y$z));
assert.equal(result, 3);

View File

@ -0,0 +1,3 @@
{
"minNodeVersion": "6.0.0"
}