Fix rare-ish bug with OBJECT mode

This commit is contained in:
Einar Lielmanis 2011-03-31 07:06:13 +03:00
parent b80ca146e2
commit 8a3123ab9f
4 changed files with 10 additions and 1 deletions

View File

@ -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':

View File

@ -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):

View File

@ -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";

View File

@ -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";