aboutsummaryrefslogtreecommitdiff
path: root/tools/js_optimizer.py
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-06-22 15:02:10 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-06-22 15:02:10 -0700
commit202461abe30f260cf403d430e51d80f225950605 (patch)
treec84ea7b7d91237bf1164f4e23798960a455ae83a /tools/js_optimizer.py
parent369167ebda362eb0c76081976ae0a48d2d3c1cbd (diff)
fix -g2 and add testing
Diffstat (limited to 'tools/js_optimizer.py')
-rw-r--r--tools/js_optimizer.py18
1 files changed, 10 insertions, 8 deletions
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();', '')