Merge branch 'master' into harmony
This commit is contained in:
@@ -71,6 +71,7 @@ function OutputStream(options) {
|
||||
keep_quoted_props: false,
|
||||
shorthand : undefined,
|
||||
ecma : 5,
|
||||
wrap_iife : false,
|
||||
}, true);
|
||||
|
||||
if (typeof options.ascii_identifiers === 'undefined')
|
||||
@@ -79,6 +80,50 @@ function OutputStream(options) {
|
||||
if (options.shorthand === undefined)
|
||||
options.shorthand = options.ecma > 5;
|
||||
|
||||
// Convert comment option to RegExp if neccessary and set up comments filter
|
||||
if (typeof options.comments === "string" && /^\/.*\/[a-zA-Z]*$/.test(options.comments)) {
|
||||
var regex_pos = options.comments.lastIndexOf("/");
|
||||
options.comments = new RegExp(
|
||||
options.comments.substr(1, regex_pos - 1),
|
||||
options.comments.substr(regex_pos + 1)
|
||||
);
|
||||
}
|
||||
if (options.comments instanceof RegExp) {
|
||||
options.comments = (function(f) {
|
||||
return function(comment) {
|
||||
return comment.type == "comment5" || f.test(comment.value);
|
||||
}
|
||||
})(options.comments);
|
||||
}
|
||||
else if (typeof options.comments === "function") {
|
||||
options.comments = (function(f) {
|
||||
return function(comment) {
|
||||
return comment.type == "comment5" || f(this, comment);
|
||||
}
|
||||
})(options.comments);
|
||||
}
|
||||
else if (options.comments === "some") {
|
||||
options.comments = function(comment) {
|
||||
var text = comment.value;
|
||||
var type = comment.type;
|
||||
if (type == "comment2") {
|
||||
// multiline comment
|
||||
return /@preserve|@license|@cc_on/i.test(text);
|
||||
}
|
||||
return type == "comment5";
|
||||
}
|
||||
}
|
||||
else if (options.comments){ // NOTE includes "all" option
|
||||
options.comments = function() {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
// Falsy case, so reject all comments, except shebangs
|
||||
options.comments = function(comment) {
|
||||
return comment.type == "comment5";
|
||||
}
|
||||
}
|
||||
|
||||
var indentation = 0;
|
||||
var current_col = 0;
|
||||
var current_line = 1;
|
||||
@@ -484,7 +529,7 @@ function OutputStream(options) {
|
||||
|
||||
AST_Node.DEFMETHOD("add_comments", function(output){
|
||||
if (output._readonly) return;
|
||||
var c = output.option("comments"), self = this;
|
||||
var self = this;
|
||||
var start = self.start;
|
||||
if (start && !start._comments_dumped) {
|
||||
start._comments_dumped = true;
|
||||
@@ -507,19 +552,7 @@ function OutputStream(options) {
|
||||
}));
|
||||
}
|
||||
|
||||
if (!c) {
|
||||
comments = comments.filter(function(comment) {
|
||||
return comment.type == "comment5";
|
||||
});
|
||||
} else if (c.test) {
|
||||
comments = comments.filter(function(comment){
|
||||
return comment.type == "comment5" || c.test(comment.value);
|
||||
});
|
||||
} else if (typeof c == "function") {
|
||||
comments = comments.filter(function(comment){
|
||||
return comment.type == "comment5" || c(self, comment);
|
||||
});
|
||||
}
|
||||
comments = comments.filter(output.option("comments"), self);
|
||||
|
||||
// Keep single line comments after nlb, after nlb
|
||||
if (!output.option("beautify") && comments.length > 0 &&
|
||||
@@ -570,7 +603,16 @@ function OutputStream(options) {
|
||||
// a function expression needs parens around it when it's provably
|
||||
// the first token to appear in a statement.
|
||||
PARENS(AST_Function, function(output){
|
||||
return first_in_statement(output);
|
||||
if (first_in_statement(output)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (output.option('wrap_iife')) {
|
||||
var p = output.parent();
|
||||
return p instanceof AST_Call && p.expression === this;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
// same goes for an object literal, because otherwise it would be
|
||||
|
||||
Reference in New Issue
Block a user