sort-js-object-keys icon indicating copy to clipboard operation
sort-js-object-keys copied to clipboard

[BUG] Spreads are improperly sorted

Open jesuscc1993 opened this issue 4 years ago • 0 comments

Description

Sorting an object with spreads results in fields in the wrong order, altering the result.

Given these objects:

const objA = {
  h: 1080,
  w: 1600
}

const objB = {
  ...objA,
  w: 1920
}

sorting objB with the extension results in

const objB = {
  w: 1920,
  ...objA
}

which is incorrect, as the new fields are no longer overwriting those in the spread object.

Expected result

const objB = {
  ...objA,
  w: 1920
}

objB === { h: 1080, w: 1920 }

Actual result

const objB = {
  w: 1920,
  ...objA
}

objB === { h: 1080, w: 1600 }

Environment

macOS Big Sur 11.6 (20G165) VSC 1.62.0

jesuscc1993 avatar Nov 05 '21 10:11 jesuscc1993