mirror of
https://github.com/beautifier/js-beautify.git
synced 2024-11-27 22:50:26 +00:00
Merge pull request #1574 from bitwiseman/object-async
Fix object literal async indenting
This commit is contained in:
commit
74cb7c407c
@ -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));
|
||||
|
@ -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' +
|
||||
'}');
|
||||
|
||||
|
||||
//============================================================
|
||||
|
@ -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:
|
||||
|
@ -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' +
|
||||
'}')
|
||||
|
||||
|
||||
#============================================================
|
||||
|
@ -991,6 +991,18 @@ exports.test_data = {
|
||||
' e = (await foo()),',
|
||||
' f = 4;'
|
||||
]
|
||||
},
|
||||
{
|
||||
unchanged: [
|
||||
'a = {',
|
||||
' myVar: async function() {',
|
||||
' return a;',
|
||||
' },',
|
||||
' myOtherVar: async function() {',
|
||||
' yield b;',
|
||||
' }',
|
||||
'}'
|
||||
]
|
||||
}
|
||||
]
|
||||
}, {
|
||||
|
Loading…
Reference in New Issue
Block a user