Skip to content

Commit

Permalink
Fix destructuring assignment in arrow functions. (babel#8916)
Browse files Browse the repository at this point in the history
Fixes 8912.
  • Loading branch information
RubenVerborgh authored and nicolo-ribaudo committed Nov 25, 2018
1 parent ef2a539 commit 57e656d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/index.js
Expand Up @@ -540,7 +540,12 @@ export default declare((api, options) => {
destructuring.init(node.left, ref || node.right);

if (ref) {
nodes.push(t.expressionStatement(t.cloneNode(ref)));
if (path.parentPath.isArrowFunctionExpression()) {
path.replaceWith(t.blockStatement([]));
nodes.push(t.returnStatement(t.cloneNode(ref)));
} else {
nodes.push(t.expressionStatement(t.cloneNode(ref)));
}
}

path.replaceWithMultiple(nodes);
Expand Down
@@ -0,0 +1 @@
() => { [a, b] = [1, 2] }
@@ -0,0 +1,4 @@
() => {
a = 1;
b = 2;
};
@@ -0,0 +1 @@
() => [a, b] = [1, 2]
@@ -0,0 +1,6 @@
() => {
var _ref = [1, 2];
a = _ref[0];
b = _ref[1];
return _ref;
};

0 comments on commit 57e656d

Please sign in to comment.