Skip to content

Commit

Permalink
Merge branch 'master' into js-default-options
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwiseman authored Oct 17, 2018
2 parents df1ca96 + 74cb7c4 commit 7ed4a77
Show file tree
Hide file tree
Showing 5 changed files with 33 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 @@ -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));
Expand Down
9 changes: 9 additions & 0 deletions js/test/generated/beautify-javascript-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' +
'}');


//============================================================
Expand Down
3 changes: 2 additions & 1 deletion python/jsbeautifier/javascript/beautifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ def start_of_statement(self, current_token):
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 (
Expand Down Expand Up @@ -711,7 +712,7 @@ def handle_word(self, current_token):
'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:
Expand Down
9 changes: 9 additions & 0 deletions python/jsbeautifier/tests/generated/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2019,6 +2019,15 @@ def unicode_char(value):
' 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' +
'}')


#============================================================
Expand Down
12 changes: 12 additions & 0 deletions test/data/javascript/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,18 @@ exports.test_data = {
' e = (await foo()),',
' f = 4;'
]
},
{
unchanged: [
'a = {',
' myVar: async function() {',
' return a;',
' },',
' myOtherVar: async function() {',
' yield b;',
' }',
'}'
]
}
]
}, {
Expand Down

0 comments on commit 7ed4a77

Please sign in to comment.