Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid breaking catch/finally on angular promises #436

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js/lib/beautify.js
Original file line number Diff line number Diff line change
Expand Up @@ -1323,7 +1323,7 @@

}

if (in_array(token_text, ['else', 'catch', 'finally'])) {
if (token_text === 'else' || (flags.last_text !== '.' && in_array(token_text, ['catch', 'finally']))) {
if (last_type !== 'TK_END_BLOCK' || opt.brace_style === "expand" || opt.brace_style === "end-expand") {
print_newline();
} else {
Expand Down
7 changes: 5 additions & 2 deletions js/test/beautify-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ function run_beautifier_tests(test_obj, Urlencoded, js_beautify, html_beautify,
opts.keep_array_indentation = false;
opts.brace_style = "collapse";


bt('');
bt('return .5');
test_fragment(' return .5');
Expand Down Expand Up @@ -270,6 +269,10 @@ function run_beautifier_tests(test_obj, Urlencoded, js_beautify, html_beautify,
// a common snippet in jQuery plugins
bt("settings = $.extend({},defaults,settings);", "settings = $.extend({}, defaults, settings);");

// promises specific
bt("$http().then().finally()", "$http().then().finally()");
bt("$http()\n.then()\n.finally()", "$http()\n .then()\n .finally()");

bt('{xxx;}()', '{\n xxx;\n}()');

bt("a = 'a'\nb = 'b'");
Expand Down Expand Up @@ -1729,7 +1732,7 @@ function run_beautifier_tests(test_obj, Urlencoded, js_beautify, html_beautify,
bth('<div>Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all.</div>',
/* expected */
'<div>Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all. Some text that should not wrap at all.</div>');

//BUGBUG: This should wrap before 40 not after.
opts.wrap_line_length = 40;
//...---------1---------2---------3---------4---------5---------6---------7
Expand Down
2 changes: 1 addition & 1 deletion python/jsbeautifier/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@ def handle_word(self, token_text):
else:
prefix = 'NEWLINE'

if token_text in ['else', 'catch', 'finally']:
if token_text == 'else' or (self.flags.last_text != '.' and token_text in ['else', 'catch', 'finally']):
if self.last_type != 'TK_END_BLOCK' \
or self.opts.brace_style == 'expand' \
or self.opts.brace_style == 'end-expand':
Expand Down
4 changes: 4 additions & 0 deletions python/jsbeautifier/tests/testjsbeautifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ def test_beautifier(self):
# a common snippet in jQuery plugins
bt("settings = $.extend({},defaults,settings);", "settings = $.extend({}, defaults, settings);");

# promises specific
bt("$http().then().finally()", "$http().then().finally()");
bt("$http()\n.then()\n.finally()", "$http()\n .then()\n .finally()");

bt('{xxx;}()', '{\n xxx;\n}()');

bt("a = 'a'\nb = 'b'");
Expand Down