diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-03-08 18:02:57 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-03-08 18:02:57 -0800 |
commit | 99a6455bffe5598b0b33ff95d30b9b0fb61976b4 (patch) | |
tree | 5afc638d3e43731b81f016704982dff43ef84804 /tools | |
parent | c65bba4e0d06db216c1176c4b02f98d816a9cfd7 (diff) |
properly scan all globals, including function names, before applying them
Diffstat (limited to 'tools')
-rw-r--r-- | tools/js-optimizer.js | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js index c3cb7f39..59ec1c3b 100644 --- a/tools/js-optimizer.js +++ b/tools/js-optimizer.js @@ -2177,6 +2177,7 @@ function minifyGlobals(ast) { var minified = {}; var next = 0; var first = true; // do not minify initial 'var asm =' + // find the globals traverse(ast, function(node, type) { if (type == 'var') { if (first) { @@ -2188,16 +2189,19 @@ function minifyGlobals(ast) { var name = vars[i][0]; vars[i][0] = minified[name] = minifierInfo.names[next++]; } - } else if (type == 'name') { + } + }); + // add all globals in function chunks, i.e. not here but passed to us + for (var i = 0; i < minifierInfo.globals.length; i++) { + name = minifierInfo.globals[i]; + minified[name] = minifierInfo.names[next++]; + } + // apply minification + traverse(ast, function(node, type) { + if (type == 'name') { var name = node[1]; if (name in minified) { node[1] = minified[name]; - } else if (name == 'EMSCRIPTEN_FUNCS') { - // minify all the globals - for (var i = 0; i < minifierInfo.globals.length; i++) { - name = minifierInfo.globals[i]; - minified[name] = minifierInfo.names[next++]; - } } } }); |