Skip to content

object-rest-spread gets property ordering wrong when spreading rest inside nested object #5629

@msmesnik

Description

@msmesnik

Choose one: is this a bug report or feature request?

Bug

Input Code

https://github.com/daerion/babel-rest-spread-bug

const defunct = {
  outer: {
    inner: {
      three: 'three',
      four: 'four'
    }
  }
}

const { outer: { inner: { three, ...other } } } = defunct

Babel Configuration (.babelrc, package.json, cli command)

{
  "plugins": [
    [ "transform-object-rest-spread" ]
  ]
}

Expected Behavior

Using the above example, two constants should be assigned:

console.log('three: %s', three) // 'three'
console.dir(other) // { four: 'four' }

Or, more explicitly, other should be an object containing all values from defunct.outer.inner except for three.

Current Behavior

Transpiling the above code results in the following (declarations omitted for brevity, see repository linked above for full source):

const { outer: { inner: { three } } } = defunct,
      other = _objectWithoutProperties(defunct.inner.outer, ['three']);

I.e. instead of constructing other from defunct.outer.inner, babel will attempt to use defunct.inner.outer, which is undefined. This happens also when nesting objects even further (again, see linked repo).

Your Environment

software version(s)
Babel 6.24.1
transform-object-rest-spread 6.23.0
node 7.9.0 and 6.10.2
npm 4.2.0 and 3.10.10
Operating System Ubuntu 16.10

Metadata

Metadata

Assignees

No one assigned

    Labels

    Has PRSpec: Object Rest/SpreadoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions