mathiasbynens / Array.from

A robust & optimized ES3-compatible polyfill for the `Array.from` method in ECMAScript 6.

Home Page:https://mths.be/array-from

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Doesn't support FileList

Wildhoney opened this issue · comments

import arrayFrom from 'array.from';
arrayFrom(FileList) instanceof Array; // false
Array.from(FileList) instanceof Array; // true

I tried to implement it, but adding a switch for FileList increases the cyclomatic complexity of the from function beyond 12. There's also no easy way of mocking FileList for the tests, as your tests don't have jsdom integrated, and I'm quite sure jsdom doesn't support FileList anyway.

We could use something like Karma, but adding that just for a FileList test seems a little overkill.

Ideas?

This is a spec-compliant method - is FileList array like, or does it have Symbol.iterator? If not, it's not supposed to work with Array.from.

Hmm - #4 is for iterator support, but since it's array-like, it should just work already. (Note that Array.isArray() is the proper way to check if something's an array, never instanceof).

In your original post, is FileList the actual list of files, or is it the constructor for the list of files?

Could you create a jsfiddle (using https://wzrd.in/standalone/array.from@latest if that helps) that reproduces the failure?

Done.

It's peculiar, because the native Array.from yields an array of File objects – whereas the polyfill implementation simply wraps FileList in an array.

Hopefully #27 can help with this issue?

FileLists are arraylike, and don't necessarily have Symbol.iterator, so this is a separate issue.

@Wildhoney thank you - I've found the bug. The tests were being run on everything except the single binding at the main entry point - and that's where it was.

Fix incoming shortly.

Released as v1.0.2