All Projects → jridgewell → babel-plugin-transform-for-of-as-array

jridgewell / babel-plugin-transform-for-of-as-array

Licence: MIT license
Transform all for-of loops into the equivalent array for loop

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to babel-plugin-transform-for-of-as-array

android-gradle-plugin-transform-patch
android gradle plugin transform patch
Stars: ✭ 28 (+100%)
Mutual labels:  transform
egjs-jquery-transform
A method extended from the jQuery animate() method. It supports CSS transform property and 3D acceleration.
Stars: ✭ 18 (+28.57%)
Mutual labels:  transform
vesdk-android-demo
VideoEditor SDK: A fully customizable video editor for your app.
Stars: ✭ 90 (+542.86%)
Mutual labels:  transform
ts-sfc-plugin
A plugin for optimizing stateless component of React (tsx)
Stars: ✭ 29 (+107.14%)
Mutual labels:  transform
SelectTransform
This project is based upon https://github.com/SelectTransform/st.js but differs in implementation, functionality and robustness.
Stars: ✭ 17 (+21.43%)
Mutual labels:  transform
nornj
More exciting JS/JSX based on Template Engine, support control flow tags, custom directives, two-way binding, filters and custom operators.
Stars: ✭ 97 (+592.86%)
Mutual labels:  babel-plugin
Xwind
Tailwind CSS as a templating language in JS and CSS-in-JS
Stars: ✭ 249 (+1678.57%)
Mutual labels:  babel-plugin
jest-preset-coffeescript
🃏 Easily write your Jests in @coffeescript.
Stars: ✭ 18 (+28.57%)
Mutual labels:  transform
babel-plugin-rewire-exports
Babel plugin for stubbing [ES6, ES2015] module exports
Stars: ✭ 62 (+342.86%)
Mutual labels:  babel-plugin
ember-cli-es6-transform
Import ES6 modules from npm, bower or anywhere else in your app.
Stars: ✭ 13 (-7.14%)
Mutual labels:  transform
babel-plugin-tailwind-rn
Allows you to use className="w-full md:w-1/2" syntax in your react native projects.
Stars: ✭ 31 (+121.43%)
Mutual labels:  babel-plugin
AITools
AI 常用脚本
Stars: ✭ 35 (+150%)
Mutual labels:  transform
etran
Erlang Parse Transforms Including Fold (MapReduce) comprehension, Elixir-like Pipeline, and default function arguments
Stars: ✭ 19 (+35.71%)
Mutual labels:  transform
react-mops
🐶 Modify Orientation Position Size
Stars: ✭ 40 (+185.71%)
Mutual labels:  transform
penv.macro
A macro used with babel-plugin-macros to write configurations for multiple environments, and remove configurations are irrelevant with the specified environment from your codes finally.
Stars: ✭ 73 (+421.43%)
Mutual labels:  babel-plugin
S2s
Coding time Compile. A tool to write code fastest.
Stars: ✭ 254 (+1714.29%)
Mutual labels:  babel-plugin
babel-plugin-hyperscript-to-jsx
This plugin transforms react-hyperscript into JSX. Intended to be used as codemod.
Stars: ✭ 20 (+42.86%)
Mutual labels:  babel-plugin
idomizer
An HTML template parser compiling an incremental-dom render factory.
Stars: ✭ 15 (+7.14%)
Mutual labels:  babel-plugin
typescript-transform-jsx
Typescript transform jsx to string
Stars: ✭ 22 (+57.14%)
Mutual labels:  transform
data-point
JavaScript Utility for collecting, processing and transforming data
Stars: ✭ 67 (+378.57%)
Mutual labels:  transform

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.log(elm);
}

let item;
for ({ item } of array.map(item => ({ item }))) {
  console.log(item);
}

Out

const array = [1, 2, 3];

for (let _i = 0, _length = array.length; _i < _length; _i++) {
  const elm = array[_i];
  console.log(elm);
}

let item;
for (let _i2 = 0, _array$map = array.map(item => ({ item })), _length2 = _array$map.length; _i2 < _length2; _i2++) {
  ({ item } = _array$map[_i2]);

  console.log(item);
}

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.log(elm);
}

let item;
for ({ item } of array.map(item => ({ item }))) {
  console.log(item);
}

Out

const array = null;

for (let _i = 0, _length = array == null ? 0 : array.length; _i < _length; _i++) {
  const elm = array[_i];
  console.log(elm);
}

let item;
for (let _i2 = 0, _array$map = array.map(item => ({ item })), _length2 = _array$map == null ? 0 : _array$map.length; _i2 < _length2; _i2++) {
  ({ item } = _array$map[_i2]);

  console.log(item);
}

Installation

$ npm install babel-plugin-transform-for-of-as-array

Usage

Via .babelrc (Recommended)

.babelrc

{
  "plugins": ["transform-for-of-as-array"]
}

Via CLI

$ babel --plugins transform-for-of-as-array script.js

Via Node API

require("babel-core").transform("code", {
  plugins: ["transform-for-of-as-array"]
});
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].