diff --git a/beautify.js b/beautify.js index b86206b0..7f152894 100644 --- a/beautify.js +++ b/beautify.js @@ -936,6 +936,10 @@ function js_beautify(js_source_text, options) { print_token(); flags.var_line = false; flags.var_line_reindented = false; + if (flags.mode == 'OBJECT') { + // OBJECT mode is weird and doesn't get reset too well. + flags.mode = 'BLOCK'; + } break; case 'TK_STRING': diff --git a/python/jsbeautifier.py b/python/jsbeautifier.py index fb4f1e23..6fa0ef0a 100755 --- a/python/jsbeautifier.py +++ b/python/jsbeautifier.py @@ -189,7 +189,7 @@ class Beautifier: parser_pos = 0 while True: token_text, token_type = self.get_next_token() - # print (token_text, token_type, self.flags.mode) + #print (token_text, token_type, self.flags.mode) if token_type == 'TK_EOF': break @@ -859,6 +859,9 @@ class Beautifier: self.append(token_text) self.flags.var_line = False self.flags.var_line_reindented = False + if self.flags.mode == 'OBJECT': + # OBJECT mode is weird and doesn't get reset too well. + self.flags.mode = 'BLOCK' def handle_string(self, token_text): diff --git a/python/test-jsbeautifier.py b/python/test-jsbeautifier.py index 996ad5cb..6770e483 100755 --- a/python/test-jsbeautifier.py +++ b/python/test-jsbeautifier.py @@ -396,6 +396,7 @@ def main(): bt('if (foo) bar();\nelse break'); bt('function x() {\n foo();\n}zzz', 'function x() {\n foo();\n}\nzzz'); + bt('a: do {} while (); xxx', 'a: do {} while ();\nxxx'); opts.brace_style = "end-expand"; diff --git a/tests/beautify-tests.js b/tests/beautify-tests.js index 4dc2d70a..57f9a2a0 100644 --- a/tests/beautify-tests.js +++ b/tests/beautify-tests.js @@ -414,6 +414,7 @@ function run_beautifier_tests(test_obj) bt('if (foo) bar();\nelse break'); bt('function x() {\n foo();\n}zzz', 'function x() {\n foo();\n}\nzzz'); + bt('a: do {} while (); xxx', 'a: do {} while ();\nxxx'); opts.brace_style = "end-expand";