Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

Array.from() with NodeList causes TypeError #14216

Closed
julkue opened this issue Apr 20, 2016 · 5 comments
Closed

Array.from() with NodeList causes TypeError #14216

julkue opened this issue Apr 20, 2016 · 5 comments

Comments

@julkue
Copy link

julkue commented Apr 20, 2016

1. Which version of PhantomJS are you using?

2.1.5

2. What steps will reproduce the problem?

In a Babel generated code I have something like that:

Array.from(document.querySelectorAll("*"));

document.querySelectorAll("*") returns a NodeList. PhantomJS will fail with this code.

TypeError: undefined is not a constructor (evaluating 'Array.from(document.querySelectorAll("*"))')

3. Which operating system are you using?

Windows 7

4. Did you use binary PhantomJS or did you compile it from source?

I am using Karma, which acutally needs phantomjs-prebuilt. So I am not using phantomjs directly.

@julkue
Copy link
Author

julkue commented Apr 21, 2016

@ariya

@vitallium
Copy link
Collaborator

ES6 features are not supported in PhantomJS yet.

@julkue
Copy link
Author

julkue commented Apr 21, 2016

@vitallium Thank you for your answer!

This is quite funny, because as I already said, this is a part of a Babel generated code.
When using

var arr = [...theNodeList];

to convert a NodeList to an array, the following (including Array.from()) will be generated, even when using the es2015 preset:

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }

var arr = _toConsumableArray(theNodeList);

I have taken this way of conversion from the docs.

So, as you already mentioned that Array.from() is part of ES6, it is funny that Babel generates a ES6 code to workaround ES6. I will open an issue for that...

@julkue
Copy link
Author

julkue commented Apr 21, 2016

Can be tracked here https://phabricator.babeljs.io/T7305

@ariya
Copy link
Owner

ariya commented Aug 25, 2016

In the mean time, please track ES6 support in #14506. Thank you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants