🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

babel-plugin-transform-array-push

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-transform-array-push

Simple transform `arr.push(a)` to `arr[arr.length] = a`, just follow loverajoel/jstips#00

latest
Source
npmnpm
Version
0.1.2
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

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, 3]
arr.push(4)

const arrLength = arr.push(5);

into

const arr = [1, 2, 3];
arr[arr.length] = 4;

const arrLength = (arr[arr.length] = 5, arr.length);

Limitation

  • Only for ArrayExpression, and it's known, no re-assign other type
// Will transform
let arr = [1, 2, 3]
arr.push(4)

// Will transform
let arr = [1, 2, 3]
arr = [1, 2, 3, 4]
arr4.push(5)

// Will not transform
let arr = [1, 2, 3]
arr = { push: 1 }
arr.push(4)
  • Not transform multi-arg of array.push
// Will not transform
let arr = [1, 2, 3]
arr.push(4, 5, 6)

Installation

npm i --save-dev babel-plugin-transform-array-push

Usage

.babelrc

{
  "plugins": ["transform-array-push"]
}

Via CLI

babel script.js --plugins transform-array-push

Via Node API

require('babel-core').transform('code', {
  plugins: ['transform-array-push'],
})

License

MIT

Keywords

babel

FAQs

Package last updated on 08 May 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts