Fix destructuring assignment in arrow functions. (#8916)

Fixes 8912.
This commit is contained in:
Ruben Verborgh 2018-11-25 19:29:58 +01:00 committed by Nicolò Ribaudo
parent 1b8d664bbe
commit 9308c870f5
5 changed files with 18 additions and 1 deletions

View File

@ -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);

View File

@ -0,0 +1,6 @@
() => {
var _ref = [1, 2];
a = _ref[0];
b = _ref[1];
return _ref;
};