bublejs / buble

https://buble.surge.sh
MIT License
871 stars 67 forks source link

Array spreading is still not working correctly #127

Closed ClassicOldSong closed 6 years ago

ClassicOldSong commented 6 years ago

Previous issue: https://gitlab.com/Rich-Harris/buble/issues/192

Expected: image

Actually happening: image

Live example

leeoniya commented 6 years ago

codemirror also uses array transposition which Buble does not handle:

[from, to] = [to, from] [1]

EDIT: sorry, don't mean to hijack.

[1] https://github.com/codemirror/CodeMirror/blob/15d9d4e201bc857af591a14258806bb236da3320/src/model/changes.js#L266

pandaGao commented 6 years ago

Same Here. For example:

class A {
  constructor () {
    this.a = [1,2]
    this.funcA()
  }

  funcA () {
    console.log('Ops!')
    this.a.splice(0, 0, ...this.a)
  }
}
let a = new A()

will transform to

var A = function A () {
  this.a = [1,2]
  this.funcA()
};

A.prototype.funcA = function funcA () {
  var ref;

  console.log('Ops!')
  (ref = this.a).splice.apply(ref, [ 0, 0 ].concat( this.a ))
};
var a = new A()

[Example](https://buble.surge.sh/#class%20A%20%7B%0A%20%20constructor%20()%20%7B%0A%09this.a%20%3D%20%5B1%2C2%5D%0A%09this.funcA()%0A%20%20%7D%0A%20%20%0A%20%20funcA%20()%20%7B%0A%09console.log('Ops!')%0A%09this.a.splice(0%2C%200%2C%20...this.a)%0A%20%20%7D%0A%7D%0Alet%20a%20%3D%20new%20A())

This will lead to an error console.log(...) is not a function which is not expected.

fskreuz commented 6 years ago

Duplicate of https://github.com/Rich-Harris/buble/issues/87