aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJez Ng <me@jezng.com>2013-06-19 01:56:47 -0700
committerJez Ng <me@jezng.com>2013-06-19 14:09:13 -0700
commit7656f948388b5a3421996196ea36c7bb052bb884 (patch)
treee7a1967ccce8cf5f0a0e077dcacda2116f4d6b8d /tools
parentbe5d45fe2932f9452c623b63720cb7d9857a1baa (diff)
Lay the groundwork for optimized source maps.
Diffstat (limited to 'tools')
-rw-r--r--tools/js-optimizer.js12
-rw-r--r--tools/js_optimizer.py20
-rw-r--r--tools/shared.py4
3 files changed, 26 insertions, 10 deletions
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js
index 07317e0a..21ce54a8 100644
--- a/tools/js-optimizer.js
+++ b/tools/js-optimizer.js
@@ -11,6 +11,7 @@
// *** Environment setup code ***
var arguments_ = [];
+var debug = false;
var ENVIRONMENT_IS_NODE = typeof process === 'object';
var ENVIRONMENT_IS_WEB = typeof window === 'object';
@@ -146,7 +147,7 @@ var generatedFunctions = false; // whether we have received only generated funct
var minifierInfo = null;
function srcToAst(src) {
- return uglify.parser.parse(src);
+ return uglify.parser.parse(src, false, debug);
}
function astToSrc(ast, compress) {
@@ -2750,6 +2751,14 @@ var passes = {
var suffix = '';
+arguments_ = arguments_.filter(function (arg) {
+ if (!/^--/.test(arg)) return true;
+
+ if (arg === '--debug') debug = true;
+ else throw new Error('Unrecognized flag: ' + arg);
+});
+
+
var src = read(arguments_[0]);
var ast = srcToAst(src);
//printErr(JSON.stringify(ast)); throw 1;
@@ -2758,6 +2767,7 @@ var minifierInfoStart = src.indexOf('// MINIFY_INFO:')
if (minifierInfoStart > 0) minifierInfo = JSON.parse(src.substr(minifierInfoStart + 15));
//printErr(JSON.stringify(minifierInfo));
+
arguments_.slice(1).forEach(function(arg) {
passes[arg](ast);
});
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))
diff --git a/tools/shared.py b/tools/shared.py
index c16c9115..89ceeccb 100644
--- a/tools/shared.py
+++ b/tools/shared.py
@@ -1213,8 +1213,8 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)''' % { 'winfix': '' if not WINDOWS e
return opts
@staticmethod
- def js_optimizer(filename, passes, jcache):
- return js_optimizer.run(filename, passes, listify(NODE_JS), jcache)
+ def js_optimizer(filename, passes, jcache, debug):
+ return js_optimizer.run(filename, passes, listify(NODE_JS), jcache, debug)
@staticmethod
def closure_compiler(filename, pretty=True):