diff --git a/js/lib/beautify.js b/js/lib/beautify.js
index 6d363e1b8..901add3e7 100644
--- a/js/lib/beautify.js
+++ b/js/lib/beautify.js
@@ -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 {
diff --git a/js/test/beautify-tests.js b/js/test/beautify-tests.js
index 7292b8393..9156dbcff 100755
--- a/js/test/beautify-tests.js
+++ b/js/test/beautify-tests.js
@@ -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');
@@ -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'");
@@ -1729,7 +1732,7 @@ function run_beautifier_tests(test_obj, Urlencoded, js_beautify, html_beautify,
bth('
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.
',
/* expected */
'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.
');
-
+
//BUGBUG: This should wrap before 40 not after.
opts.wrap_line_length = 40;
//...---------1---------2---------3---------4---------5---------6---------7
diff --git a/python/jsbeautifier/__init__.py b/python/jsbeautifier/__init__.py
index 4837a904f..2fb514ecd 100644
--- a/python/jsbeautifier/__init__.py
+++ b/python/jsbeautifier/__init__.py
@@ -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':
diff --git a/python/jsbeautifier/tests/testjsbeautifier.py b/python/jsbeautifier/tests/testjsbeautifier.py
index 6da9f7d4f..a50adea9c 100644
--- a/python/jsbeautifier/tests/testjsbeautifier.py
+++ b/python/jsbeautifier/tests/testjsbeautifier.py
@@ -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'");