From 9318d63b5cb3a8443d46200d1c6d9b82dfa994f5 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Mon, 10 Nov 2014 08:16:47 +1100 Subject: [PATCH] add let-scoping-return template to let scoping transformer --- lib/6to5/templates/let-scoping-return.js | 1 + lib/6to5/transformation/transformers/let-scoping.js | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) create mode 100644 lib/6to5/templates/let-scoping-return.js diff --git a/lib/6to5/templates/let-scoping-return.js b/lib/6to5/templates/let-scoping-return.js new file mode 100644 index 0000000000..c5ec90d02f --- /dev/null +++ b/lib/6to5/templates/let-scoping-return.js @@ -0,0 +1 @@ +if (typeof RETURN === "object") return RETURN.v; diff --git a/lib/6to5/transformation/transformers/let-scoping.js b/lib/6to5/transformation/transformers/let-scoping.js index 624e5358c6..d7d7709b05 100644 --- a/lib/6to5/transformation/transformers/let-scoping.js +++ b/lib/6to5/transformation/transformers/let-scoping.js @@ -287,10 +287,9 @@ var run = function (forParent, block, parent, file, scope) { if (has.hasReturn) { // typeof ret === "object" - retCheck = t.ifStatement( - t.binaryExpression("===", t.unaryExpression("typeof", ret, true), t.literal("object")), - t.returnStatement(t.memberExpression(ret, t.identifier("v"))) - ); + retCheck = util.template("let-scoping-return", { + RETURN: ret, + }); // there's no `break` or `continue` so we can just push in the `if` if (!has.hasBreak && !has.hasContinue) {