mirror of
https://github.com/beautifier/js-beautify.git
synced 2024-11-26 22:20:56 +00:00
parent
b770af0123
commit
5b2736f096
@ -919,7 +919,7 @@
|
||||
} else if (last_type !== 'TK_END_EXPR') {
|
||||
if ((last_type !== 'TK_START_EXPR' || !(current_token.type === 'TK_RESERVED' && in_array(current_token.text, ['var', 'let', 'const']))) && flags.last_text !== ':') {
|
||||
// no need to force newline on 'var': for (var x = 0...)
|
||||
if (current_token.type === 'TK_RESERVED' && current_token.text === 'if' && flags.last_word === 'else' && flags.last_text !== '{') {
|
||||
if (current_token.type === 'TK_RESERVED' && current_token.text === 'if' && flags.last_text === 'else') {
|
||||
// no newline for } else if {
|
||||
output.space_before_token = true;
|
||||
} else {
|
||||
|
@ -1732,6 +1732,19 @@ function run_beautifier_tests(test_obj, Urlencoded, js_beautify, html_beautify,
|
||||
'};');
|
||||
// END tests for issue 440
|
||||
|
||||
// START tests for issue 311
|
||||
// if-else with braces edge case
|
||||
bt('if(x){a();}else{b();}if(y){c();}',
|
||||
'if (x) {\n' +
|
||||
' a();\n' +
|
||||
'} else {\n' +
|
||||
' b();\n' +
|
||||
'}\n' +
|
||||
'if (y) {\n' +
|
||||
' c();\n' +
|
||||
'}');
|
||||
// END tests for issue 311
|
||||
|
||||
// START tests for issue 485
|
||||
// ensure function declarations behave the same in arrays as elsewhere
|
||||
bt( 'var v = ["a",\n' +
|
||||
|
@ -861,7 +861,7 @@ class Beautifier:
|
||||
if (self.last_type != 'TK_START_EXPR' or not (current_token.type == 'TK_RESERVED' and current_token.text in ['var', 'let', 'const'])) and self.flags.last_text != ':':
|
||||
# no need to force newline on VAR -
|
||||
# for (var x = 0...
|
||||
if current_token.type == 'TK_RESERVED' and current_token.text == 'if' and self.flags.last_word == 'else' and self.flags.last_text != '{':
|
||||
if current_token.type == 'TK_RESERVED' and current_token.text == 'if' and self.flags.last_text == 'else':
|
||||
self.output.space_before_token = True
|
||||
else:
|
||||
self.print_newline()
|
||||
|
@ -1602,6 +1602,19 @@ class TestJSBeautifier(unittest.TestCase):
|
||||
'};');
|
||||
# END tests for issue 440
|
||||
|
||||
# START tests for issue 311
|
||||
# if-else with braces edge case
|
||||
bt('if(x){a();}else{b();}if(y){c();}',
|
||||
'if (x) {\n' +
|
||||
' a();\n' +
|
||||
'} else {\n' +
|
||||
' b();\n' +
|
||||
'}\n' +
|
||||
'if (y) {\n' +
|
||||
' c();\n' +
|
||||
'}');
|
||||
# END tests for issue 311
|
||||
|
||||
# START tests for issue 485
|
||||
# ensure function declarations behave the same in arrays as elsewhere
|
||||
bt( 'var v = ["a",\n' +
|
||||
|
Loading…
Reference in New Issue
Block a user