diff options
Diffstat (limited to 'tools/eliminator/node_modules/uglify-js')
-rw-r--r-- | tools/eliminator/node_modules/uglify-js/lib/process.js | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/tools/eliminator/node_modules/uglify-js/lib/process.js b/tools/eliminator/node_modules/uglify-js/lib/process.js index 660001aa..39ccde37 100644 --- a/tools/eliminator/node_modules/uglify-js/lib/process.js +++ b/tools/eliminator/node_modules/uglify-js/lib/process.js @@ -65,6 +65,7 @@ function NodeWithLine(str, 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 @@ -473,7 +474,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(); @@ -499,7 +503,16 @@ 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)) + ";"; @@ -555,8 +568,8 @@ function gen_code(ast, options) { if (op && op !== true) op += "="; else op = "="; var s = add_spaces([ make(lvalue), op, parenthesize(rvalue, "seq") ]); - if (options.debug && lvalue[0].start) - return new NodeWithLine(s, lvalue[0].start.line); + if (options.debug && this[0].start) + return new NodeWithLine(s, this[0].start.line); return s; }, "dot": function(expr) { @@ -574,9 +587,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, @@ -613,7 +629,7 @@ function gen_code(ast, options) { var out = [ "return" ]; var str = make(expr); if (expr != null) out.push(str); - return add_spaces(out) + ";" + str.lineComment(); + return add_spaces(out) + ";" + (str ? str.lineComment() : ''); }, "binary": function(operator, lvalue, rvalue) { var left = make(lvalue), right = make(rvalue); @@ -633,7 +649,11 @@ function gen_code(ast, options) { && rvalue[0] == "regexp" && /^script/i.test(rvalue[1])) { right = " " + right; } - return add_spaces([ left, operator, right ]); + var tok = this[0]; + var str = add_spaces([ left, operator, right ]); + if (options.debug && tok.start) + return new NodeWithLine(str, tok.start.line); + return str; }, "unary-prefix": function(operator, expr) { var val = make(expr); |