js-beautify
Advanced tools
Comparing version 0.3.4 to 0.3.5
364
beautify.js
@@ -68,4 +68,4 @@ /*jslint onevar: false, plusplus: false */ | ||
var whitespace, wordchar, punct, parser_pos, line_starters, digits; | ||
var prefix, token_type, do_block_just_closed; | ||
var wanted_newline, just_added_newline, n_newlines; | ||
var prefix, token_type; | ||
var wanted_newline, n_newlines, output_wrapped, output_space_before_token; | ||
var preindent_string = ''; | ||
@@ -88,3 +88,2 @@ | ||
var opt_indent_size = options.indent_size ? parseInt(options.indent_size) : 4, | ||
@@ -101,4 +100,2 @@ opt_indent_char = options.indent_char ? options.indent_char : ' ', | ||
just_added_newline = false; | ||
// cache the source's length. | ||
@@ -140,2 +137,17 @@ var input_length = js_source_text.length; | ||
function just_added_newline() { | ||
return output[output.length - 1] === "\n"; | ||
} | ||
function _last_index_of(arr, find) { | ||
var i = arr.length - 1; | ||
if (i < 0) i += arr.length; | ||
if (i > arr.length - 1) { | ||
i = arr.length - 1; | ||
} | ||
for (i++; i-- > 0;) { | ||
if (i in arr && arr[i]===find) return i; | ||
} | ||
return -1; | ||
} | ||
function allow_wrap_or_preserved_newline(force_linewrap) { | ||
@@ -145,7 +157,10 @@ force_linewrap = typeof force_linewrap === 'undefined' ? false : force_linewrap; | ||
var current_line = ''; | ||
var start_line = output.lastIndexOf('\n') + 1; | ||
var proposed_line_length = 0; | ||
var start_line = _last_index_of(output, '\n') + 1; | ||
// never wrap the first token of a line. | ||
if(start_line < output.length) { | ||
current_line = output.slice(start_line).join(''); | ||
if(current_line.length + token_text.length >= opt_wrap_line_length) { | ||
proposed_line_length = current_line.length + token_text.length + | ||
(output_space_before_token ? 1 : 0); | ||
if(proposed_line_length >= opt_wrap_line_length) { | ||
force_linewrap = true; | ||
@@ -155,18 +170,21 @@ } | ||
} | ||
if(!just_added_newline && | ||
((opt_preserve_newlines && wanted_newline) || force_linewrap)) { | ||
print_newline(); | ||
print_indent_string(); | ||
wanted_newline = false; | ||
if(((opt_preserve_newlines && wanted_newline) || force_linewrap) && !just_added_newline()) { | ||
print_newline(false, true); | ||
output_wrapped = true; | ||
wanted_newline = false; | ||
} | ||
} | ||
function print_newline(ignore_repeated) { | ||
function print_newline(force_newline, preserve_statement_flags) { | ||
output_wrapped = false; | ||
output_space_before_token = false; | ||
flags.eat_next_space = false; | ||
if (!preserve_statement_flags) { | ||
if(last_text !== ';') { | ||
while (flags.mode === 'STATEMENT' && !flags.if_block) { | ||
restore_mode(); | ||
} | ||
} | ||
} | ||
ignore_repeated = typeof ignore_repeated === 'undefined' ? true : ignore_repeated; | ||
trim_output(); | ||
if (!output.length) { | ||
@@ -176,16 +194,20 @@ return; // no newline on start of file | ||
if (output[output.length - 1] !== "\n" || !ignore_repeated) { | ||
just_added_newline = true; | ||
if (force_newline || !just_added_newline()) { | ||
output.push("\n"); | ||
} | ||
} | ||
if (opt_keep_array_indentation && is_array(flags.mode) && flags.whitespace_before.length) { | ||
output.push(flags.whitespace_before.join('') + ''); | ||
} else { | ||
if (preindent_string) { | ||
output.push(preindent_string); | ||
function print_line_indentation() { | ||
if(just_added_newline()) { | ||
if (opt_keep_array_indentation && is_array(flags.mode) && flags.whitespace_before.length) { | ||
output.push(flags.whitespace_before.join('') + ''); | ||
} else { | ||
if (preindent_string) { | ||
output.push(preindent_string); | ||
} | ||
print_indent_string(flags.indentation_level); | ||
print_indent_string(flags.var_line && flags.var_line_reindented); | ||
print_indent_string(output_wrapped); | ||
} | ||
print_indent_string(flags.indentation_level); | ||
print_indent_string(flags.var_line && flags.var_line_reindented); | ||
} | ||
@@ -213,21 +235,20 @@ } | ||
if (flags.eat_next_space) { | ||
flags.eat_next_space = false; | ||
} else if (last_type === 'TK_COMMENT') { | ||
print_newline(); | ||
} else { | ||
if (output.length) { | ||
last_output = output[output.length - 1]; | ||
} | ||
if (last_output !== ' ' && last_output !== '\n' && last_output !== indent_string) { // prevent occassional duplicate space | ||
output.push(' '); | ||
} | ||
if (output.length) { | ||
last_output = output[output.length - 1]; | ||
} | ||
if (!just_added_newline() && last_output !== ' ' && last_output !== indent_string) { // prevent occassional duplicate space | ||
output.push(' '); | ||
} | ||
} | ||
function print_token() { | ||
just_added_newline = false; | ||
flags.eat_next_space = false; | ||
output.push(token_text); | ||
function print_token(printable_token) { | ||
printable_token = printable_token || token_text; | ||
print_line_indentation(); | ||
output_wrapped = false; | ||
if (output_space_before_token) { | ||
print_single_space(); | ||
output_space_before_token = false; | ||
} | ||
output.push(printable_token); | ||
} | ||
@@ -239,9 +260,2 @@ | ||
function remove_indent() { | ||
if (output.length && output[output.length - 1] === indent_string) { | ||
output.pop(); | ||
} | ||
} | ||
function set_mode(mode) { | ||
@@ -258,7 +272,8 @@ if (flags) { | ||
in_html_comment: false, | ||
if_line: false, | ||
if_block: false, | ||
do_block: false, | ||
do_while: false, | ||
in_case_statement: false, // switch(..){ INSIDE HERE } | ||
in_case: false, // we're on the exact line with "case 0:" | ||
case_body: false, // the indented case-action block | ||
eat_next_space: false, | ||
indentation_level: (flags ? flags.indentation_level + ((flags.var_line && flags.var_line_reindented) ? 1 : 0) : 0), | ||
@@ -278,3 +293,2 @@ ternary_depth: 0 | ||
function restore_mode() { | ||
do_block_just_closed = flags.mode === 'DO_BLOCK'; | ||
if (flag_store.length > 0) { | ||
@@ -287,2 +301,17 @@ var mode = flags.mode; | ||
function start_of_statement() { | ||
if ( | ||
(last_text === 'do' || | ||
(last_text === 'else' && token_text !== 'if' ) || | ||
(last_type === 'TK_END_EXPR' && (flags.previous_mode === '(FOR-EXPRESSION)' || flags.previous_mode === '(COND-EXPRESSION)'))) | ||
) { | ||
allow_wrap_or_preserved_newline(); | ||
set_mode('STATEMENT'); | ||
indent(); | ||
output_wrapped = false; | ||
return true; | ||
} | ||
return false; | ||
} | ||
function all_lines_start_with(lines, c) { | ||
@@ -692,5 +721,5 @@ for (var i = 0; i < lines.length; i++) { | ||
output = []; | ||
output_wrapped = false; | ||
output_space_before_token = false; | ||
do_block_just_closed = false; | ||
whitespace = "\n\r\t ".split(''); | ||
@@ -726,4 +755,3 @@ wordchar = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$'.split(''); | ||
for (i = 0; i < n_newlines; i += 1) { | ||
print_newline(false); | ||
just_added_newline = true; | ||
print_newline(true); | ||
} | ||
@@ -738,5 +766,5 @@ } else { | ||
if( n_newlines > 1) { | ||
for (i = 0; i < n_newlines; i += 1) { | ||
print_newline(i === 0); | ||
just_added_newline = true; | ||
print_newline(); | ||
for (i = 1; i < n_newlines; i += 1) { | ||
print_newline(true); | ||
} | ||
@@ -750,2 +778,5 @@ } | ||
case 'TK_START_EXPR': | ||
if (start_of_statement()) { | ||
// The conditional starts the statement if appropriate. | ||
} | ||
@@ -758,3 +789,3 @@ if (token_text === '[') { | ||
if (in_array(last_text, line_starters)) { | ||
print_single_space(); | ||
output_space_before_token = true; | ||
} | ||
@@ -798,8 +829,6 @@ set_mode('(EXPRESSION)'); | ||
} else { | ||
if (last_word === 'for') { | ||
if (last_text === 'for') { | ||
set_mode('(FOR-EXPRESSION)'); | ||
} else if (in_array(last_word, ['if', 'while'])) { | ||
} else if (in_array(last_text, ['if', 'while'])) { | ||
set_mode('(COND-EXPRESSION)'); | ||
@@ -819,11 +848,11 @@ } else { | ||
} else if (last_type !== 'TK_WORD' && last_type !== 'TK_OPERATOR') { | ||
print_single_space(); | ||
output_space_before_token = true; | ||
} else if (last_word === 'function' || last_word === 'typeof') { | ||
// function() vs function () | ||
if (opt_jslint_happy) { | ||
print_single_space(); | ||
output_space_before_token = true; | ||
} | ||
} else if (in_array(last_text, line_starters) || last_text === 'catch') { | ||
if (opt_space_before_conditional) { | ||
print_single_space(); | ||
output_space_before_token = true; | ||
} | ||
@@ -849,3 +878,3 @@ } | ||
if (is_special_word(last_text)) { | ||
print_single_space(); | ||
output_space_before_token = true; | ||
} else { | ||
@@ -875,11 +904,17 @@ // allow preserved newlines before dots in general | ||
print_token(); | ||
// do {} while () // no statement required after | ||
if (flags.do_while && flags.previous_mode === '(COND-EXPRESSION)') | ||
{ | ||
flags.previous_mode = '(EXPRESSION)'; | ||
flags.do_block = false; | ||
flags.do_while = false; | ||
} | ||
break; | ||
case 'TK_START_BLOCK': | ||
set_mode('BLOCK'); | ||
if (last_word === 'do') { | ||
set_mode('DO_BLOCK'); | ||
} else { | ||
set_mode('BLOCK'); | ||
} | ||
if (opt_brace_style === "expand" || opt_brace_style === "expand-strict") { | ||
@@ -890,3 +925,3 @@ var empty_braces = false; | ||
if (!empty_braces) { | ||
print_newline(true); | ||
print_newline(); | ||
} | ||
@@ -897,5 +932,5 @@ } else { | ||
(is_special_word(last_text) && last_text !== 'else')) { | ||
print_single_space(); | ||
output_space_before_token = true; | ||
} else { | ||
print_newline(true); | ||
print_newline(); | ||
} | ||
@@ -913,3 +948,3 @@ } | ||
} else { | ||
print_single_space(); | ||
output_space_before_token = true; | ||
} | ||
@@ -921,3 +956,3 @@ } else { | ||
// }, { in array context | ||
print_single_space(); | ||
output_space_before_token = true; | ||
} else { | ||
@@ -928,4 +963,4 @@ print_newline(); // [a, b, c, { | ||
} | ||
print_token(); | ||
indent(); | ||
print_token(); | ||
} | ||
@@ -944,9 +979,3 @@ | ||
if (last_type === 'TK_START_BLOCK') { | ||
// nothing | ||
if (just_added_newline) { | ||
remove_indent(); | ||
} else { | ||
// {} | ||
trim_output(); | ||
} | ||
// {} | ||
} else { | ||
@@ -968,19 +997,37 @@ if (is_array(flags.mode) && opt_keep_array_indentation) { | ||
case 'TK_WORD': | ||
if (wanted_newline && last_type !== 'TK_OPERATOR' | ||
if (start_of_statement()) { | ||
// The conditional starts the statement if appropriate. | ||
} else if (wanted_newline && last_type !== 'TK_OPERATOR' | ||
&& last_type !== 'TK_EQUALS' | ||
&& !flags.if_line && (opt_preserve_newlines || last_text !== 'var')) { | ||
&& (opt_preserve_newlines || last_text !== 'var')) { | ||
print_newline(); | ||
} | ||
// no, it's not you. even I have problems understanding how this works | ||
// and what does what. | ||
if (do_block_just_closed) { | ||
if (flags.do_block && !flags.do_while) { | ||
// do {} ## while () | ||
print_single_space(); | ||
print_token(); | ||
print_single_space(); | ||
do_block_just_closed = false; | ||
break; | ||
if (token_text !== 'while') { | ||
// if we don't see the expected while, recover | ||
print_newline(); | ||
flags.do_block = false; | ||
} else { | ||
output_space_before_token = true; | ||
print_token(); | ||
output_space_before_token = true; | ||
flags.do_while = true; | ||
break; | ||
} | ||
} | ||
if (flags.if_block) { | ||
if(token_text !== 'else') { | ||
while (flags.mode === 'STATEMENT') { | ||
restore_mode(); | ||
} | ||
flags.if_block = false; | ||
} | ||
} | ||
prefix = 'NONE'; | ||
@@ -992,7 +1039,7 @@ | ||
} | ||
if ((just_added_newline || last_text === ';') && last_text !== '{' | ||
if ((just_added_newline() || last_text === ';') && last_text !== '{' | ||
&& last_type !== 'TK_BLOCK_COMMENT' && last_type !== 'TK_COMMENT') { | ||
// make sure there is a nice clean space of at least one blank line | ||
// before a new function definition | ||
n_newlines = just_added_newline ? n_newlines : 0; | ||
n_newlines = just_added_newline() ? n_newlines : 0; | ||
if (!opt_preserve_newlines) { | ||
@@ -1003,3 +1050,3 @@ n_newlines = 1; | ||
for (var i = 0; i < 2 - n_newlines; i++) { | ||
print_newline(false); | ||
print_newline(true); | ||
} | ||
@@ -1009,3 +1056,3 @@ } | ||
if (last_text === 'get' || last_text === 'set' || last_text === 'new' || last_text === 'return') { | ||
print_single_space(); | ||
output_space_before_token = true; | ||
} else { | ||
@@ -1016,3 +1063,3 @@ print_newline(); | ||
// foo = function | ||
print_single_space(); | ||
output_space_before_token = true; | ||
} else if (is_expression(flags.mode)) { | ||
@@ -1035,3 +1082,2 @@ // print nothing | ||
flags.case_body = false; | ||
remove_indent(); | ||
} | ||
@@ -1053,6 +1099,6 @@ print_token(); | ||
prefix = 'SPACE'; | ||
print_single_space(); | ||
output_space_before_token = true; | ||
} | ||
} | ||
} else if (last_type === 'TK_SEMICOLON' && (flags.mode === 'BLOCK' || flags.mode === 'DO_BLOCK')) { | ||
} else if (last_type === 'TK_SEMICOLON' && flags.mode === 'BLOCK') { | ||
prefix = 'NEWLINE'; | ||
@@ -1064,7 +1110,2 @@ } else if (last_type === 'TK_SEMICOLON' && is_expression(flags.mode)) { | ||
} else if (last_type === 'TK_WORD') { | ||
if (last_text === 'else') { | ||
// eat newlines between ...else *** some_op... | ||
// won't preserve extra newlines in this place (if any), but don't care that much | ||
trim_output(true); | ||
} | ||
prefix = 'SPACE'; | ||
@@ -1074,3 +1115,3 @@ } else if (last_type === 'TK_START_BLOCK') { | ||
} else if (last_type === 'TK_END_EXPR') { | ||
print_single_space(); | ||
output_space_before_token = true; | ||
prefix = 'NEWLINE'; | ||
@@ -1088,6 +1129,2 @@ } | ||
if (flags.if_line && last_type === 'TK_END_EXPR') { | ||
flags.if_line = false; | ||
} | ||
if (last_type === 'TK_COMMA' || last_type === 'TK_START_EXPR' || last_type === 'TK_EQUALS' || last_type === 'TK_OPERATOR') { | ||
@@ -1104,3 +1141,3 @@ if (flags.mode !== 'OBJECT') { | ||
trim_output(true); | ||
print_single_space(); | ||
output_space_before_token = true; | ||
} | ||
@@ -1110,3 +1147,3 @@ } else if (prefix === 'NEWLINE') { | ||
// no newline between 'return nnn' | ||
print_single_space(); | ||
output_space_before_token = true; | ||
} else if (last_type !== 'TK_END_EXPR') { | ||
@@ -1117,3 +1154,3 @@ if ((last_type !== 'TK_START_EXPR' || token_text !== 'var') && last_text !== ':') { | ||
// no newline for } else if { | ||
print_single_space(); | ||
output_space_before_token = true; | ||
} else { | ||
@@ -1133,3 +1170,3 @@ flags.var_line = false; | ||
} else if (prefix === 'SPACE') { | ||
print_single_space(); | ||
output_space_before_token = true; | ||
} | ||
@@ -1145,8 +1182,9 @@ print_token(); | ||
if (token_text === 'do') { | ||
flags.do_block = true; | ||
} | ||
if (token_text === 'if') { | ||
flags.if_line = true; | ||
flags.if_block = true; | ||
} | ||
if (token_text === 'else') { | ||
flags.if_line = false; | ||
} | ||
@@ -1156,3 +1194,5 @@ break; | ||
case 'TK_SEMICOLON': | ||
while (flags.mode === 'STATEMENT' && !flags.if_block) { | ||
restore_mode(); | ||
} | ||
print_token(); | ||
@@ -1168,7 +1208,8 @@ flags.var_line = false; | ||
case 'TK_STRING': | ||
if (last_type === 'TK_END_EXPR' && in_array(flags.previous_mode, ['(COND-EXPRESSION)', '(FOR-EXPRESSION)'])) { | ||
print_single_space(); | ||
if (start_of_statement()) { | ||
// The conditional starts the statement if appropriate. | ||
// One difference - strings want at least a space before | ||
output_space_before_token = true; | ||
} else if (last_type === 'TK_WORD') { | ||
print_single_space(); | ||
output_space_before_token = true; | ||
} else if (last_type === 'TK_COMMA' || last_type === 'TK_START_EXPR' || last_type === 'TK_EQUALS' || last_type === 'TK_OPERATOR') { | ||
@@ -1189,5 +1230,5 @@ if (flags.mode !== 'OBJECT') { | ||
} | ||
print_single_space(); | ||
output_space_before_token = true; | ||
print_token(); | ||
print_single_space(); | ||
output_space_before_token = true; | ||
break; | ||
@@ -1212,10 +1253,6 @@ | ||
print_token(); | ||
print_single_space(); | ||
output_space_before_token = true; | ||
break; | ||
} | ||
if (last_type === 'TK_COMMENT') { | ||
print_newline(); | ||
} | ||
if (last_type === 'TK_END_BLOCK' && flags.mode !== "(EXPRESSION)") { | ||
@@ -1226,3 +1263,3 @@ print_token(); | ||
} else { | ||
print_single_space(); | ||
output_space_before_token = true; | ||
} | ||
@@ -1236,3 +1273,3 @@ } else { | ||
print_token(); | ||
print_single_space(); | ||
output_space_before_token = true; | ||
} | ||
@@ -1249,3 +1286,3 @@ } | ||
// "return" had a special handling in TK_WORD. Now we need to return the favor | ||
print_single_space(); | ||
output_space_before_token = true; | ||
print_token(); | ||
@@ -1291,3 +1328,3 @@ break; | ||
if (flags.mode === 'BLOCK' && (last_text === '{' || last_text === ';')) { | ||
if ((flags.mode === 'BLOCK' || flags.mode === 'STATEMENT') && (last_text === '{' || last_text === ';')) { | ||
// { foo; --i } | ||
@@ -1309,12 +1346,5 @@ // foo(); --bar; | ||
} | ||
if (space_before) { | ||
print_single_space(); | ||
} | ||
output_space_before_token = output_space_before_token || space_before; | ||
print_token(); | ||
if (space_after) { | ||
print_single_space(); | ||
} | ||
output_space_before_token = space_after; | ||
break; | ||
@@ -1329,8 +1359,7 @@ | ||
// javadoc: reformat and reindent | ||
print_newline(); | ||
output.push(lines[0]); | ||
print_newline(false,true); | ||
print_token(lines[0]); | ||
for (j = 1; j < lines.length; j++) { | ||
print_newline(); | ||
output.push(' '); | ||
output.push(trim(lines[j])); | ||
print_newline(false,true); | ||
print_token(' ' + trim(lines[j])); | ||
} | ||
@@ -1343,9 +1372,9 @@ | ||
// multiline comment block starts with a new line | ||
print_newline(); | ||
print_newline(false,true); | ||
} else { | ||
// single-line /* comment */ stays where it is | ||
if (last_type === 'TK_END_BLOCK') { | ||
print_newline(); | ||
print_newline(false,true); | ||
} else { | ||
print_single_space(); | ||
output_space_before_token = true; | ||
} | ||
@@ -1355,3 +1384,5 @@ | ||
for (j = 0; j < lines.length; j++) { | ||
print_token(lines[0]); | ||
output.push("\n"); | ||
for (j = 1; j < lines.length; j++) { | ||
output.push(lines[j]); | ||
@@ -1363,3 +1394,3 @@ output.push("\n"); | ||
if (look_up('\n') !== '\n') { | ||
print_newline(); | ||
print_newline(false,true); | ||
} | ||
@@ -1370,5 +1401,5 @@ break; | ||
case 'TK_INLINE_COMMENT': | ||
print_single_space(); | ||
output_space_before_token = true; | ||
print_token(); | ||
print_single_space(); | ||
output_space_before_token = true; | ||
break; | ||
@@ -1378,3 +1409,3 @@ | ||
if (wanted_newline) { | ||
print_newline(); | ||
print_newline(false,true); | ||
} | ||
@@ -1384,11 +1415,7 @@ if (last_text === ',' && !wanted_newline) { | ||
} | ||
if (last_type !== 'TK_COMMENT') { | ||
if (wanted_newline) { | ||
print_newline(); | ||
} else { | ||
print_single_space(); | ||
} | ||
} | ||
output_space_before_token = true; | ||
print_token(); | ||
print_newline(); | ||
print_newline(false,true); | ||
break; | ||
@@ -1406,3 +1433,4 @@ | ||
// Also ignore unknown tokens. Again, the should result in better behavior. | ||
if(token_type !== 'TK_INLINE_COMMENT' && token_type !== 'TK_UNKNOWN') { | ||
if(token_type !== 'TK_INLINE_COMMENT' && token_type !== 'TK_COMMENT' && | ||
token_type !== 'TK_UNKNOWN') { | ||
last_last_text = last_text; | ||
@@ -1409,0 +1437,0 @@ last_type = token_type; |
{ | ||
"name": "js-beautify", | ||
"version": "0.3.4", | ||
"version": "0.3.5", | ||
"description": "jsbeautifier.org for node", | ||
@@ -5,0 +5,0 @@ "main": "beautify.js", |
@@ -89,3 +89,4 @@ /*global js_beautify: true */ | ||
bt('return .5'); | ||
test_fragment(' return .5'); | ||
test_fragment(' return .5'); | ||
test_fragment(' return .5;\n a();'); | ||
bt('a = 1', 'a = 1'); | ||
@@ -100,3 +101,2 @@ bt('a=1', 'a = 1'); | ||
bt('if(1){2}else{3}', "if (1) {\n 2\n} else {\n 3\n}"); | ||
bt('if (foo) bar();\nelse\ncar();', 'if (foo) bar();\nelse car();'); | ||
bt('if(1||2);', 'if (1 || 2);'); | ||
@@ -140,6 +140,8 @@ bt('(a==1)||(b==2)', '(a == 1) || (b == 2)'); | ||
bt('if((a))foo();', 'if ((a)) foo();'); | ||
bt('for(var i=0;;)', 'for (var i = 0;;)'); | ||
bt('for(var i=0;;) a', 'for (var i = 0;;) a'); | ||
bt('for(var i=0;;)\na', 'for (var i = 0;;)\n a'); | ||
bt('a++;', 'a++;'); | ||
bt('for(;;i++)', 'for (;; i++)'); | ||
bt('for(;;++i)', 'for (;; ++i)'); | ||
bt('for(;;i++)a()', 'for (;; i++) a()'); | ||
bt('for(;;i++)\na()', 'for (;; i++)\n a()'); | ||
bt('for(;;++i)a', 'for (;; ++i) a'); | ||
bt('return(1)', 'return (1)'); | ||
@@ -181,3 +183,2 @@ bt('try{a();}catch(b){c();}finally{d();}', "try {\n a();\n} catch (b) {\n c();\n} finally {\n d();\n}"); | ||
bt("if (a) {\n do();\n}"); // was: extra space appended | ||
bt("if\n(a)\nb();", "if (a) b();"); // test for proper newline removal | ||
@@ -198,5 +199,5 @@ bt("if (a) {\n// comment\n}else{\n// comment\n}", "if (a) {\n // comment\n} else {\n // comment\n}"); // if/else statement with empty body | ||
bt("delete x[x] if (a) b();", "delete x[x]\nif (a) b();"); | ||
bt("for(var a=1,b=2)", "for (var a = 1, b = 2)"); | ||
bt("for(var a=1,b=2,c=3)", "for (var a = 1, b = 2, c = 3)"); | ||
bt("for(var a=1,b=2,c=3;d<3;d++)", "for (var a = 1, b = 2, c = 3; d < 3; d++)"); | ||
bt("for(var a=1,b=2)d", "for (var a = 1, b = 2) d"); | ||
bt("for(var a=1,b=2,c=3) d", "for (var a = 1, b = 2, c = 3) d"); | ||
bt("for(var a=1,b=2,c=3;d<3;d++)\ne", "for (var a = 1, b = 2, c = 3; d < 3; d++)\n e"); | ||
bt("function x(){(a||b).c()}", "function x() {\n (a || b).c()\n}"); | ||
@@ -221,4 +222,4 @@ bt("function x(){return - 1}", "function x() {\n return -1\n}"); | ||
bt('for (; s-->0;)', 'for (; s-- > 0;)'); | ||
bt('for (; s++>0;)', 'for (; s++ > 0;)'); | ||
bt('for (; s-->0;)t', 'for (; s-- > 0;) t'); | ||
bt('for (; s++>0;)u', 'for (; s++ > 0;) u'); | ||
bt('a = s++>s--;', 'a = s++ > s--;'); | ||
@@ -474,3 +475,3 @@ bt('a = s++>--s;', 'a = s++ > --s;'); | ||
bt('if (foo) {}\nelse /regex/.test();'); | ||
// bt('if (foo) /regex/.test();'); // doesn't work, detects as a division. should it work? | ||
bt('if (foo) /regex/.test();'); | ||
@@ -496,3 +497,3 @@ bt('a = <?= external() ?> ;'); // not the most perfect thing in the world, but you're the weirdo beaufifying php mix-ins with javascript beautifier | ||
bt("var x = {\n set function()\n}"); | ||
bt("var x = set\n\nfunction() {}"); | ||
bt("var x = set\n\nfunction() {}", "var x = set\n\n function() {}"); | ||
@@ -544,11 +545,2 @@ bt('<!-- foo\nbar();\n-->'); | ||
bt('foo(a, /regex/)'); | ||
// known problem: the indentation of the next line is slightly borked :( | ||
// bt('if (foo) // comment\n bar();'); | ||
// bt('if (foo) // comment\n (bar());'); | ||
// bt('if (foo) // comment\n (bar());'); | ||
// bt('if (foo) // comment\n /asdf/;'); | ||
bt('if (foo) // comment\nbar();'); | ||
bt('if (foo) // comment\n(bar());'); | ||
bt('if (foo) // comment\n(bar());'); | ||
bt('if (foo) // comment\n/asdf/;'); | ||
@@ -678,3 +670,3 @@ bt('/* foo */\n"x"'); | ||
'if (wraps_can_occur && inside_an_if_block) that_is_\n' + | ||
' .okay();'); | ||
' .okay();'); | ||
@@ -692,3 +684,3 @@ opts.wrap_line_length = 70; | ||
'if (wraps_can_occur && inside_an_if_block) that_is_\n' + | ||
' .okay();'); | ||
' .okay();'); | ||
@@ -709,3 +701,3 @@ | ||
' inside_an_if_block) that_is_\n' + | ||
' .okay();'); | ||
' .okay();'); | ||
@@ -726,3 +718,3 @@ opts.wrap_line_length = 41; | ||
' inside_an_if_block) that_is_\n' + | ||
' .okay();'); | ||
' .okay();'); | ||
@@ -746,3 +738,3 @@ opts.wrap_line_length = 45; | ||
' inside_an_if_block) that_is_\n' + | ||
' .okay();\n' + | ||
' .okay();\n' + | ||
'}'); | ||
@@ -753,2 +745,18 @@ | ||
opts.preserve_newlines = false; | ||
bt('if (foo) // comment\n bar();'); | ||
bt('if (foo) // comment\n (bar());'); | ||
bt('if (foo) // comment\n (bar());'); | ||
bt('if (foo) // comment\n /asdf/;'); | ||
// these aren't ready yet. | ||
//bt('if (foo) // comment\n bar() /*i*/ + baz() /*j\n*/ + asdf();'); | ||
bt('if\n(foo)\nif\n(bar)\nif\n(baz)\nwhee();\na();', 'if (foo) if (bar) if (baz) whee();\na();'); | ||
bt('if\n(foo)\nif\n(bar)\nif\n(baz)\nwhee();\nelse\na();', 'if (foo) if (bar) if (baz) whee();\n else a();'); | ||
bt('if (foo)\nbar();\nelse\ncar();', 'if (foo) bar();\nelse car();'); | ||
bt('if (foo) if (bar) if (baz) whee();\na();'); | ||
bt('if (foo) a()\nif (bar) if (baz) whee();\na();'); | ||
bt("if\n(a)\nb();", "if (a) b();"); | ||
bt('var a =\nfoo', 'var a = foo'); | ||
@@ -766,2 +774,17 @@ bt('var a = {\n"a":1,\n"b":2}', "var a = {\n \"a\": 1,\n \"b\": 2\n}"); | ||
opts.preserve_newlines = true; | ||
bt('if (foo) // comment\n bar();'); | ||
bt('if (foo) // comment\n (bar());'); | ||
bt('if (foo) // comment\n (bar());'); | ||
bt('if (foo) // comment\n /asdf/;'); | ||
// these aren't ready yet. | ||
// bt('if (foo) // comment\n bar() /*i*/ + baz() /*j\n*/ + asdf();'); | ||
bt('if\n(foo)\nif\n(bar)\nif\n(baz)\nwhee();\na();', 'if (foo)\n if (bar)\n if (baz)\n whee();\na();'); | ||
bt('if\n(foo)\nif\n(bar)\nif\n(baz)\nwhee();\nelse\na();', 'if (foo)\n if (bar)\n if (baz)\n whee();\n else\n a();'); | ||
bt('if (foo) bar();\nelse\ncar();', 'if (foo) bar();\nelse\n car();'); | ||
bt('if (foo) if (bar) if (baz) whee();\na();'); | ||
bt('if (foo) a()\nif (bar) if (baz) whee();\na();'); | ||
bt("if\n(a)\nb();", "if (a)\n b();"); | ||
bt('var a =\nfoo', 'var a =\n foo'); | ||
@@ -768,0 +791,0 @@ bt('var a = {\n"a":1,\n"b":2}', "var a = {\n \"a\": 1,\n \"b\": 2\n}"); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
110417
2273