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.file = file;
this.outsideLetReferences = {}; this.outsideLetReferences = {};
this.hasLetReferences = false;
this.letReferences = {}; this.letReferences = {};
this.body = []; this.body = [];
} }
@ -99,9 +100,12 @@ LetScoping.prototype.run = function () {
var needsClosure = this.getLetReferences(); var needsClosure = this.getLetReferences();
this.checkTDZ(); 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; if (t.isFunction(this.parent) || t.isProgram(this.block)) return;
// we can skip everything
if (!this.hasLetReferences) return;
if (needsClosure) { if (needsClosure) {
this.needsClosure(); this.needsClosure();
} else { } else {
@ -284,8 +288,12 @@ LetScoping.prototype.getLetReferences = function () {
declar = declarators[i]; declar = declarators[i];
var keys = t.getIds(declar, true); var keys = t.getIds(declar, true);
_.extend(this.letReferences, keys); _.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 // set let references to plain var references
standardiseLets(declarators); standardiseLets(declarators);