Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix - semicolon followed by block statement doesnt have new line #2117

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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 @@ -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