diff --git a/packages/babel-plugin-transform-destructuring/src/index.js b/packages/babel-plugin-transform-destructuring/src/index.js index 3e8bd464298c..2daa2604d42f 100644 --- a/packages/babel-plugin-transform-destructuring/src/index.js +++ b/packages/babel-plugin-transform-destructuring/src/index.js @@ -83,7 +83,11 @@ export default declare((api, options) => { if (op) { node = t.expressionStatement( - t.assignmentExpression(op, id, t.cloneNode(init)), + t.assignmentExpression( + op, + id, + t.cloneNode(init) || this.scope.buildUndefinedNode(), + ), ); } else { node = t.variableDeclaration(this.kind, [ diff --git a/packages/babel-plugin-transform-destructuring/test/fixtures/destructuring/array-unpack-optimisation/input.js b/packages/babel-plugin-transform-destructuring/test/fixtures/destructuring/array-unpack-optimisation/input.js index 87493c5fd57f..935a280524fc 100644 --- a/packages/babel-plugin-transform-destructuring/test/fixtures/destructuring/array-unpack-optimisation/input.js +++ b/packages/babel-plugin-transform-destructuring/test/fixtures/destructuring/array-unpack-optimisation/input.js @@ -11,3 +11,7 @@ var [a, b] = [...foo, bar]; var [a, b] = [foo(), bar]; var [a, b] = [clazz.foo(), bar]; var [a, b] = [clazz.foo, bar]; +var [a, b] = [, 2]; +[a, b] = [1, 2]; +[a, b] = [, 2]; +; // Avoid completion record special case diff --git a/packages/babel-plugin-transform-destructuring/test/fixtures/destructuring/array-unpack-optimisation/output.js b/packages/babel-plugin-transform-destructuring/test/fixtures/destructuring/array-unpack-optimisation/output.js index 32816cdc73c4..7de1af1261e7 100644 --- a/packages/babel-plugin-transform-destructuring/test/fixtures/destructuring/array-unpack-optimisation/output.js +++ b/packages/babel-plugin-transform-destructuring/test/fixtures/destructuring/array-unpack-optimisation/output.js @@ -34,3 +34,10 @@ var _ref7 = [clazz.foo(), bar], var _ref8 = [clazz.foo, bar], a = _ref8[0], b = _ref8[1]; +var a, + b = 2; +a = 1; +b = 2; +a = void 0; +b = 2; +; // Avoid completion record special case