handle bitwise ~ operator

This commit is contained in:
Ansh Saini 2021-06-25 01:08:24 +05:30
parent 60228b35c4
commit e77f74b140
3 changed files with 11 additions and 3 deletions

View File

@ -1284,7 +1284,7 @@ Beautifier.prototype.handle_operator = function(current_token) {
// http://www.ecma-international.org/ecma-262/5.1/#sec-7.9.1
// if there is a newline between -- or ++ and anything else we should preserve it.
if (current_token.newlines && (current_token.text === '--' || current_token.text === '++')) {
if (current_token.newlines && (current_token.text === '--' || current_token.text === '++' || current_token.text === '~')) {
this.print_newline(false, true);
}

View File

@ -1439,7 +1439,9 @@ class Beautifier:
# if there is a newline between -- or ++ and anything else we
# should preserve it.
if current_token.newlines and (
current_token.text == "--" or current_token.text == "++"
current_token.text == "--"
or current_token.text == "++"
or current_token.text == "~"
):
self.print_newline(preserve_statement_flags=True)

View File

@ -5436,7 +5436,13 @@ exports.test_data = {
{ unchanged: 'if (1 + foo() && bar(baz()) / 2) one();\ntwo();\nthree();' },
{ input: 'var a=1,b={bang:2},c=3;', output: 'var a = 1,\n b = {\n bang: 2\n },\n c = 3;' },
{ input: 'var a={bing:1},b=2,c=3;', output: 'var a = {\n bing: 1\n },\n b = 2,\n c = 3;' }
{ input: 'var a={bing:1},b=2,c=3;', output: 'var a = {\n bing: 1\n },\n b = 2,\n c = 3;' },
{
comment: 'Issue #1896: Handle newlines with bitwise ~ operator',
input: 'if (foo) {\nvar bar = 1;\n~bar ? 0 : 1\n }',
output: 'if (foo) {\n var bar = 1;\n ~bar ? 0 : 1\n}'
}
]
}
],