babel-plugin-transform-for-of-as-array
Transform all for-of loops into the equivalent array for loop
Example
In
const array = 1 2 3;for const elm of array console; let item;for item of array console;
Out
const array = 1 2 3; for let _i = 0 _length = arraylength; _i < _length; _i++ const elm = array_i; console; let item;for let _i2 = 0 _array$map = array _length2 = _array$maplength; _i2 < _length2; _i2++ item = _array$map_i2; console;
loose
transformation
In addition to the normal transform, we also support a null-ish checking loose
transform. Passing { loose: true }
option into the plugin enables it:
In
const array = null;for const elm of array console; let item;for item of array console;
Out
const array = null; for let _i = 0 _length = array == null ? 0 : arraylength; _i < _length; _i++ const elm = array_i; console; let item;for let _i2 = 0 _array$map = array _length2 = _array$map == null ? 0 : _array$maplength; _i2 < _length2; _i2++ item = _array$map_i2; console;
Installation
$ npm install babel-plugin-transform-for-of-as-array
Usage
.babelrc
(Recommended)
Via .babelrc
Via CLI
$ babel --plugins transform-for-of-as-array script.js
Via Node API
;