bublejs / buble

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

Buble's spread will not work on array-like (i. e. iterable) objects #131

Open fskreuz opened 6 years ago

fskreuz commented 6 years ago

Spreading a NodeList into an array works in vanilla JS. The following example will log an array containing text, p, text, p, text.

<div>
  <p>Hello, World!</p>
  <p>Lorem Ipsum</p>
</div>
console.log([...document.querySelector('div').childNodes])

However, because Buble uses array.concat for spread, it will fail on array-like objects because concat will only "spread" arrays. Anything else, it just appends to the target array as is.

Input:

const foo = [...someElement.childNodes] // Expected [node, node, node, ...]

Output:

var foo = [].concat(someElement.childNodes) // Actual [NodeList{}]
adrianheine commented 5 years ago

We discussed some solutions in #81. Destructuring and for-of loops have closely related issues.