aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2011-11-20 00:35:15 -0800
committerAlon Zakai <alonzakai@gmail.com>2011-11-20 00:35:15 -0800
commitdfe5f60e7c44d3f7fc7ac92e0ce6e76497319480 (patch)
tree17b297b308b65f7047162a602b5e308c890567f7 /tools
parenta1dce8a3413e8a72e4f2ecba4d6b4f771c8216e6 (diff)
js optimizer fix, and remove assigns to undefined in library
Diffstat (limited to 'tools')
-rw-r--r--tools/js-optimizer.js12
-rw-r--r--tools/test-js-optimizer.js1
2 files changed, 12 insertions, 1 deletions
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js
index bc993eae..5aeee636 100644
--- a/tools/js-optimizer.js
+++ b/tools/js-optimizer.js
@@ -160,7 +160,6 @@ function unGlobalize(ast) {
// This pass assumes that unGlobalize has been run, so undefined
// is now explicit.
function removeAssignsToUndefined(ast) {
- // TODO: in vars too
traverse(ast, function(node, type) {
if (type == 'assign' && jsonCompare(node[3], ['unary-prefix', 'void', ['num', 0]])) {
return emptyNode();
@@ -173,6 +172,17 @@ function removeAssignsToUndefined(ast) {
});
}
});
+ // cleanup (|x = y = void 0| leaves |x = ;| right now)
+ var modified = true;
+ while (modified) {
+ modified = false;
+ traverse(ast, function(node, type) {
+ if (type == 'assign' && jsonCompare(node[3], emptyNode())) {
+ modified = true;
+ return emptyNode();
+ }
+ });
+ }
}
// Main
diff --git a/tools/test-js-optimizer.js b/tools/test-js-optimizer.js
index 042f4cf9..05e574f9 100644
--- a/tools/test-js-optimizer.js
+++ b/tools/test-js-optimizer.js
@@ -7,6 +7,7 @@ function abc() {
var fleefl;
cheez = 10;
fleefl = x;
+ fleefl = cheez = x;
var waka = x, flake = x, marfoosh = x;
var waka2 = 5, flake2 = x, marfoosh2 = x;
var waka3 = x, flake3 = 5, marfoosh3 = x;