aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/js-optimizer.js10
-rw-r--r--tools/js_optimizer.py18
2 files changed, 15 insertions, 13 deletions
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js
index ae72437b..fba97a14 100644
--- a/tools/js-optimizer.js
+++ b/tools/js-optimizer.js
@@ -149,10 +149,10 @@ function srcToAst(src) {
return uglify.parser.parse(src);
}
-function astToSrc(ast, compress) {
+function astToSrc(ast, minifyWhitespace) {
return uglify.uglify.gen_code(ast, {
ascii_only: true,
- beautify: !compress,
+ beautify: !minifyWhitespace,
indent_level: 1
});
}
@@ -2759,7 +2759,7 @@ function asmLoopOptimizer(ast) {
// Passes table
-var compress = false, printMetadata = true, asm = false, last = false;
+var minifyWhitespace = false, printMetadata = true, asm = false, last = false;
var passes = {
dumpAst: dumpAst,
@@ -2777,7 +2777,7 @@ var passes = {
eliminate: eliminate,
eliminateMemSafe: eliminateMemSafe,
minifyGlobals: minifyGlobals,
- compress: function() { compress = true },
+ minifyWhitespace: function() { minifyWhitespace = true },
noPrintMetadata: function() { printMetadata = false },
asm: function() { asm = true },
last: function() { last = true },
@@ -2803,7 +2803,7 @@ if (asm && last) {
asmLoopOptimizer(ast);
prepDotZero(ast);
}
-var js = astToSrc(ast, compress), old;
+var js = astToSrc(ast, minifyWhitespace), old;
if (asm && last) {
js = fixDotZero(js);
}
diff --git a/tools/js_optimizer.py b/tools/js_optimizer.py
index 0452a725..f014c7d4 100644
--- a/tools/js_optimizer.py
+++ b/tools/js_optimizer.py
@@ -57,7 +57,7 @@ class Minifier:
if curr not in INVALID_3: self.names.append(curr)
#print >> sys.stderr, self.names
- def minify_shell(self, shell, compress):
+ def minify_shell(self, shell, minify_whitespace):
#print >> sys.stderr, "MINIFY SHELL 1111111111", shell, "\n222222222222222"
# Run through js-optimizer.js to find and minify the global symbols
# We send it the globals, which it parses at the proper time. JS decides how
@@ -77,7 +77,7 @@ class Minifier:
f.write('// MINIFY_INFO:' + self.serialize())
f.close()
- output = subprocess.Popen(self.js_engine + [JS_OPTIMIZER, temp_file, 'minifyGlobals', 'noPrintMetadata'] + (['compress'] if compress else []), stdout=subprocess.PIPE).communicate()[0]
+ output = subprocess.Popen(self.js_engine + [JS_OPTIMIZER, temp_file, 'minifyGlobals', 'noPrintMetadata'] + (['minifyWhitespace'] if minify_whitespace else []), stdout=subprocess.PIPE).communicate()[0]
assert len(output) > 0 and not output.startswith('Assertion failed'), 'Error in js optimizer: ' + output
#print >> sys.stderr, "minified SHELL 3333333333333333", output, "\n44444444444444444444"
code, metadata = output.split('// MINIFY_INFO:')
@@ -130,8 +130,10 @@ def run_on_js(filename, passes, js_engine, jcache):
start_funcs = js.find(start_funcs_marker)
end_funcs = js.rfind(end_funcs_marker)
#assert (start_funcs >= 0) == (end_funcs >= 0) == (not not suffix)
- asm_registerize = 'asm' in passes and 'registerize' in passes
- if asm_registerize:
+
+ minify_globals = 'minifyGlobals' in passes
+ if minify_globals:
+ passes = filter(lambda p: p != 'minifyGlobals', passes) # we will run it manually
start_asm_marker = '// EMSCRIPTEN_START_ASM\n'
end_asm_marker = '// EMSCRIPTEN_END_ASM\n'
start_asm = js.find(start_asm_marker)
@@ -146,7 +148,7 @@ def run_on_js(filename, passes, js_engine, jcache):
jcache = False
if suffix:
- if not asm_registerize:
+ if not minify_globals:
pre = js[:start_funcs + len(start_funcs_marker)]
post = js[end_funcs + len(end_funcs_marker):]
js = js[start_funcs + len(start_funcs_marker):end_funcs]
@@ -171,7 +173,7 @@ EMSCRIPTEN_FUNCS();
js = js[start_funcs + len(start_funcs_marker):end_funcs]
minifier = Minifier(js, js_engine)
- asm_shell_pre, asm_shell_post = minifier.minify_shell(asm_shell, 'compress' in passes).split('EMSCRIPTEN_FUNCS();');
+ asm_shell_pre, asm_shell_post = minifier.minify_shell(asm_shell, 'minifyWhitespace' in passes).split('EMSCRIPTEN_FUNCS();');
asm_shell_post = asm_shell_post.replace('});', '})');
pre += asm_shell_pre + '\n' + start_funcs_marker
post = end_funcs_marker + asm_shell_post + post
@@ -236,7 +238,7 @@ EMSCRIPTEN_FUNCS();
f = open(temp_file, 'w')
f.write(chunk)
f.write(suffix_marker)
- if asm_registerize:
+ if minify_globals:
f.write('\n')
f.write('// MINIFY_INFO:' + minify_info)
f.close()
@@ -279,7 +281,7 @@ EMSCRIPTEN_FUNCS();
c.write(closure_sep)
c.write(post_2)
c.close()
- closured = shared.Building.closure_compiler(closuree, pretty='compress' not in passes)
+ closured = shared.Building.closure_compiler(closuree, pretty='minifyWhitespace' not in passes)
temp_files.note(closured)
coutput = open(closured).read()
coutput = coutput.replace('wakaUnknownBefore();', '')