aboutsummaryrefslogtreecommitdiff
path: root/tools/js_optimizer.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/js_optimizer.py')
-rw-r--r--tools/js_optimizer.py31
1 files changed, 18 insertions, 13 deletions
diff --git a/tools/js_optimizer.py b/tools/js_optimizer.py
index 0452a725..16bc73c1 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
@@ -73,14 +73,13 @@ class Minifier:
f = open(temp_file, 'w')
f.write(shell)
f.write('\n')
- self
- f.write('// MINIFY_INFO:' + self.serialize())
+ f.write('// EXTRA_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:')
+ code, metadata = output.split('// EXTRA_INFO:')
self.globs = json.loads(metadata)
return code.replace('13371337', '0.0')
@@ -130,14 +129,20 @@ 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 = 'registerizeAndMinify' in passes and 'asm' in passes
+ if minify_globals:
+ passes = map(lambda p: p if p != 'registerizeAndMinify' else 'registerize', passes)
start_asm_marker = '// EMSCRIPTEN_START_ASM\n'
end_asm_marker = '// EMSCRIPTEN_END_ASM\n'
start_asm = js.find(start_asm_marker)
end_asm = js.rfind(end_asm_marker)
assert (start_asm >= 0) == (end_asm >= 0)
+ closure = 'closure' in passes
+ if closure:
+ passes = filter(lambda p: p != 'closure', passes) # we will do it manually
+
if not suffix and jcache:
# JCache cannot be used without metadata, since it might reorder stuff, and that's dangerous since only generated can be reordered
# This means jcache does not work after closure compiler runs, for example. But you won't get much benefit from jcache with closure
@@ -146,7 +151,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 +176,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,9 +241,9 @@ 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.write('// EXTRA_INFO:' + minify_info)
f.close()
return temp_file
filenames = [write_chunk(chunks[i], i) for i in range(len(chunks))]
@@ -265,7 +270,7 @@ EMSCRIPTEN_FUNCS();
for filename in filenames: temp_files.note(filename)
- if 'closure' in passes:
+ if closure:
# run closure on the shell code, everything but what we js-optimize
start_asm = '// EMSCRIPTEN_START_ASM\n'
end_asm = '// EMSCRIPTEN_END_ASM\n'
@@ -279,7 +284,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();', '')