diff --git a/lib/6to5/transformation/transformers/es6/tail-call.js b/lib/6to5/transformation/transformers/es6/tail-call.js index 2cc9ec4fed..ce02115ab6 100644 --- a/lib/6to5/transformation/transformers/es6/tail-call.js +++ b/lib/6to5/transformation/transformers/es6/tail-call.js @@ -294,7 +294,15 @@ TailCallTransformer.prototype.subTransformCallExpression = function (node) { // looks for and replaces tail recursion calls var firstPass = { enter: function (node, parent, scope, state) { - if (t.isReturnStatement(node)) { + if (t.isIfStatement(node)) { + if (t.isReturnStatement(node.alternate)) { + t.ensureBlock(node, "alternate"); + } + + if (t.isReturnStatement(node.consequent)) { + t.ensureBlock(node, "consequent"); + } + } else if (t.isReturnStatement(node)) { this.skip(); return state.subTransform(node.argument); } else if (t.isTryStatement(parent)) { diff --git a/test/fixtures/transformation/es6-tail-call/expression-consequent/actual.js b/test/fixtures/transformation/es6-tail-call/expression-consequent/actual.js new file mode 100644 index 0000000000..0e0986168b --- /dev/null +++ b/test/fixtures/transformation/es6-tail-call/expression-consequent/actual.js @@ -0,0 +1,4 @@ +function f() { + if (true) {} + else return f() +} diff --git a/test/fixtures/transformation/es6-tail-call/expression-consequent/expected.js b/test/fixtures/transformation/es6-tail-call/expression-consequent/expected.js new file mode 100644 index 0000000000..6d106af2b0 --- /dev/null +++ b/test/fixtures/transformation/es6-tail-call/expression-consequent/expected.js @@ -0,0 +1,9 @@ +"use strict"; + +function f() { + _function: while (true) { + if (true) {} else { + continue _function; + } + } +}