From 9e3c67a8a216559b27e6f2ed26e4493c09739486 Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Sun, 8 Feb 2015 10:53:09 +0200 Subject: [PATCH] Clean up `functionChildrenVisitor` a bit. --- .../transformers/es6/tail-call.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/lib/6to5/transformation/transformers/es6/tail-call.js b/lib/6to5/transformation/transformers/es6/tail-call.js index 5ad846c8cc..6d061bcf11 100644 --- a/lib/6to5/transformation/transformers/es6/tail-call.js +++ b/lib/6to5/transformation/transformers/es6/tail-call.js @@ -62,19 +62,16 @@ var functionChildrenVisitor = { // transform return argument into statement if // it contains tail recursion transformExpression(node.argument, scope, state); - return; } else if (t.isFunction(node)) { - return this.skip(); + // inner function's bodies are irrelevant + this.skip(); } else if (t.isTryStatement(parent)) { if (node === parent.block) { - return this.skip(); - } else if (node === parent.finalizer) { - return; - } else { - if (parent.finalizer) { - this.skip(); - } - return; + // `try`-blocks can't be optimized + this.skip(); + } else if (parent.finalizer && node !== parent.finalizer) { + // `catch` clause followed by `finally` can't be optimized + this.skip(); } } }