aboutsummaryrefslogtreecommitdiff
path: root/tools/eliminator/node_modules/uglify-js/lib/process.js
diff options
context:
space:
mode:
Diffstat (limited to 'tools/eliminator/node_modules/uglify-js/lib/process.js')
-rw-r--r--tools/eliminator/node_modules/uglify-js/lib/process.js72
1 files changed, 63 insertions, 9 deletions
diff --git a/tools/eliminator/node_modules/uglify-js/lib/process.js b/tools/eliminator/node_modules/uglify-js/lib/process.js
index c3abb6f8..e1d692b2 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.start)
+ return new NodeWithLine(best, this.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].start)
+ return s + (new NodeWithLine(s, defs[0][1].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.start)
+ return new NodeWithLine(s, this.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.start)
+ return new NodeWithLine(str, this.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.start)
+ return new NodeWithLine(str, this.start.line);
+ else if (lvalue.start)
+ return new NodeWithLine(str, lvalue.start.line);
+ else if (rvalue.start)
+ return new NodeWithLine(str, rvalue.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));