From 4844882f5e5d79facbcb254e9467c712f45e793a Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Sun, 18 Jan 2015 21:37:37 +1100 Subject: [PATCH] break let scoping transformer if there are no block scoped references --- .../transformation/transformers/es6-let-scoping.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/6to5/transformation/transformers/es6-let-scoping.js b/lib/6to5/transformation/transformers/es6-let-scoping.js index ebff0352b3..5a9c829b31 100644 --- a/lib/6to5/transformation/transformers/es6-let-scoping.js +++ b/lib/6to5/transformation/transformers/es6-let-scoping.js @@ -83,6 +83,7 @@ function LetScoping(loopParent, block, parent, scope, file) { this.file = file; this.outsideLetReferences = {}; + this.hasLetReferences = false; this.letReferences = {}; this.body = []; } @@ -99,9 +100,12 @@ LetScoping.prototype.run = function () { var needsClosure = this.getLetReferences(); this.checkTDZ(); - // this is a block within a `Function` so we can safely leave it be + // this is a block within a `Function/Program` so we can safely leave it be if (t.isFunction(this.parent) || t.isProgram(this.block)) return; + // we can skip everything + if (!this.hasLetReferences) return; + if (needsClosure) { this.needsClosure(); } else { @@ -284,8 +288,12 @@ LetScoping.prototype.getLetReferences = function () { declar = declarators[i]; var keys = t.getIds(declar, true); _.extend(this.letReferences, keys); + this.hasLetReferences = true; } + // no let references so we can just quit + if (!this.hasLetReferences) return; + // set let references to plain var references standardiseLets(declarators);