Merge pull request #343 from benjamn/fix-if-statement-pruning

Make constant propagation smarter about pruning if statements
This commit is contained in:
Ben Newman
2013-09-18 11:10:56 -07:00
3 changed files with 15 additions and 15 deletions
+1 -1
View File
@@ -50,7 +50,7 @@
"grunt-contrib-jshint": "~0.6.0",
"optimist": "~0.6.0",
"phantomjs": "~1.9.1-4",
"recast": "~0.4.8",
"recast": "~0.4.16",
"semver": "~2.1.0",
"uglify-js": "~2.4.0",
"grunt-contrib-clean": "~0.5.0",
+7 -13
View File
@@ -87,12 +87,10 @@ var DOMPropertyOperations = {
}
return processAttributeNameAndPrefix(name) +
escapeTextForBrowser(value) + '"';
} else {
if (__DEV__) {
warnUnknownProperty(name);
}
return null;
} else if (__DEV__) {
warnUnknownProperty(name);
}
return null;
},
/**
@@ -121,10 +119,8 @@ var DOMPropertyOperations = {
}
} else if (DOMProperty.isCustomAttribute(name)) {
node.setAttribute(name, value);
} else {
if (__DEV__) {
warnUnknownProperty(name);
}
} else if (__DEV__) {
warnUnknownProperty(name);
}
},
@@ -150,10 +146,8 @@ var DOMPropertyOperations = {
}
} else if (DOMProperty.isCustomAttribute(name)) {
node.removeAttribute(name);
} else {
if (__DEV__) {
warnUnknownProperty(name);
}
} else if (__DEV__) {
warnUnknownProperty(name);
}
}
+7 -1
View File
@@ -53,7 +53,13 @@ var ConstantVisitor = recast.Visitor.extend({
} else if (stmt.alternate) {
return stmt.alternate;
} else {
this.remove();
// In case this if statement is an alternate clause for another
// if-statement, replacing that alternate with null will have the
// effect of pruning the unnecessary clause. If this is just a
// free-floating if statement, replacing it with null will have
// the effect of removing it from the enclosing list of
// statements.
return null;
}
}
}