Fix mis-indenting in untainted var lines

Fixes issue #184.
This commit is contained in:
Liam Newman 2013-03-15 02:25:24 -07:00
parent 3a35ec6fd4
commit 23a6428eef
2 changed files with 12 additions and 10 deletions

View File

@ -1194,18 +1194,20 @@ function js_beautify(js_source_text, options) {
// do not break on comma, for(var a = 1, b = 2)
flags.var_line_tainted = false;
}
if (flags.var_line_tainted) {
print_token();
if (flags.var_line) {
flags.var_line_reindented = true;
flags.var_line_tainted = false;
print_newline();
break;
} else {
flags.var_line_tainted = false;
}
print_token();
output_space_before_token = true;
if (flags.var_line_tainted) {
flags.var_line_tainted = false;
print_newline();
} else {
output_space_before_token = true;
}
break;
}

View File

@ -93,6 +93,7 @@ function run_beautifier_tests(test_obj)
bt("a();\n\nb();", "a();\n\nb();");
bt('var a = 1 var b = 2', "var a = 1\nvar b = 2");
bt('var a=1, b=c[d], e=6;', 'var a = 1,\n b = c[d],\n e = 6;');
bt('var a,\n b,\n c;');
bt('a = " 12345 "');
bt("a = ' 12345 '");
bt('if (a == 1) b = 2;', "if (a == 1) b = 2;");
@ -316,8 +317,7 @@ function run_beautifier_tests(test_obj)
bt('if (a) a()\nnewline()');
bt('a=typeof(x)', 'a = typeof(x)');
// known problem, the next "b = false" has insufficient indentation:
bt('var a = function() {\n return null;\n},\nb = false;');
bt('var a = function() {\n return null;\n},\n b = false;');
bt('var a = function() {\n func1()\n}');
bt('var a = function() {\n func1()\n}\nvar b = function() {\n func2()\n}');