diff --git a/js/src/javascript/beautifier.js b/js/src/javascript/beautifier.js index d2a2111b..94aaf83d 100644 --- a/js/src/javascript/beautifier.js +++ b/js/src/javascript/beautifier.js @@ -473,7 +473,7 @@ Beautifier.prototype.start_of_statement = function(current_token) { var start = false; start = start || reserved_array(this._flags.last_token, ['var', 'let', 'const']) && current_token.type === TOKEN.WORD; start = start || reserved_word(this._flags.last_token, 'do'); - start = start || (reserved_array(this._flags.last_token, newline_restricted_tokens) && !current_token.newlines); + start = start || (!(this._flags.parent.mode === MODE.ObjectLiteral && this._flags.mode === MODE.Statement)) && reserved_array(this._flags.last_token, newline_restricted_tokens) && !current_token.newlines; start = start || reserved_word(this._flags.last_token, 'else') && !(reserved_word(current_token, 'if') && !current_token.comments_before); start = start || (this._flags.last_token.type === TOKEN.END_EXPR && (this._previous_flags.mode === MODE.ForInitializer || this._previous_flags.mode === MODE.Conditional)); diff --git a/js/test/generated/beautify-javascript-tests.js b/js/test/generated/beautify-javascript-tests.js index 70e6d396..bf50159a 100644 --- a/js/test/generated/beautify-javascript-tests.js +++ b/js/test/generated/beautify-javascript-tests.js @@ -2249,6 +2249,15 @@ function run_javascript_tests(test_obj, Urlencoded, js_beautify, html_beautify, ' d = 3,\n' + ' e = (await foo()),\n' + ' f = 4;'); + bt( + 'a = {\n' + + ' myVar: async function() {\n' + + ' return a;\n' + + ' },\n' + + ' myOtherVar: async function() {\n' + + ' yield b;\n' + + ' }\n' + + '}'); //============================================================ diff --git a/python/jsbeautifier/javascript/beautifier.py b/python/jsbeautifier/javascript/beautifier.py index 4813793f..6750b737 100644 --- a/python/jsbeautifier/javascript/beautifier.py +++ b/python/jsbeautifier/javascript/beautifier.py @@ -398,6 +398,7 @@ class Beautifier: current_token.type == TOKEN.WORD) start = start or reserved_word(self._flags.last_token, 'do') start = start or ( + not (self._flags.parent.mode == MODE.ObjectLiteral and self._flags.mode == MODE.Statement) and reserved_array(self._flags.last_token, self._newline_restricted_tokens) and not current_token.newlines) start = start or ( @@ -711,7 +712,7 @@ class Beautifier: 'set', 'get'] and self._flags.mode != MODE.ObjectLiteral: current_token.type = TOKEN.WORD elif current_token.text == 'import' and self._tokens.peek().text == '(': - current_token.type = TOKEN.WORD + current_token.type = TOKEN.WORD elif current_token.text in ['as', 'from'] and not self._flags.import_block: current_token.type = TOKEN.WORD elif self._flags.mode == MODE.ObjectLiteral: diff --git a/python/jsbeautifier/tests/generated/tests.py b/python/jsbeautifier/tests/generated/tests.py index 840a94d3..5d7534f2 100644 --- a/python/jsbeautifier/tests/generated/tests.py +++ b/python/jsbeautifier/tests/generated/tests.py @@ -2019,6 +2019,15 @@ class TestJSBeautifier(unittest.TestCase): ' d = 3,\n' + ' e = (await foo()),\n' + ' f = 4;') + bt( + 'a = {\n' + + ' myVar: async function() {\n' + + ' return a;\n' + + ' },\n' + + ' myOtherVar: async function() {\n' + + ' yield b;\n' + + ' }\n' + + '}') #============================================================ diff --git a/test/data/javascript/tests.js b/test/data/javascript/tests.js index 67fe30e8..0518f46b 100644 --- a/test/data/javascript/tests.js +++ b/test/data/javascript/tests.js @@ -991,6 +991,18 @@ exports.test_data = { ' e = (await foo()),', ' f = 4;' ] + }, + { + unchanged: [ + 'a = {', + ' myVar: async function() {', + ' return a;', + ' },', + ' myOtherVar: async function() {', + ' yield b;', + ' }', + '}' + ] } ] }, {