break let scoping transformer if there are no block scoped references

This commit is contained in:
Sebastian McKenzie 2015-01-18 21:37:37 +11:00
parent a80945cfb4
commit 4844882f5e

View File

@ -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);