https://github.com/sapphi-red/ts-transformer-for-of
A TypeScript custom transformer to transform `for-of` and array methods to a normal `for` loop.
https://github.com/sapphi-red/ts-transformer-for-of
Last synced: about 1 month ago
JSON representation
A TypeScript custom transformer to transform `for-of` and array methods to a normal `for` loop.
- Host: GitHub
- URL: https://github.com/sapphi-red/ts-transformer-for-of
- Owner: sapphi-red
- License: mit
- Created: 2020-03-16T08:40:14.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2022-12-30T19:52:53.000Z (over 2 years ago)
- Last Synced: 2025-03-29T05:41:24.414Z (about 2 months ago)
- Language: TypeScript
- Homepage:
- Size: 122 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ts-transformer-for-of
A TypeScript custom transformer to transform `for-of` and array methods like `filter`, `map`, `forEach` to a normal `for` loop.This transformation results in a higher performance. See [here](https://github.com/aminya/typescript-optimization) for benchmarks.
```shell
npm install --save-dev @sapphi-red/ts-transformer-for-of
```# How to use the custom transformer
### ttypescript
Install ttypescript and use `ttsc` like how you use `tsc`
```shell
npm install --save-dev ttypescript
```In tsconfig.json:
```jsonc
{
"compilerOptions": {
// ...
"plugins": [
{
"transform": "@sapphi-red/ts-transformer-for-of",
"cacheLength": false // cache the length of the array in `for-of` transformations. Defaults to false.,
"exclusions": [] // exclude the transformations. The values of the array can be among: 'Array-for-of', 'Array-forEach', 'Array-map', 'Array-filter'
}
]
},
// ...
}
```See [ttypescript's README](https://github.com/cevek/ttypescript/blob/master/README.md) for how to use this with module bundlers such as webpack or Rollup.
### other methods
See [kimamula/ts-transformer-keys](https://github.com/kimamula/ts-transformer-keys/blob/master/README.md#how-to-use-the-custom-transformer) for other methods.# Caveats
## Sparse arrays are not supported
Using this transformer with Sparse arrays, arrays with unfilled slots, may lead to unintended behavior.
Before transforming the code, Array iteration methods will skip unfilled slots, but after transforming the code it will work as if it is filled with `undefined`.# License
MIT
Some code are from [kimamula/ts-transformer-keys](https://github.com/kimamula/ts-transformer-keys/blob/master/README.md#how-to-use-the-custom-transformer).
Copyright (c) 2017 Kenji Imamula
[kimamula/ts-transformer-keys:/LICENSE](https://github.com/kimamula/ts-transformer-keys/blob/master/LICENSE)