aboutsummaryrefslogtreecommitdiff
path: root/tools/eliminator
diff options
context:
space:
mode:
Diffstat (limited to 'tools/eliminator')
-rw-r--r--tools/eliminator/node_modules/uglify-js/lib/parse-js.js25
-rw-r--r--tools/eliminator/node_modules/uglify-js/lib/process.js72
2 files changed, 86 insertions, 11 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));