Skip to content

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

@ghost

Description

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{}]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions