@@ -173,7 +173,7 @@ function OutputStream(options) {
|
|||||||
default:
|
default:
|
||||||
return dq > sq ? quote_single() : quote_double();
|
return dq > sq ? quote_single() : quote_double();
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
function encode_string(str, quote) {
|
function encode_string(str, quote) {
|
||||||
var ret = make_string(str, quote);
|
var ret = make_string(str, quote);
|
||||||
@@ -183,17 +183,17 @@ function OutputStream(options) {
|
|||||||
ret = ret.replace(/--\x3e/g, "--\\x3e");
|
ret = ret.replace(/--\x3e/g, "--\\x3e");
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
};
|
}
|
||||||
|
|
||||||
function make_name(name) {
|
function make_name(name) {
|
||||||
name = name.toString();
|
name = name.toString();
|
||||||
name = to_utf8(name, true);
|
name = to_utf8(name, true);
|
||||||
return name;
|
return name;
|
||||||
};
|
}
|
||||||
|
|
||||||
function make_indent(back) {
|
function make_indent(back) {
|
||||||
return repeat_string(" ", options.indent_start + indentation - back * options.indent_level);
|
return repeat_string(" ", options.indent_start + indentation - back * options.indent_level);
|
||||||
};
|
}
|
||||||
|
|
||||||
/* -----[ beautification/minification ]----- */
|
/* -----[ beautification/minification ]----- */
|
||||||
|
|
||||||
@@ -351,7 +351,7 @@ function OutputStream(options) {
|
|||||||
current_col = a[n].length;
|
current_col = a[n].length;
|
||||||
}
|
}
|
||||||
last = str;
|
last = str;
|
||||||
};
|
}
|
||||||
|
|
||||||
var space = options.beautify ? function() {
|
var space = options.beautify ? function() {
|
||||||
print(" ");
|
print(" ");
|
||||||
@@ -374,6 +374,11 @@ function OutputStream(options) {
|
|||||||
return ret;
|
return ret;
|
||||||
} : function(col, cont) { return cont() };
|
} : function(col, cont) { return cont() };
|
||||||
|
|
||||||
|
var may_add_newline = options.max_line_len ? function() {
|
||||||
|
ensure_line_len();
|
||||||
|
might_add_newline = OUTPUT.length;
|
||||||
|
} : noop;
|
||||||
|
|
||||||
var newline = options.beautify ? function() {
|
var newline = options.beautify ? function() {
|
||||||
if (newline_insert < 0) return print("\n");
|
if (newline_insert < 0) return print("\n");
|
||||||
if (OUTPUT[newline_insert] != "\n") {
|
if (OUTPUT[newline_insert] != "\n") {
|
||||||
@@ -382,10 +387,7 @@ function OutputStream(options) {
|
|||||||
current_line++;
|
current_line++;
|
||||||
}
|
}
|
||||||
newline_insert++;
|
newline_insert++;
|
||||||
} : options.max_line_len ? function() {
|
} : may_add_newline;
|
||||||
ensure_line_len();
|
|
||||||
might_add_newline = OUTPUT.length;
|
|
||||||
} : noop;
|
|
||||||
|
|
||||||
var semicolon = options.beautify ? function() {
|
var semicolon = options.beautify ? function() {
|
||||||
print(";");
|
print(";");
|
||||||
@@ -396,11 +398,11 @@ function OutputStream(options) {
|
|||||||
function force_semicolon() {
|
function force_semicolon() {
|
||||||
might_need_semicolon = false;
|
might_need_semicolon = false;
|
||||||
print(";");
|
print(";");
|
||||||
};
|
}
|
||||||
|
|
||||||
function next_indent() {
|
function next_indent() {
|
||||||
return indentation + options.indent_level;
|
return indentation + options.indent_level;
|
||||||
};
|
}
|
||||||
|
|
||||||
function with_block(cont) {
|
function with_block(cont) {
|
||||||
var ret;
|
var ret;
|
||||||
@@ -412,34 +414,40 @@ function OutputStream(options) {
|
|||||||
indent();
|
indent();
|
||||||
print("}");
|
print("}");
|
||||||
return ret;
|
return ret;
|
||||||
};
|
}
|
||||||
|
|
||||||
function with_parens(cont) {
|
function with_parens(cont) {
|
||||||
print("(");
|
print("(");
|
||||||
|
may_add_newline();
|
||||||
//XXX: still nice to have that for argument lists
|
//XXX: still nice to have that for argument lists
|
||||||
//var ret = with_indent(current_col, cont);
|
//var ret = with_indent(current_col, cont);
|
||||||
var ret = cont();
|
var ret = cont();
|
||||||
|
may_add_newline();
|
||||||
print(")");
|
print(")");
|
||||||
return ret;
|
return ret;
|
||||||
};
|
}
|
||||||
|
|
||||||
function with_square(cont) {
|
function with_square(cont) {
|
||||||
print("[");
|
print("[");
|
||||||
|
may_add_newline();
|
||||||
//var ret = with_indent(current_col, cont);
|
//var ret = with_indent(current_col, cont);
|
||||||
var ret = cont();
|
var ret = cont();
|
||||||
|
may_add_newline();
|
||||||
print("]");
|
print("]");
|
||||||
return ret;
|
return ret;
|
||||||
};
|
}
|
||||||
|
|
||||||
function comma() {
|
function comma() {
|
||||||
|
may_add_newline();
|
||||||
print(",");
|
print(",");
|
||||||
|
may_add_newline();
|
||||||
space();
|
space();
|
||||||
};
|
}
|
||||||
|
|
||||||
function colon() {
|
function colon() {
|
||||||
print(":");
|
print(":");
|
||||||
space();
|
space();
|
||||||
};
|
}
|
||||||
|
|
||||||
var add_mapping = mappings ? function(token, name) {
|
var add_mapping = mappings ? function(token, name) {
|
||||||
mapping_token = token;
|
mapping_token = token;
|
||||||
@@ -451,7 +459,7 @@ function OutputStream(options) {
|
|||||||
ensure_line_len();
|
ensure_line_len();
|
||||||
}
|
}
|
||||||
return OUTPUT;
|
return OUTPUT;
|
||||||
};
|
}
|
||||||
|
|
||||||
function has_nlb() {
|
function has_nlb() {
|
||||||
var index = OUTPUT.lastIndexOf("\n");
|
var index = OUTPUT.lastIndexOf("\n");
|
||||||
@@ -619,8 +627,7 @@ function OutputStream(options) {
|
|||||||
return stack[stack.length - 2 - (n || 0)];
|
return stack[stack.length - 2 - (n || 0)];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
}
|
||||||
};
|
|
||||||
|
|
||||||
/* -----[ code generators ]----- */
|
/* -----[ code generators ]----- */
|
||||||
|
|
||||||
@@ -630,7 +637,7 @@ function OutputStream(options) {
|
|||||||
|
|
||||||
function DEFPRINT(nodetype, generator) {
|
function DEFPRINT(nodetype, generator) {
|
||||||
nodetype.DEFMETHOD("_codegen", generator);
|
nodetype.DEFMETHOD("_codegen", generator);
|
||||||
};
|
}
|
||||||
|
|
||||||
var in_directive = false;
|
var in_directive = false;
|
||||||
var active_scope = null;
|
var active_scope = null;
|
||||||
@@ -679,7 +686,7 @@ function OutputStream(options) {
|
|||||||
} else {
|
} else {
|
||||||
nodetype.DEFMETHOD("needs_parens", func);
|
nodetype.DEFMETHOD("needs_parens", func);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
PARENS(AST_Node, return_false);
|
PARENS(AST_Node, return_false);
|
||||||
|
|
||||||
@@ -865,7 +872,7 @@ function OutputStream(options) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
in_directive = false;
|
in_directive = false;
|
||||||
};
|
}
|
||||||
|
|
||||||
AST_StatementWithBody.DEFMETHOD("_do_print_body", function(output){
|
AST_StatementWithBody.DEFMETHOD("_do_print_body", function(output){
|
||||||
force_statement(this.body, output);
|
force_statement(this.body, output);
|
||||||
@@ -901,7 +908,7 @@ function OutputStream(options) {
|
|||||||
display_body(self.body, false, output, allow_directives);
|
display_body(self.body, false, output, allow_directives);
|
||||||
});
|
});
|
||||||
} else print_braced_empty(self, output);
|
} else print_braced_empty(self, output);
|
||||||
};
|
}
|
||||||
DEFPRINT(AST_BlockStatement, function(self, output){
|
DEFPRINT(AST_BlockStatement, function(self, output){
|
||||||
print_braced(self, output);
|
print_braced(self, output);
|
||||||
});
|
});
|
||||||
@@ -1064,7 +1071,7 @@ function OutputStream(options) {
|
|||||||
else break;
|
else break;
|
||||||
}
|
}
|
||||||
force_statement(self.body, output);
|
force_statement(self.body, output);
|
||||||
};
|
}
|
||||||
DEFPRINT(AST_If, function(self, output){
|
DEFPRINT(AST_If, function(self, output){
|
||||||
output.print("if");
|
output.print("if");
|
||||||
output.space();
|
output.space();
|
||||||
@@ -1184,7 +1191,7 @@ function OutputStream(options) {
|
|||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
node.print(output, parens);
|
node.print(output, parens);
|
||||||
};
|
}
|
||||||
|
|
||||||
DEFPRINT(AST_VarDef, function(self, output){
|
DEFPRINT(AST_VarDef, function(self, output){
|
||||||
self.name.print(output);
|
self.name.print(output);
|
||||||
@@ -1430,7 +1437,7 @@ function OutputStream(options) {
|
|||||||
else
|
else
|
||||||
stat.print(output);
|
stat.print(output);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
// self should be AST_New. decide if we want to show parens or not.
|
// self should be AST_New. decide if we want to show parens or not.
|
||||||
function need_constructor_parens(self, output) {
|
function need_constructor_parens(self, output) {
|
||||||
@@ -1438,7 +1445,7 @@ function OutputStream(options) {
|
|||||||
if (self.args.length > 0) return true;
|
if (self.args.length > 0) return true;
|
||||||
|
|
||||||
return output.option("beautify");
|
return output.option("beautify");
|
||||||
};
|
}
|
||||||
|
|
||||||
function best_of(a) {
|
function best_of(a) {
|
||||||
var best = a[0], len = best.length;
|
var best = a[0], len = best.length;
|
||||||
@@ -1449,7 +1456,7 @@ function OutputStream(options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return best;
|
return best;
|
||||||
};
|
}
|
||||||
|
|
||||||
function make_num(num) {
|
function make_num(num) {
|
||||||
var str = num.toString(10), a = [ str.replace(/^0\./, ".").replace('e+', 'e') ], m;
|
var str = num.toString(10), a = [ str.replace(/^0\./, ".").replace('e+', 'e') ], m;
|
||||||
@@ -1469,7 +1476,7 @@ function OutputStream(options) {
|
|||||||
str.substr(str.indexOf(".")));
|
str.substr(str.indexOf(".")));
|
||||||
}
|
}
|
||||||
return best_of(a);
|
return best_of(a);
|
||||||
};
|
}
|
||||||
|
|
||||||
function make_block(stmt, output) {
|
function make_block(stmt, output) {
|
||||||
if (!stmt || stmt instanceof AST_EmptyStatement)
|
if (!stmt || stmt instanceof AST_EmptyStatement)
|
||||||
@@ -1481,7 +1488,7 @@ function OutputStream(options) {
|
|||||||
stmt.print(output);
|
stmt.print(output);
|
||||||
output.newline();
|
output.newline();
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
/* -----[ source map generators ]----- */
|
/* -----[ source map generators ]----- */
|
||||||
|
|
||||||
|
|||||||
@@ -8,14 +8,14 @@ too_short: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect_exact: [
|
expect_exact: [
|
||||||
'function f(a){',
|
"function f(",
|
||||||
'return{',
|
"a){return{",
|
||||||
'c:42,',
|
"c:42,d:a(",
|
||||||
'd:a(),',
|
'),e:"foo"}',
|
||||||
'e:"foo"}}',
|
"}",
|
||||||
]
|
]
|
||||||
expect_warnings: [
|
expect_warnings: [
|
||||||
"WARN: Output exceeds 10 characters"
|
"WARN: Output exceeds 10 characters",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,11 +29,25 @@ just_enough: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect_exact: [
|
expect_exact: [
|
||||||
'function f(a){',
|
"function f(a){",
|
||||||
'return{c:42,',
|
"return{c:42,",
|
||||||
'd:a(),e:"foo"}',
|
'd:a(),e:"foo"}',
|
||||||
'}',
|
"}",
|
||||||
]
|
|
||||||
expect_warnings: [
|
|
||||||
]
|
]
|
||||||
|
expect_warnings: []
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_304: {
|
||||||
|
beautify = {
|
||||||
|
max_line_len: 10,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 0, b = 0, c = 0, d = 0, e = 0;
|
||||||
|
}
|
||||||
|
expect_exact: [
|
||||||
|
"var a=0,",
|
||||||
|
"b=0,c=0,",
|
||||||
|
"d=0,e=0;",
|
||||||
|
]
|
||||||
|
expect_warnings: []
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
function test(a){
|
function test(a){
|
||||||
"aaaaaaaaaaaaaaaa"
|
"aaaaaaaaaaaaaaaa"
|
||||||
;a(err,data),a(err,data)
|
;a(err,data),a(err,
|
||||||
}
|
data)}
|
||||||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIjAiXSwibmFtZXMiOlsidGVzdCIsImNhbGxiYWNrIiwiZXJyIiwiZGF0YSJdLCJtYXBwaW5ncyI6IkFBQUEsU0FBU0EsS0FBS0M7QUFDVjtDQUNBQSxFQUFTQyxJQUFLQyxNQUNkRixFQUFTQyxJQUFLQyJ9
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIjAiXSwibmFtZXMiOlsidGVzdCIsImNhbGxiYWNrIiwiZXJyIiwiZGF0YSJdLCJtYXBwaW5ncyI6IkFBQUEsU0FBU0EsS0FBS0M7QUFDVjtDQUNBQSxFQUFTQyxJQUFLQyxNQUNkRixFQUFTQztBQUFLQyJ9
|
||||||
Reference in New Issue
Block a user