update minification.constantFolding transformer to deopt bindings that are reassigned in a different function scope

This commit is contained in:
Sebastian McKenzie 2015-06-05 23:01:31 +01:00
parent 9f2b739046
commit 6296f49653

View File

@ -11,7 +11,7 @@ export function AssignmentExpression() {
if (!left.isIdentifier()) return;
var binding = this.scope.getBinding(left.node.name);
if (!binding || binding.deoptValue) return;
if (!binding || binding.hasDeoptValue) return;
var evaluated = this.get("right").evaluate();
if (evaluated.confident) {
@ -33,6 +33,25 @@ export function IfStatement() {
}
export var Scopable = {
enter() {
var funcScope = this.scope.getFunctionParent();
for (var name in this.scope.bindings) {
var binding = this.scope.bindings[name];
var deopt = false;
for (var path of (binding.constantViolations: Array)) {
var funcViolationScope = path.scope.getFunctionParent();
if (funcViolationScope !== funcScope) {
deopt = true;
break;
}
}
if (deopt) binding.deoptValue();
}
},
exit() {
for (var name in this.scope.bindings) {
var binding = this.scope.bindings[name];