Permalink
Browse files

Update code generator to never miss outputting comments at the end of…

… an expression
  • Loading branch information...
1 parent c0773f2 commit 65eb0dc63fab42417743a2ade1f8ca1cc913e182 Scriby committed Feb 27, 2012
Showing with 25 additions and 13 deletions.
  1. +24 −12 lib/process.js
  2. +1 −1 package.json
View
@@ -1447,14 +1447,14 @@ function gen_code(ast, options) {
var ret = make_string(str, options.ascii_only);
if (options.inline_script)
ret = ret.replace(/<\x2fscript([>\/\t\n\f\r ])/gi, "<\\/script$1");
- return ret + outputComments(this.postComments);
+ return ret;
};
function make_name(name) {
name = name.toString();
if (options.ascii_only)
name = to_ascii(name);
- return name + outputComments(this.postComments);
+ return name;
};
function indent(line) {
@@ -1559,7 +1559,7 @@ function gen_code(ast, options) {
}
var toReturn = best_of(a);
- toReturn += outputComments(this.postComments);
+
return toReturn;
};
@@ -1593,9 +1593,23 @@ function gen_code(ast, options) {
return false;
};
+ var wrapWithExpressionComments = function(originalWalkers){
+ var walkers = {};
+
+ Object.keys(originalWalkers).forEach(function(key){
+ walkers[key] = function(){
+ var original = originalWalkers[key].apply(this, arguments);
+
+ return original + outputComments(this.postComments);
+ };
+ });
+
+ return walkers;
+ };
+
var w = ast_walker();
var make = w.walk;
- return w.with_walkers({
+ return w.with_walkers(wrapWithExpressionComments({
"string": encode_string,
"num": make_num,
"name": make_name,
@@ -1686,7 +1700,7 @@ function gen_code(ast, options) {
}
}]) + args ]);
- return returnValue + outputComments(this.postComments);
+ return returnValue;
},
"switch": function(expr, body) {
return add_spaces([ "switch", "(" + make(expr) + ")", make_switch_block(body) ]);
@@ -1744,7 +1758,6 @@ function gen_code(ast, options) {
}
out += outputComments(postOperatorComments);
- out += outputComments(this.postComments);
return out;
},
@@ -1764,7 +1777,7 @@ function gen_code(ast, options) {
}
return toReturn;
- }).join('') + ")" + outputComments(this.postComments);
+ }).join('') + ")";
},
"function": make_function,
"defun": make_function,
@@ -1866,7 +1879,6 @@ function gen_code(ast, options) {
out += "[";
out += outputComments(postOperatorComments);
out += make(subscript) + "]";
- out += outputComments(this.postComments);
return out;
},
@@ -1922,14 +1934,14 @@ function gen_code(ast, options) {
return objOutput.join(newline);
}) + newline + indent("}");
var toReturn = obj_needs_parens ? "(" + out + ")" : out;
- toReturn += outputComments(this.postComments);
+
return toReturn;
},
"regexp": function(rx, mods) {
return "/" + rx + "/" + mods;
},
"array": function(elements) {
- if (elements.length == 0) return "[]" + outputComments(this.postComments);
+ if (elements.length == 0) return "[]";
return add_spaces([ "[", MAP(elements, function(el, i){
if (!beautify && el[0] == "atom" && el[1] == "undefined") return i === elements.length - 1 ? "," : "";
var toReturn = parenthesize(el, ["seq"]);
@@ -1939,7 +1951,7 @@ function gen_code(ast, options) {
}
return toReturn;
- }).join(''), "]" ]) + outputComments(this.postComments);
+ }).join(''), "]" ]);
},
"stat": function(stmt) {
var result = make(stmt);
@@ -1970,7 +1982,7 @@ function gen_code(ast, options) {
"comma": function(prepend){
return prepend + ',';
}
- }, function(){ return make(ast) });
+ }), function(){ return make(ast) });
// The squeezer replaces "block"-s that contain only a single
// statement with the statement itself; technically, the AST
View
@@ -9,7 +9,7 @@
"url" : "http://mihai.bazon.net/blog"
},
- "version" : "1.2.5-5",
+ "version" : "1.2.5-6",
"main" : "./uglify-js.js",

0 comments on commit 65eb0dc

Please sign in to comment.