diff --git a/src/babel/transformation/transformers/es6/tail-call.js b/src/babel/transformation/transformers/es6/tail-call.js index 495d88591a..12fb5a8a8d 100644 --- a/src/babel/transformation/transformers/es6/tail-call.js +++ b/src/babel/transformation/transformers/es6/tail-call.js @@ -181,9 +181,11 @@ class TailCallTransformer { var declarations = flatten(map(this.vars, function (decl) { return decl.declarations; })); + var assignment = reduceRight(declarations, function (expr, decl) { return t.assignmentExpression("=", decl.id, expr); }, t.identifier("undefined")); + var statement = t.expressionStatement(assignment); statement._blockHoist = Infinity; body.unshift(statement); @@ -191,7 +193,9 @@ class TailCallTransformer { var paramDecls = this.paramDecls; if (paramDecls.length > 0) { - body.unshift(t.variableDeclaration("var", paramDecls)); + var paramDecl = t.variableDeclaration("var", paramDecls); + paramDecl._blockHoist = Infinity; + body.unshift(paramDecl); } body.unshift(t.expressionStatement( diff --git a/test/core/fixtures/transformation/es6.tail-call/call-apply/expected.js b/test/core/fixtures/transformation/es6.tail-call/call-apply/expected.js index c54d8457eb..a243561b14 100755 --- a/test/core/fixtures/transformation/es6.tail-call/call-apply/expected.js +++ b/test/core/fixtures/transformation/es6.tail-call/call-apply/expected.js @@ -7,8 +7,8 @@ var _again = true; _function: while (_again) { - _again = false; var n = _x; + _again = false; if (n <= 0) { console.log(_this, _arguments); diff --git a/test/core/fixtures/transformation/es6.tail-call/expressions/expected.js b/test/core/fixtures/transformation/es6.tail-call/expressions/expected.js index 785a0413cc..306683936e 100755 --- a/test/core/fixtures/transformation/es6.tail-call/expressions/expected.js +++ b/test/core/fixtures/transformation/es6.tail-call/expressions/expected.js @@ -6,8 +6,8 @@ var _again = true; _function: while (_again) { - _again = false; var n = _x; + _again = false; if (n <= 0) { return "foo"; } else { @@ -26,4 +26,4 @@ continue _function; } } -})(1000000, true) === "foo"; \ No newline at end of file +})(1000000, true) === "foo"; diff --git a/test/core/fixtures/transformation/es6.tail-call/factorial/expected.js b/test/core/fixtures/transformation/es6.tail-call/factorial/expected.js index 3277ad8120..005b1e39a2 100644 --- a/test/core/fixtures/transformation/es6.tail-call/factorial/expected.js +++ b/test/core/fixtures/transformation/es6.tail-call/factorial/expected.js @@ -5,9 +5,9 @@ function fact(_x2) { var _again = true; _function: while (_again) { + var n = _x2; acc = undefined; _again = false; - var n = _x2; var acc = _arguments[1] === undefined ? 1 : _arguments[1]; if (n > 1) { _arguments = [_x2 = n - 1, acc * n]; @@ -17,4 +17,4 @@ function fact(_x2) { return acc; } } -} \ No newline at end of file +} diff --git a/test/core/fixtures/transformation/es6.tail-call/recursion/expected.js b/test/core/fixtures/transformation/es6.tail-call/recursion/expected.js index 68726e0d21..ebec4402e3 100755 --- a/test/core/fixtures/transformation/es6.tail-call/recursion/expected.js +++ b/test/core/fixtures/transformation/es6.tail-call/recursion/expected.js @@ -5,12 +5,12 @@ var _again = true; _function: while (_again) { + var n = _x2; m = local1 = local2 = local3 = undefined; var g = function g() {}; _again = false; - var n = _x2; var m = _arguments[1] === undefined ? getDefaultValue() : _arguments[1]; // `m` should be `getDefaultValue()` after first pass @@ -27,4 +27,4 @@ _again = true; continue _function; } -})(1000000, true) === "foo"; \ No newline at end of file +})(1000000, true) === "foo"; diff --git a/test/core/fixtures/transformation/es6.tail-call/try-catch/expected.js b/test/core/fixtures/transformation/es6.tail-call/try-catch/expected.js index c3f3b9bc69..434dad6698 100755 --- a/test/core/fixtures/transformation/es6.tail-call/try-catch/expected.js +++ b/test/core/fixtures/transformation/es6.tail-call/try-catch/expected.js @@ -14,8 +14,8 @@ var _again = true; _function: while (_again) { - _again = false; var n = _x; + _again = false; if (n <= 0) { return "foo"; @@ -47,8 +47,8 @@ var _again2 = true; _function2: while (_again2) { - _again2 = false; var n = _x2; + _again2 = false; if (n <= 0) { return "foo"; @@ -60,4 +60,4 @@ continue _function2; } } -})(1000000) === "foo"; \ No newline at end of file +})(1000000) === "foo";