2.1.5
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("*"))')
Windows 7
I am using Karma, which acutally needs phantomjs-prebuilt. So I am not using phantomjs directly.
@ariya
ES6 features are not supported in PhantomJS yet.
@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...
Can be tracked here https://phabricator.babeljs.io/T7305
In the mean time, please track ES6 support in #14506. Thank you!
Most helpful comment
@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
to convert a
NodeList
to anarray
, the following (includingArray.from()
) will be generated, even when using the es2015 preset: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...