beautifier/js-beautify
View on GitHubBeautification failing for code with Bitwise Not operator(~)
Open
#1896 opened on Mar 12, 2021
good first issuelanguage: ecma-2015type: enhancement
Description
Description
Beautification failing for code with Bitwise Not operator(~)
Input
The code looked like this before beautification:
if (stack.length > 0) {
var thisPos = stack.indexOf(this)
~thisPos ? stack.splice(thisPos + 1) : stack.push(this)
~thisPos ? keys.splice(thisPos, Infinity, key) : keys.push(key)
if (~stack.indexOf(value)) "value" = cycleReplacer.call(this, key, value)
}
Expected Output
The code should have looked like this after beautification:
if (stack.length > 0) {
var thisPos = stack.indexOf(this)
~thisPos ? stack.splice(thisPos + 1) : stack.push(this)
~thisPos ? keys.splice(thisPos, Infinity, key) : keys.push(key)
if (~stack.indexOf(value)) "value" = cycleReplacer.call(this, key, value)
}
Actual Output
The code actually looked like this after beautification:
if (stack.length > 0) {
var thisPos = stack.indexOf(this) ~thisPos ? stack.splice(thisPos + 1) : stack.push(this) ~thisPos ? keys.splice(thisPos, Infinity, key) : keys.push(key)
if (~stack.indexOf(value)) "value" = cycleReplacer.call(this, key, value)
}
Steps to Reproduce
Environment
OS: Ubuntu 20.04.2 LTS
Settings
Example:
{
"indent_size": 2,
"preserve_newlines": true
}