Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js/src/javascript/beautifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ Beautifier.prototype.handle_end_block = function(current_token) {
this.restore_mode();
}

var empty_braces = this._flags.last_token.type === TOKEN.START_BLOCK;
var empty_braces = !current_token.comments_before && this._flags.last_token.type === TOKEN.START_BLOCK;

if (this._flags.inline_frame && !empty_braces) { // try inline_frame (only set if this._options.braces-preserve-inline) first
this._output.space_before_token = true;
Expand Down
5 changes: 4 additions & 1 deletion python/jsbeautifier/javascript/beautifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,10 @@ def handle_end_block(self, current_token):
while self._flags.mode == MODE.Statement:
self.restore_mode()

empty_braces = self._flags.last_token.type == TOKEN.START_BLOCK
empty_braces = (
current_token.comments_before is None
and self._flags.last_token.type == TOKEN.START_BLOCK
)

# try inline_frame (only set if opt.braces-preserve-inline) first
if self._flags.inline_frame and not empty_braces:
Expand Down
18 changes: 18 additions & 0 deletions test/data/javascript/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3006,6 +3006,24 @@ exports.test_data = {
'foo(o)'
]
},
{
comment: 'object literal containing only a block comment - closing brace on its own line',
input: 'var a = {/* c */}',
output: [
'var a = {',
' /* c */',
'}'
]
},
{
comment: 'block statement containing only a block comment - closing brace on its own line',
input: 'if (x) {/* c */}',
output: [
'if (x) {',
' /* c */',
'}'
]
},
{
comment: '#713 and #964',
unchanged: [
Expand Down