aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/eliminator/node_modules/uglify-js/lib/process.js29
-rw-r--r--tools/js-optimizer.js1
2 files changed, 24 insertions, 6 deletions
diff --git a/tools/eliminator/node_modules/uglify-js/lib/process.js b/tools/eliminator/node_modules/uglify-js/lib/process.js
index 70a4b0a4..660001aa 100644
--- a/tools/eliminator/node_modules/uglify-js/lib/process.js
+++ b/tools/eliminator/node_modules/uglify-js/lib/process.js
@@ -58,6 +58,18 @@ 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.lineComment = function() { return " // @line " + this.line; }
+
+// XXX ugly hack
+String.prototype.lineComment = function() { return ""; }
+
/* -----[ helper for AST traversal ]----- */
function ast_walker() {
@@ -339,6 +351,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,
@@ -470,8 +483,7 @@ function gen_code(ast, options) {
"num": make_num,
"name": make_name,
"toplevel": function(statements) {
- return make_block_statements(statements)
- .join(newline + newline);
+ return make_block_statements(statements).join(newline + newline);
},
"splice": function(statements) {
var parent = w.parent();
@@ -542,7 +554,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 && lvalue[0].start)
+ return new NodeWithLine(s, lvalue[0].start.line);
+ return s;
},
"dot": function(expr) {
var out = make(expr), i = 1;
@@ -596,8 +611,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.lineComment();
},
"binary": function(operator, lvalue, rvalue) {
var left = make(lvalue), right = make(rvalue);
@@ -673,7 +689,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 21ce54a8..f86bb0d6 100644
--- a/tools/js-optimizer.js
+++ b/tools/js-optimizer.js
@@ -152,6 +152,7 @@ function srcToAst(src) {
function astToSrc(ast, compress) {
return uglify.uglify.gen_code(ast, {
+ debug: debug,
ascii_only: true,
beautify: !compress,
indent_level: 2