Transforms ES6 Array Comprehensions to ES5 compliant equivalent.
var squared = for x of 12345 if x > 2 x * x ;
var ;var ;varvar $__result = ;for var $__0 = $__getIterator12345 $__1; !$__1 = $__0nextdone;var x = $__1value;if x > 2$__resultpushx * x;return $__result;bindthis;
I'm glad to inform you that es6-comprehensions is now a part of es-next project.
For more information check out the current draft for ECMAScript 6.
Please notice that the syntax has changed and many resources is still using the old one.
$ npm install es6-comprehensions [--save]
Array comprehensions progressed to the Draft ECMAScript 6 Specification. It doesn't mean that there will be no changes or that array comprehensions will be included in the final ES6 Specification.
ES6 defines also iterators that can be used together with for-of loops that can be used in array comprehensions. This translator does not support iterators in
for-of loops. It translates
for-of loops to plain
for loops. Thus, it supports only plain JS arrays.
forEachmethod. It will result in more compact code,
Pull requests are highly appreciated.
for...ofloop. (Thanks @vslinko for PR.) Important! Generated code contains two more necessary functions.
thisin an array comprehension. An example can be found in a test file. (Thanks @vslinko for PR.)