Make constant propagation smarter about pruning if statements.
Ben Newman committed
Sep 11, 2013 at 17:56 UTC
adda400602291d913eaa9d28d9883ac649edb814
3 files changed
+15
-15
package.json
+1
-1
@@ -50,7 +50,7 @@
50
"grunt-contrib-jshint": "~0.6.0",
51
"optimist": "~0.6.0",
52
"phantomjs": "~1.9.1-4",
53
- "recast": "~0.4.8",
53
+ "recast": "~0.4.16",
54
"semver": "~2.1.0",
55
"uglify-js": "~2.4.0",
56
"grunt-contrib-clean": "~0.5.0",
src/dom/DOMPropertyOperations.js
+7
-13
@@ -87,12 +87,10 @@ var DOMPropertyOperations = {
87
}
88
return processAttributeNameAndPrefix(name) +
89
escapeTextForBrowser(value) + '"';
90
- } else {
91
- if (__DEV__) {
92
- warnUnknownProperty(name);
93
- }
94
- return null;
90
+ } else if (__DEV__) {
91
+ warnUnknownProperty(name);
92
}
93
+ return null;
94
},
95
96
/**
@@ -121,10 +119,8 @@ var DOMPropertyOperations = {
119
}
120
} else if (DOMProperty.isCustomAttribute(name)) {
121
node.setAttribute(name, value);
124
- } else {
125
- if (__DEV__) {
126
- warnUnknownProperty(name);
127
- }
122
+ } else if (__DEV__) {
123
+ warnUnknownProperty(name);
124
}
125
},
126
@@ -150,10 +146,8 @@ var DOMPropertyOperations = {
146
}
147
} else if (DOMProperty.isCustomAttribute(name)) {
148
node.removeAttribute(name);
153
- } else {
154
- if (__DEV__) {
155
- warnUnknownProperty(name);
156
- }
149
+ } else if (__DEV__) {
150
+ warnUnknownProperty(name);
151
}
152
}
153
vendor/constants.js
+7
-1
@@ -53,7 +53,13 @@ var ConstantVisitor = recast.Visitor.extend({
53
} else if (stmt.alternate) {
54
return stmt.alternate;
55
} else {
56
- this.remove();
56
+ // In case this if statement is an alternate clause for another
57
+ // if-statement, replacing that alternate with null will have the
58
+ // effect of pruning the unnecessary clause. If this is just a
59
+ // free-floating if statement, replacing it with null will have
60
+ // the effect of removing it from the enclosing list of
61
+ // statements.
62
+ return null;
63
}
64
}
65
}