Buble's spread will not work on array-like (i. e. iterable) objects
- Dominant language
- JavaScript
- Stars
- 874
- Forks
- 62
- PR merge metrics
- No merged PRs in 30d
Description
[Spreading a NodeList into an array works in vanilla JS](https://jsfiddle.net/yeL4x7v4/). The following example will log an _array_ containing text, p, text, p, text.
```html
Hello, World!
Lorem Ipsum
```
```js
console.log([...document.querySelector('div').childNodes])
```
However, because Buble uses `array.concat` for spread, [it will fail on _array-like_ objects](https://buble.surge.sh/#const%20foo%20%3D%20%5B...someElement.childNodes%5D) because concat will only "spread" arrays. Anything else, it just appends to the target array as is.
Input:
```js
const foo = [...someElement.childNodes] // Expected [node, node, node, ...]
```
Output:
```js
var foo = [].concat(someElement.childNodes) // Actual [NodeList{}]
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the linked vanilla-JS example and Buble reproduction, then trace the spread transformation that produces [].concat(someElement.childNodes). Done means array-like iterable values are expanded into individual elements, with a regression test covering the NodeList case and the expected array output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100