beautifier/js-beautify

Beautification failing for code with Bitwise Not operator(~)

Open

#1 896 ouverte le 12 mars 2021

Voir sur GitHub
 (5 commentaires) (0 réactions) (0 assignés)JavaScript (1 460 forks)batch import
good first issuelanguage: ecma-2015type: enhancement

Métriques du dépôt

Stars
 (8 342 stars)
Métriques de merge PR
 (Merge moyen 51j 1h) (16 PRs mergées en 30 j)

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
}

Guide contributeur