Skip to content

Commit

Permalink
Resolve beautifier#806: Preserve newline on arrow functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
timothyeburke authored and olsonpm committed Dec 13, 2015
1 parent 4a3713a commit 6bf6c0e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
8 changes: 8 additions & 0 deletions js/lib/beautify.js
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,14 @@
}
}

// Support preserving wrapped arrow function expressions
// a.b('c',
// () => d.e
// )
if (current_token.text === '(' && current_token.type === 'TK_START_EXPR' && ['TK_WORD', 'TK_RESERVED'].indexOf(last_type) === -1) {
allow_wrap_or_preserved_newline();
}

set_mode(next_mode);
print_token();
if (opt.space_in_paren) {
Expand Down
6 changes: 6 additions & 0 deletions js/test/beautify-javascript-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2499,6 +2499,12 @@ function run_javascript_tests(test_obj, Urlencoded, js_beautify, html_beautify,
' phantom.onError = function() {};\n' +
'}\n' +
'// Comment');

// Issue 806 - newline arrow functions
bt(
'a.b("c",\n' +
' () => d.e\n' +
')');



Expand Down
6 changes: 6 additions & 0 deletions python/jsbeautifier/tests/testjsbeautifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -2255,6 +2255,12 @@ def unicode_char(value):
' phantom.onError = function() {};\n' +
'}\n' +
'// Comment')

# Issue 806 - newline arrow functions
bt(
'a.b("c",\n' +
' () => d.e\n' +
')')

# Old tests
bt('')
Expand Down
9 changes: 8 additions & 1 deletion test/data/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -1984,7 +1984,14 @@ exports.test_data = {
'}',
'// Comment' ]
},

{
comment: "Issue 806 - newline arrow functions",
unchanged: [
'a.b("c",',
' () => d.e',
')'
]
},
]
},

Expand Down

0 comments on commit 6bf6c0e

Please sign in to comment.