Skip to content

Commit

Permalink
Fixed await indenting
Browse files Browse the repository at this point in the history
Fixes #1519
Fixes #1517
  • Loading branch information
bitwiseman committed Aug 30, 2018
1 parent e333ae5 commit 75f38d9
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 2 deletions.
2 changes: 1 addition & 1 deletion js/src/javascript/beautifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ Beautifier.prototype.handle_whitespace_and_comments = function(current_token, pr

};

var newline_restricted_tokens = ['async', 'await', 'break', 'continue', 'return', 'throw', 'yield'];
var newline_restricted_tokens = ['async', 'break', 'continue', 'return', 'throw', 'yield'];

Beautifier.prototype.allow_wrap_or_preserved_newline = function(current_token, force_linewrap) {
force_linewrap = (force_linewrap === undefined) ? false : force_linewrap;
Expand Down
15 changes: 15 additions & 0 deletions js/test/generated/beautify-javascript-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2073,6 +2073,21 @@ function run_javascript_tests(test_obj, Urlencoded, js_beautify, html_beautify,
'}');
bt('async () => 5;');
bt('async x => x * 2;');
bt(
'async function() {\n' +
' const obj = {\n' +
' a: 1,\n' +
' b: await fn(),\n' +
' c: 2\n' +
' };\n' +
'}');
bt(
'const a = 1,\n' +
' b = a ? await foo() : b,\n' +
' c = await foo(),\n' +
' d = 3,\n' +
' e = (await foo()),\n' +
' f = 4;');


//============================================================
Expand Down
1 change: 0 additions & 1 deletion python/jsbeautifier/javascript/beautifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ def is_expression(self, mode):

_newline_restricted_tokens = frozenset([
'async',
'await',
'break',
'continue',
'return',
Expand Down
15 changes: 15 additions & 0 deletions python/jsbeautifier/tests/generated/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1849,6 +1849,21 @@ def unicode_char(value):
'}')
bt('async () => 5;')
bt('async x => x * 2;')
bt(
'async function() {\n' +
' const obj = {\n' +
' a: 1,\n' +
' b: await fn(),\n' +
' c: 2\n' +
' };\n' +
'}')
bt(
'const a = 1,\n' +
' b = a ? await foo() : b,\n' +
' c = await foo(),\n' +
' d = 3,\n' +
' e = (await foo()),\n' +
' f = 4;')


#============================================================
Expand Down
21 changes: 21 additions & 0 deletions test/data/javascript/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,27 @@ exports.test_data = {
},
{
unchanged: "async x => x * 2;"
},
{
unchanged: [
'async function() {',
' const obj = {',
' a: 1,',
' b: await fn(),',
' c: 2',
' };',
'}'
]
},
{
unchanged: [
'const a = 1,',
' b = a ? await foo() : b,',
' c = await foo(),',
' d = 3,',
' e = (await foo()),',
' f = 4;'
]
}
]
}, {
Expand Down

0 comments on commit 75f38d9

Please sign in to comment.