diff options
author | Ryan Kelly <ryan@rfk.id.au> | 2014-01-21 17:43:09 +1100 |
---|---|---|
committer | Ryan Kelly <ryan@rfk.id.au> | 2014-01-21 17:43:09 +1100 |
commit | 7a8c26b65f906de5f7490311e89eb6d5bf722211 (patch) | |
tree | c9504c16d0abe5de24b64f1d9789a7496c065a1d | |
parent | d806b71796493113e000b1dd5f918aaab691aba0 (diff) |
Minify loop labels while we're minifying local names.
-rw-r--r-- | tools/js-optimizer.js | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js index d604f546..98cb4c49 100644 --- a/tools/js-optimizer.js +++ b/tools/js-optimizer.js @@ -2870,7 +2870,6 @@ function minifyLocals(ast) { } }); - // Traverse and minify all names. // The first time we encounter a local name, we assign it a // minified name that's not currently in use. Allocating on // demand means they're processed in a predicatable order, @@ -2887,6 +2886,17 @@ function minifyLocals(ast) { } } } + + // We can also minify loop labels, using a separate namespace + // to the variable declarations. + var newLabels = {}; + var nextMinifiedLabel = 0; + function getNextMinifiedLabel() { + ensureMinifiedNames(nextMinifiedLabel); + return minifiedNames[nextMinifiedLabel++]; + } + + // Traverse and minify all names. if (fun[1] in extraInfo.globals) { fun[1] = extraInfo.globals[fun[1]]; assert(fun[1]); @@ -2917,6 +2927,15 @@ function minifyLocals(ast) { } defn[0] = newNames[name]; }); + } else if (type === 'label') { + if (!newLabels[node[1]]) { + newLabels[node[1]] = getNextMinifiedLabel(); + } + node[1] = newLabels[node[1]]; + } else if (type === 'break' || type === 'continue') { + if (node[1]) { + node[1] = newLabels[node[1]]; + } } }); |