diff --git a/js/lib/beautify.js b/js/lib/beautify.js index 75c40e8fc..495249d77 100644 --- a/js/lib/beautify.js +++ b/js/lib/beautify.js @@ -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) { diff --git a/js/test/beautify-javascript-tests.js b/js/test/beautify-javascript-tests.js index c1d22f74b..759802be3 100644 --- a/js/test/beautify-javascript-tests.js +++ b/js/test/beautify-javascript-tests.js @@ -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' + + ')'); diff --git a/python/jsbeautifier/tests/testjsbeautifier.py b/python/jsbeautifier/tests/testjsbeautifier.py index 21faf0b79..abc3c6d35 100644 --- a/python/jsbeautifier/tests/testjsbeautifier.py +++ b/python/jsbeautifier/tests/testjsbeautifier.py @@ -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('') diff --git a/test/data/javascript.js b/test/data/javascript.js index c65884505..c554b3c5e 100644 --- a/test/data/javascript.js +++ b/test/data/javascript.js @@ -1984,7 +1984,14 @@ exports.test_data = { '}', '// Comment' ] }, - + { + comment: "Issue 806 - newline arrow functions", + unchanged: [ + 'a.b("c",', + ' () => d.e', + ')' + ] + }, ] },