From adda400602291d913eaa9d28d9883ac649edb814 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Wed, 11 Sep 2013 17:56:42 -0400 Subject: [PATCH] Make constant propagation smarter about pruning if statements. --- package.json | 2 +- src/dom/DOMPropertyOperations.js | 20 +++++++------------- vendor/constants.js | 8 +++++++- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index a8d669b49b..cf0db02cf1 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/dom/DOMPropertyOperations.js b/src/dom/DOMPropertyOperations.js index 9dcc2e2471..e5aec159b0 100644 --- a/src/dom/DOMPropertyOperations.js +++ b/src/dom/DOMPropertyOperations.js @@ -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); } } diff --git a/vendor/constants.js b/vendor/constants.js index 339398c2a8..935b0561c6 100644 --- a/vendor/constants.js +++ b/vendor/constants.js @@ -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; } } }