From 25566a24f6555ce1319f75b0dcd14378c3fbf8f2 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Sun, 1 Feb 2015 18:33:36 +1100 Subject: [PATCH] block hoist assignment pattern destructuring - fixes #652 --- .../transformation/transformers/es6/destructuring.js | 6 ++++-- .../transformation/regenerator/destructuring/exec.js | 9 ++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/6to5/transformation/transformers/es6/destructuring.js b/lib/6to5/transformation/transformers/es6/destructuring.js index bf94da2cca..246edf31ee 100644 --- a/lib/6to5/transformation/transformers/es6/destructuring.js +++ b/lib/6to5/transformation/transformers/es6/destructuring.js @@ -46,9 +46,11 @@ var push = function (opts, nodes, elem, parentId) { var pushAssignmentPattern = function (opts, nodes, pattern, parentId) { var tempParentId = opts.scope.generateUidBasedOnNode(parentId, opts.file); - nodes.push(t.variableDeclaration("var", [ + var declar = t.variableDeclaration("var", [ t.variableDeclarator(tempParentId, parentId) - ])); + ]); + declar._blockHoist = opts.blockHoist; + nodes.push(declar); nodes.push(buildVariableAssign( opts, diff --git a/test/fixtures/transformation/regenerator/destructuring/exec.js b/test/fixtures/transformation/regenerator/destructuring/exec.js index b9cf63e289..483a5724c1 100644 --- a/test/fixtures/transformation/regenerator/destructuring/exec.js +++ b/test/fixtures/transformation/regenerator/destructuring/exec.js @@ -3,4 +3,11 @@ function* foo() { return bar; } -assert.deepEqual(foo().next().value, "bar"); +assert.equal(foo().next().value, "bar"); + +function *foo({ bar = 0 }) { + return bar; +} + +assert.equal(foo({ bar: undefined }).next(), 0); +assert.equal(foo({ bar: 3 }).next(), 3);