diff options
author | Jez Ng <me@jezng.com> | 2013-06-19 01:56:47 -0700 |
---|---|---|
committer | Jez Ng <me@jezng.com> | 2013-06-19 14:09:13 -0700 |
commit | 7656f948388b5a3421996196ea36c7bb052bb884 (patch) | |
tree | e7a1967ccce8cf5f0a0e077dcacda2116f4d6b8d /tools/js_optimizer.py | |
parent | be5d45fe2932f9452c623b63720cb7d9857a1baa (diff) |
Lay the groundwork for optimized source maps.
Diffstat (limited to 'tools/js_optimizer.py')
-rw-r--r-- | tools/js_optimizer.py | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/tools/js_optimizer.py b/tools/js_optimizer.py index 0452a725..e99c02be 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, compress, debug=False): #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,11 @@ 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'] + + (['compress'] if compress else []) + + (['--debug'] if debug 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:') @@ -103,7 +107,7 @@ def run_on_chunk(command): if DEBUG and not shared.WINDOWS: print >> sys.stderr, '.' # Skip debug progress indicator on Windows, since it doesn't buffer well with multiple threads printing to console. return filename -def run_on_js(filename, passes, js_engine, jcache): +def run_on_js(filename, passes, js_engine, jcache, debug=False): if isinstance(jcache, bool) and jcache: jcache = shared.JCache if jcache: shared.JCache.ensure() @@ -171,7 +175,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, 'compress' in passes, debug).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 @@ -247,7 +251,9 @@ EMSCRIPTEN_FUNCS(); if len(filenames) > 0: # XXX Use '--nocrankshaft' to disable crankshaft to work around v8 bug 1895, needed for older v8/node (node 0.6.8+ should be ok) - commands = map(lambda filename: js_engine + [JS_OPTIMIZER, filename, 'noPrintMetadata'] + passes, filenames) + commands = map(lambda filename: js_engine + + [JS_OPTIMIZER, filename, 'noPrintMetadata'] + + (['--debug'] if debug else []) + passes, filenames) #print [' '.join(command) for command in commands] cores = min(cores, filenames) @@ -315,6 +321,6 @@ EMSCRIPTEN_FUNCS(); return filename -def run(filename, passes, js_engine, jcache): - return temp_files.run_and_clean(lambda: run_on_js(filename, passes, js_engine, jcache)) +def run(filename, passes, js_engine, jcache, debug=False): + return temp_files.run_and_clean(lambda: run_on_js(filename, passes, js_engine, jcache, debug)) |