Skip to content

Commit

Permalink
Merge branch 'array_objects'
Browse files Browse the repository at this point in the history
  • Loading branch information
einars committed Jan 31, 2011
2 parents f614cc4 + 16c1f22 commit 97732b2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 6 additions & 1 deletion beautify.js
Expand Up @@ -726,7 +726,12 @@ function js_beautify(js_source_text, options) {
} else {
// if TK_OPERATOR or TK_START_EXPR
if (is_array(flags.previous_mode) && last_text === ',') {
print_newline(); // [a, b, c, {
if (last_last_text === '}') {
// }, { in array context
print_single_space();
} else {
print_newline(); // [a, b, c, {
}
}
}
indent();
Expand Down
6 changes: 4 additions & 2 deletions tests/beautify-tests.js
Expand Up @@ -157,6 +157,8 @@ function run_beautifier_tests(test_obj)
bt("a = 1; // comment\n", "a = 1; // comment");
bt("a = 1;\n // comment\n", "a = 1;\n// comment");

bt('o = [{a:b},{c:d}]', 'o = [{\n a: b\n}, {\n c: 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

Expand Down Expand Up @@ -206,7 +208,7 @@ function run_beautifier_tests(test_obj)
bt('{a:#1#}', '{\n a: #1#\n}');

test_fragment('{a:1},{a:2}', '{\n a: 1\n}, {\n a: 2\n}');
test_fragment('var ary=[{a:1}, {a:2}];', 'var ary = [{\n a: 1\n},\n{\n a: 2\n}];');
test_fragment('var ary=[{a:1}, {a:2}];', 'var ary = [{\n a: 1\n}, {\n a: 2\n}];');

test_fragment('{a:#1', '{\n a: #1'); // incomplete
test_fragment('{a:#', '{\n a: #'); // incomplete
Expand Down Expand Up @@ -306,7 +308,7 @@ function run_beautifier_tests(test_obj)
bt("var a2, b2, c2, d2 = 0, c = function() {}, d = '';", "var a2, b2, c2, d2 = 0,\n c = function() {},\n d = '';");
bt('var o2=$.extend(a);function(){alert(x);}', 'var o2 = $.extend(a);\n\nfunction() {\n alert(x);\n}');

bt('{"x":[{"a":1,"b":3},7,8,8,8,8,{"b":99},{"a":11}]}', '{\n "x": [{\n "a": 1,\n "b": 3\n },\n 7, 8, 8, 8, 8,\n {\n "b": 99\n },\n {\n "a": 11\n }]\n}');
bt('{"x":[{"a":1,"b":3},7,8,8,8,8,{"b":99},{"a":11}]}', '{\n "x": [{\n "a": 1,\n "b": 3\n },\n 7, 8, 8, 8, 8,\n {\n "b": 99\n }, {\n "a": 11\n }]\n}');

bt('{"1":{"1a":"1b"},"2"}', '{\n "1": {\n "1a": "1b"\n },\n "2"\n}');
bt('{a:{a:b},c}', '{\n a: {\n a: b\n },\n c\n}');
Expand Down

0 comments on commit 97732b2

Please sign in to comment.