Make statements inside blocks close when the parent block closes

Closes #186
This commit is contained in:
Liam Newman 2013-03-16 18:11:39 -07:00
parent 1d3cf832df
commit 6206c3cf78
2 changed files with 19 additions and 0 deletions

View File

@ -928,6 +928,10 @@ function Beautifier(js_source_text, options) {
}
function handle_end_block() {
// statements inside blocks must all be closed when the parent block closes
while (flags.mode === 'STATEMENT') {
restore_mode();
}
restore_mode();
if (opt_brace_style === "expand" || opt_brace_style === "expand-strict") {
if (last_text !== '{') {

View File

@ -176,6 +176,10 @@ function run_beautifier_tests(test_obj)
bt("a = 1;\n // comment", "a = 1;\n// comment");
bt('a = [-1, -1, -1]');
// The exact formatting these should have is open for discussion, but they currently aren't right
//bt('a = [ // comment\n -1,\n -1,\n -1]');
//bt('var a = [ // comment\n -1,\n -1,\n -1]');
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
@ -748,6 +752,11 @@ function run_beautifier_tests(test_obj)
' this[p] = options[p];',
'if (options) for (var p in options) this[p] = options[p];');
bt('function f(a,b) {if(a) b()}function g(a,b) {if(!a) b()}',
'function f(a, b) {\n if (a) b()\n}\nfunction g(a, b) {\n if (!a) b()\n}');
bt('function f(a,b) {if(a) b()}\n\n\n\nfunction g(a,b) {if(!a) b()}',
'function f(a, b) {\n if (a) b()\n}\n\nfunction g(a, b) {\n if (!a) b()\n}');
bt("if\n(a)\nb();", "if (a) b();");
bt('var a =\nfoo', 'var a = foo');
bt('var a = {\n"a":1,\n"b":2}', "var a = {\n \"a\": 1,\n \"b\": 2\n}");
@ -778,6 +787,12 @@ function run_beautifier_tests(test_obj)
' for (var p in options)\n' +
' this[p] = options[p];');
bt('function f(a,b) {if(a) b()}function g(a,b) {if(!a) b()}',
'function f(a, b) {\n if (a) b()\n}\nfunction g(a, b) {\n if (!a) b()\n}');
bt('function f(a,b) {if(a) b()}\n\n\n\nfunction g(a,b) {if(!a) b()}',
'function f(a, b) {\n if (a) b()\n}\n\n\n\nfunction g(a, b) {\n if (!a) b()\n}');
bt("if\n(a)\nb();", "if (a)\n b();");
bt('var a =\nfoo', 'var a =\n foo');
bt('var a = {\n"a":1,\n"b":2}', "var a = {\n \"a\": 1,\n \"b\": 2\n}");