diff options
Diffstat (limited to 'tools')
47 files changed, 4942 insertions, 32 deletions
diff --git a/tools/eliminator/node_modules/uglify-js/lib/parse-js.js b/tools/eliminator/node_modules/uglify-js/lib/parse-js.js index a89163c6..2dc2ef70 100644 --- a/tools/eliminator/node_modules/uglify-js/lib/parse-js.js +++ b/tools/eliminator/node_modules/uglify-js/lib/parse-js.js @@ -679,7 +679,28 @@ function NodeWithToken(str, start, end) { this.end = end; }; -NodeWithToken.prototype.toString = function() { return this.name; }; +NodeWithToken.prototype = { + get length() { + return this.name.length; + }, + set length(v) { + return this.name.length = v; + }, + replace: function() { return this.name.replace.apply(this.name, arguments); }, + concat: function() { return this.name.concat.apply(this.name, arguments); }, + indexOf: function() { return this.name.indexOf.apply(this.name, arguments); }, + lastIndexOf: function() { return this.name.lastIndexOf.apply(this.name, arguments); }, + lastIndexOf: function() { return this.name.lastIndexOf.apply(this.name, arguments); }, + match: function() { return this.name.match.apply(this.name, arguments); }, + search: function() { return this.name.search.apply(this.name, arguments); }, + slice: function() { return this.name.slice.apply(this.name, arguments); }, + split: function() { return this.name.split.apply(this.name, arguments); }, + substr: function() { return this.name.substr.apply(this.name, arguments); }, + substring: function() { return this.name.substring.apply(this.name, arguments); }, + toString: function() { return this.name; }, + toJSON: function() { return this.name; }, + valueOf: function() { return this.name; }, +}; function parse($TEXT, exigent_mode, embed_tokens) { @@ -1314,7 +1335,7 @@ function characters(str) { function member(name, array) { for (var i = array.length; --i >= 0;) - if (array[i] === name) + if (array[i] == name) return true; return false; }; diff --git a/tools/eliminator/node_modules/uglify-js/lib/process.js b/tools/eliminator/node_modules/uglify-js/lib/process.js index c3abb6f8..3fd99b79 100644 --- a/tools/eliminator/node_modules/uglify-js/lib/process.js +++ b/tools/eliminator/node_modules/uglify-js/lib/process.js @@ -64,6 +64,19 @@ var jsp = require("./parse-js"), PRECEDENCE = jsp.PRECEDENCE, OPERATORS = jsp.OPERATORS; +function NodeWithLine(str, line) { + this.str = str; + this.line = line; +} + +NodeWithLine.prototype = new String(); +NodeWithLine.prototype.toString = function() { return this.str; } +NodeWithLine.prototype.valueOf = function() { return this.str; } +NodeWithLine.prototype.lineComment = function() { return " //@line " + this.line; } + +// XXX ugly hack +String.prototype.lineComment = function() { return ""; } + /* -----[ helper for AST traversal ]----- */ function ast_walker() { @@ -1363,6 +1376,7 @@ var SPLICE_NEEDS_BRACKETS = jsp.array_to_hash([ "if", "while", "do", "for", "for function gen_code(ast, options) { options = defaults(options, { + debug: false, indent_start : 0, indent_level : 4, quote_keys : false, @@ -1422,7 +1436,19 @@ function gen_code(ast, options) { }; function add_commas(a) { - return a.join("," + space); + var str = a.join("," + space); + if (options.debug) { + // if a line contains more than one comma-separated segment, assign it the + // original line number of the first NodeWithLine segment + for (var i = 0, l = a.length; i < l; i ++) { + var v = a[i]; + if (v instanceof NodeWithLine) { + v.str = str; + return v + } + } + } + return str; }; function parenthesize(expr) { @@ -1484,7 +1510,10 @@ function gen_code(ast, options) { a.push(m[2] + "e-" + (m[1].length + m[2].length), str.substr(str.indexOf("."))); } - return best_of(a); + var best = best_of(a); + if (options.debug && this[0].start) + return new NodeWithLine(best, this[0].start.line); + return best; }; var w = ast_walker(); @@ -1512,7 +1541,15 @@ function gen_code(ast, options) { }, "block": make_block, "var": function(defs) { - return "var " + add_commas(MAP(defs, make_1vardef)) + ";"; + var s = "var " + add_commas(MAP(defs, make_1vardef)) + ";"; + if (options.debug) { + // hack: we don't support mapping one optimized line to more than one + // generated line, so in case of multiple comma-separated var definitions, + // just take the first + if (defs[0][1] && defs[0][1][0] && defs[0][1][0].start) + return s + (new NodeWithLine(s, defs[0][1][0].start.line)).lineComment(); + } + return s; }, "const": function(defs) { return "const " + add_commas(MAP(defs, make_1vardef)) + ";"; @@ -1567,7 +1604,10 @@ function gen_code(ast, options) { "assign": function(op, lvalue, rvalue) { if (op && op !== true) op += "="; else op = "="; - return add_spaces([ make(lvalue), op, parenthesize(rvalue, "seq") ]); + var s = add_spaces([ make(lvalue), op, parenthesize(rvalue, "seq") ]); + if (options.debug && this[0].start) + return new NodeWithLine(s, this[0].start.line); + return s; }, "dot": function(expr) { var out = make(expr), i = 1; @@ -1584,9 +1624,12 @@ function gen_code(ast, options) { var f = make(func); if (needs_parens(func)) f = "(" + f + ")"; - return f + "(" + add_commas(MAP(args, function(expr){ + var str = f + "(" + add_commas(MAP(args, function(expr){ return parenthesize(expr, "seq"); })) + ")"; + if (options.debug && this[0].start) + return new NodeWithLine(str, this[0].start.line) + return str; }, "function": make_function, "defun": make_function, @@ -1621,8 +1664,9 @@ function gen_code(ast, options) { }, "return": function(expr) { var out = [ "return" ]; - if (expr != null) out.push(make(expr)); - return add_spaces(out) + ";"; + var str = make(expr); + if (expr != null) out.push(str); + return add_spaces(out) + ";" + (str ? str.lineComment() : ''); }, "binary": function(operator, lvalue, rvalue) { var left = make(lvalue), right = make(rvalue); @@ -1642,7 +1686,16 @@ function gen_code(ast, options) { && rvalue[0] == "regexp" && /^script/i.test(rvalue[1])) { right = " " + right; } - return add_spaces([ left, operator, right ]); + var str = add_spaces([ left, operator, right ]); + if (options.debug) { + if (this[0].start) + return new NodeWithLine(str, this[0].start.line); + else if (lvalue[0].start) + return new NodeWithLine(str, lvalue[0].start.line); + else if (rvalue[0].start) + return new NodeWithLine(str, rvalue[0].start.line); + } + return str; }, "unary-prefix": function(operator, expr) { var val = make(expr); @@ -1698,7 +1751,8 @@ function gen_code(ast, options) { })), "]" ]); }, "stat": function(stmt) { - return make(stmt).replace(/;*\s*$/, ";"); + var str = make(stmt); + return str.replace(/;*\s*$/, ";") + str.lineComment(); }, "seq": function() { return add_commas(MAP(slice(arguments), make)); diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js index 5d7704d7..940719e9 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,11 +147,12 @@ 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, minifyWhitespace) { return uglify.uglify.gen_code(ast, { + debug: debug, ascii_only: true, beautify: !minifyWhitespace, indent_level: 1 @@ -162,7 +164,8 @@ function astToSrc(ast, minifyWhitespace) { function traverseChildren(node, traverse, pre, post, stack) { for (var i = 0; i < node.length; i++) { var subnode = node[i]; - if (typeof subnode == 'object' && subnode && subnode.length) { + if (typeof subnode == 'object' && subnode && subnode.length && + typeof subnode.valueOf() !== 'string') { var subresult = traverse(subnode, pre, post, stack); if (subresult == true) return true; if (subresult !== null && typeof subresult == 'object') node[i] = subresult; @@ -186,7 +189,9 @@ function traverseChildren(node, traverse, pre, post, stack) { // was stopped, true. Otherwise undefined. function traverse(node, pre, post, stack) { var type = node[0], result, len; - var relevant = typeof type == 'string'; + // valueOf() ensures that NodeWithToken (produced by uglify's parser during + // 'embed tokens' mode) gets marked as 'relevant' + var relevant = type && typeof type.valueOf() == 'string'; if (relevant) { if (stack) len = stack.length; var result = pre(node, type, stack); @@ -446,7 +451,9 @@ function simplifyExpressionsPre(ast) { traverse(ast, function process(node, type, stack) { if (type == 'binary' && node[1] == '|') { if (node[2][0] == 'num' && node[3][0] == 'num') { - return ['num', node[2][1] | node[3][1]]; + // pass node[2][0] instead of 'num' because it might be a token + // object with line numbers attached. + return [node[2][0], node[2][1] | node[3][1]]; } var go = false; if (jsonCompare(node[2], ZERO)) { @@ -2031,7 +2038,7 @@ function eliminate(ast, memSafe) { // examine body and note locals var hasSwitch = false; traverse(func, function(node, type) { - if (type === 'var') { + if (type == 'var') { var node1 = node[1]; for (var i = 0; i < node1.length; i++) { var node1i = node1[i]; @@ -2045,7 +2052,7 @@ function eliminate(ast, memSafe) { if (!uses[name]) uses[name] = 0; locals[name] = true; } - } else if (type === 'name') { + } else if (type == 'name') { var name = node[1]; if (!uses[name]) uses[name] = 0; uses[name]++; @@ -2505,7 +2512,7 @@ function eliminate(ast, memSafe) { // clean up vars, and loop variable elimination traverse(func, function(node, type) { // pre - if (type === 'var') { + if (type == 'var') { node[1] = node[1].filter(function(pair) { return !varsToRemove[pair[0]] }); if (node[1].length == 0) { // wipe out an empty |var;| @@ -2634,21 +2641,21 @@ function eliminate(ast, memSafe) { this.run = function() { traverse(this.node, function(node, type) { - if (type === 'binary' && node[1] == '+') { + if (type == 'binary' && node[1] == '+') { var names = []; var num = 0; var has_num = false; var fail = false; traverse(node, function(subNode, subType) { - if (subType === 'binary') { + if (subType == 'binary') { if (subNode[1] != '+') { fail = true; return false; } - } else if (subType === 'name') { + } else if (subType == 'name') { names.push(subNode[1]); return; - } else if (subType === 'num') { + } else if (subType == 'num') { num += subNode[1]; has_num = true; return; @@ -2787,6 +2794,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; @@ -2795,6 +2810,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 b610206c..256c03cf 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, minify_whitespace): + def minify_shell(self, shell, minify_whitespace, source_map=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 @@ -76,7 +76,12 @@ class Minifier: f.write('// MINIFY_INFO:' + self.serialize()) f.close() - output = subprocess.Popen(self.js_engine + [JS_OPTIMIZER, temp_file, 'minifyGlobals', 'noPrintMetadata'] + (['minifyWhitespace'] if minify_whitespace else []), stdout=subprocess.PIPE).communicate()[0] + output = subprocess.Popen(self.js_engine + + [JS_OPTIMIZER, temp_file, 'minifyGlobals', 'noPrintMetadata'] + + (['minifyWhitespace'] if minify_whitespace else []) + + (['--debug'] if source_map 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:') @@ -102,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, source_map=False): if isinstance(jcache, bool) and jcache: jcache = shared.JCache if jcache: shared.JCache.ensure() @@ -176,7 +181,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, 'minifyWhitespace' in passes).split('EMSCRIPTEN_FUNCS();'); + asm_shell_pre, asm_shell_post = minifier.minify_shell(asm_shell, 'minifyWhitespace' in passes, source_map).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 @@ -212,7 +217,9 @@ EMSCRIPTEN_FUNCS(); total_size = len(js) js = None - cores = int(os.environ.get('EMCC_CORES') or multiprocessing.cpu_count()) + # if we are making source maps, we want our debug numbering to start from the + # top of the file, so avoid breaking the JS into chunks + cores = 1 if source_map else int(os.environ.get('EMCC_CORES') or multiprocessing.cpu_count()) intended_num_chunks = int(round(cores * NUM_CHUNKS_PER_CORE)) chunk_size = min(MAX_CHUNK_SIZE, max(MIN_CHUNK_SIZE, total_size / intended_num_chunks)) @@ -252,7 +259,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 source_map else []) + passes, filenames) #print [' '.join(command) for command in commands] cores = min(cores, filenames) @@ -320,6 +329,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, source_map=False): + return temp_files.run_and_clean(lambda: run_on_js(filename, passes, js_engine, jcache, source_map)) diff --git a/tools/node_modules/source-map/.npmignore b/tools/node_modules/source-map/.npmignore new file mode 100644 index 00000000..3dddf3f6 --- /dev/null +++ b/tools/node_modules/source-map/.npmignore @@ -0,0 +1,2 @@ +dist/* +node_modules/* diff --git a/tools/node_modules/source-map/.travis.yml b/tools/node_modules/source-map/.travis.yml new file mode 100644 index 00000000..ddc9c4f9 --- /dev/null +++ b/tools/node_modules/source-map/.travis.yml @@ -0,0 +1,4 @@ +language: node_js +node_js: + - 0.8 + - "0.10"
\ No newline at end of file diff --git a/tools/node_modules/source-map/CHANGELOG.md b/tools/node_modules/source-map/CHANGELOG.md new file mode 100644 index 00000000..140fe0cf --- /dev/null +++ b/tools/node_modules/source-map/CHANGELOG.md @@ -0,0 +1,58 @@ +# Change Log + +## 0.1.22 + +* Ignore duplicate mappings in SourceMapGenerator. Fixes github issue 21. + +## 0.1.21 + +* Fixed handling of sources that start with a slash so that they are relative to + the source root's host. + +## 0.1.20 + +* Fixed github issue #43: absolute URLs aren't joined with the source root + anymore. + +## 0.1.19 + +* Using Travis CI to run tests. + +## 0.1.18 + +* Fixed a bug in the handling of sourceRoot. + +## 0.1.17 + +* Added SourceNode.fromStringWithSourceMap. + +## 0.1.16 + +* Added missing documentation. + +* Fixed the generating of empty mappings in SourceNode. + +## 0.1.15 + +* Added SourceMapGenerator.applySourceMap. + +## 0.1.14 + +* The sourceRoot is now handled consistently. + +## 0.1.13 + +* Added SourceMapGenerator.fromSourceMap. + +## 0.1.12 + +* SourceNode now generates empty mappings too. + +## 0.1.11 + +* Added name support to SourceNode. + +## 0.1.10 + +* Added sourcesContent support to the customer and generator. + diff --git a/tools/node_modules/source-map/LICENSE b/tools/node_modules/source-map/LICENSE new file mode 100644 index 00000000..ed1b7cf2 --- /dev/null +++ b/tools/node_modules/source-map/LICENSE @@ -0,0 +1,28 @@ + +Copyright (c) 2009-2011, Mozilla Foundation and contributors +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the names of the Mozilla Foundation nor the names of project + contributors may be used to endorse or promote products derived from this + software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/tools/node_modules/source-map/Makefile.dryice.js b/tools/node_modules/source-map/Makefile.dryice.js new file mode 100644 index 00000000..8973ac2c --- /dev/null +++ b/tools/node_modules/source-map/Makefile.dryice.js @@ -0,0 +1,166 @@ +/* -*- |