From dfe5f60e7c44d3f7fc7ac92e0ce6e76497319480 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Sun, 20 Nov 2011 00:35:15 -0800 Subject: js optimizer fix, and remove assigns to undefined in library --- tools/js-optimizer.js | 12 +++++++++++- tools/test-js-optimizer.js | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'tools') 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; -- cgit v1.2.3-18-g5258