Skip to content

Commit

Permalink
Merge pull request #2117 from mhnaeem/bug/block-statement-after-semic…
Browse files Browse the repository at this point in the history
…olon

fix - semicolon followed by block statement doesnt have new line
  • Loading branch information
bitwiseman authored Nov 24, 2022
2 parents 49cd14d + c904700 commit ca52d26
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion js/src/javascript/beautifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ Beautifier.prototype.handle_start_block = function(current_token) {
}
}
if (this._flags.last_token.type !== TOKEN.OPERATOR && this._flags.last_token.type !== TOKEN.START_EXPR) {
if (this._flags.last_token.type === TOKEN.START_BLOCK && !this._flags.inline_frame) {
if (in_array(this._flags.last_token.type, [TOKEN.START_BLOCK, TOKEN.SEMICOLON]) && !this._flags.inline_frame) {
this.print_newline();
} else {
this._output.space_before_token = true;
Expand Down
2 changes: 1 addition & 1 deletion python/jsbeautifier/javascript/beautifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ def handle_start_block(self, current_token):

elif self._flags.last_token.type not in [TOKEN.OPERATOR, TOKEN.START_EXPR]:
if (
self._flags.last_token.type == TOKEN.START_BLOCK
self._flags.last_token.type in [TOKEN.START_BLOCK, TOKEN.SEMICOLON]
and not self._flags.inline_frame
):
self.print_newline()
Expand Down
2 changes: 1 addition & 1 deletion test/data/javascript/node.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ function run_javascript_tests(test_obj, Urlencoded, js_beautify, html_beautify,
'if (foo)' + eo + '{}' + ec + 'else /regex/.test();');
test_fragment('if (foo)' + to + '{', 'if (foo)' + eo + '{');
test_fragment('foo' + to + '{', 'foo' + eo + '{');
test_fragment('return;' + to + '{', 'return;' + eo + '{');
test_fragment('return;' + to + '{', 'return;\n{');
bt( 'function x()' + to + '{\n foo();\n}zzz', 'function x()' + eo +'{\n foo();\n}\nzzz');
bt( 'var a = new function a()' + to + '{};', 'var a = new function a()' + eo + '{};');
bt( 'var a = new function a()' + to + ' {},\n b = new function b()' + to + ' {};',
Expand Down
27 changes: 27 additions & 0 deletions test/data/javascript/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3367,6 +3367,33 @@ exports.test_data = {
' });',
'var test = 1;'
]
}, {
comment: "Issue #1852 - semicolon followed by block statement",
unchanged: [
'(function() {',
' some_code_here();',
' {',
' /* IE11 let bug bypass */',
' let index;',
' for (index in a) {',
' a[index];',
' }',
' }',
'})();'
]
}, {
comment: "Issue #1852 - semicolon followed by block statement 2",
input: [
'let x = { A: 1 }; { console.log("hello"); }'
],
output: [
'let x = {',
' A: 1',
'};',
'{',
' console.log("hello");',
'}'
]
}, {
comment: "Issue #772",
input: [
Expand Down

0 comments on commit ca52d26

Please sign in to comment.