From f47d17345cf02224ad2106412ac1f11f46cd3ada Mon Sep 17 00:00:00 2001 From: Logan Smyth Date: Fri, 3 Jul 2015 11:23:02 -0700 Subject: [PATCH] Ensure _blockHoist is set on function destructuring defaults - fixes #1908 --- src/babel/transformation/transformers/es6/destructuring.js | 7 +++++-- .../transformation/es6.destructuring/parameters/actual.js | 2 +- .../es6.destructuring/parameters/expected.js | 4 +++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/babel/transformation/transformers/es6/destructuring.js b/src/babel/transformation/transformers/es6/destructuring.js index ebf7751d7a..c87c5f8214 100644 --- a/src/babel/transformation/transformers/es6/destructuring.js +++ b/src/babel/transformation/transformers/es6/destructuring.js @@ -316,9 +316,12 @@ class DestructuringTransformer { var left = pattern.left; if (t.isPattern(left)) { - this.nodes.push(t.expressionStatement( + var tempValueDefault = t.expressionStatement( t.assignmentExpression("=", tempValueRef, tempConditional) - )); + ); + tempValueDefault._blockHoist = this.blockHoist; + + this.nodes.push(tempValueDefault); this.push(left, tempValueRef); } else { this.nodes.push(this.buildVariableAssignment(left, tempConditional)); diff --git a/test/core/fixtures/transformation/es6.destructuring/parameters/actual.js b/test/core/fixtures/transformation/es6.destructuring/parameters/actual.js index 4446360a01..23e062af36 100644 --- a/test/core/fixtures/transformation/es6.destructuring/parameters/actual.js +++ b/test/core/fixtures/transformation/es6.destructuring/parameters/actual.js @@ -1,4 +1,4 @@ -function somethingAdvanced({topLeft: {x: x1, y: y1}, bottomRight: {x: x2, y: y2}}){ +function somethingAdvanced({topLeft: {x: x1, y: y1} = {}, bottomRight: {x: x2, y: y2} = {}}, p2, p3){ } diff --git a/test/core/fixtures/transformation/es6.destructuring/parameters/expected.js b/test/core/fixtures/transformation/es6.destructuring/parameters/expected.js index 50365469a1..dc5d19e9ef 100644 --- a/test/core/fixtures/transformation/es6.destructuring/parameters/expected.js +++ b/test/core/fixtures/transformation/es6.destructuring/parameters/expected.js @@ -1,10 +1,12 @@ "use strict"; -function somethingAdvanced(_ref) { +function somethingAdvanced(_ref, p2, p3) { var _ref$topLeft = _ref.topLeft; + _ref$topLeft = _ref$topLeft === undefined ? {} : _ref$topLeft; var x1 = _ref$topLeft.x; var y1 = _ref$topLeft.y; var _ref$bottomRight = _ref.bottomRight; + _ref$bottomRight = _ref$bottomRight === undefined ? {} : _ref$bottomRight; var x2 = _ref$bottomRight.x; var y2 = _ref$bottomRight.y; }