babel-plugin-transform-array-push
Simple transform arr.push(a)
to arr[arr.length] = a
, just follow loverajoel/jstips#00 - Adding an element at the end.
const arr = 1 2 3arr const arrLength = arr;
into
const arr = 1 2 3;arrarrlength = 4; const arrLength = arrarrlength = 5 arrlength;
Limitation
- Only for
ArrayExpression
, and it's known, no re-assign other type
// Will transformlet arr = 1 2 3arr // Will transformlet arr = 1 2 3arr = 1 2 3 4arr4 // Will not transformlet arr = 1 2 3arr = push: 1 arr
- Not transform multi-arg of
array.push
// Will not transformlet arr = 1 2 3arr
Installation
npm i --save-dev babel-plugin-transform-array-push
Usage
.babelrc
(recommended)
Via .babelrc
Via CLI
babel scriptjs --plugins transform-array-push
Via Node API