New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-transform-isnil

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-transform-isnil - npm Package Compare versions

Comparing version 0.0.8 to 1.0.0

yarn.lock

25

package.json
{
"name": "babel-plugin-transform-isnil",
"version": "0.0.8",
"version": "1.0.0",
"description": "replace the comparing of null or undefined with isNil",
"main": "lib",
"main": "src",
"scripts": {
"compile": "babel -V && babel src --out-dir lib",
"pretest": "npm run compile & npm run lint",
"pretest": "npm run lint",
"test": "ava",
"lint": "xo --ignore lib/*.js",
"fix": "xo --ignore lib/*.js --fix"
"lint": "xo",
"fix": "xo --fix"
},

@@ -31,16 +30,6 @@ "repository": {

"devDependencies": {
"ava": "^0.14.0",
"ava-spec": "^1.0.1",
"babel-cli": "^6.11.4",
"ava": "^0.22.0",
"babel-core": "^6.13.2",
"babel-preset-es2015": "^6.13.2",
"babel-register": "^6.11.6",
"flat": "^2.0.1",
"lodash.get": "^4.4.1",
"xo": "^0.15.0"
},
"dependencies": {
"flat": "^2.0.0",
"lodash.get": "^4.2.1"
"xo": "^0.18.2"
}
}

@@ -111,24 +111,2 @@ # babel-plugin-transform-isNil

## TODO
I can't think of implementation method. :cry:
May possibly to stop the support of the fuunction. :persevere:
**In**
```js
if (hoge().poge(hoge).isNil) {
console.log('hoge.poge and foo.bar is null or undefined');
}
```
**Out**
```js
if (hoge().poge(hoge) === null || hoge().poge(hoge) === undefined) {
console.log('hoge.poge and foo.bar is null or undefined');
}
```
## Usage

@@ -148,4 +126,3 @@

* Node v6.2.0
* npm v3.7.2
* Node v4 or above

@@ -160,4 +137,8 @@ ```bash

Special Thanks
---
- [@shnhrrsn](https://github.com/shnhrrsn)
LICENSE
---
[MIT](./LICENSE.txt)

@@ -1,6 +0,6 @@

import flatten from 'flat'
import _get from 'lodash.get'
import template from 'babel-template'
import * as t from 'babel-types'
'use strict'
const template = require('babel-template')
const t = require('babel-types')
const isNilWrapper = template('(function (val) { return val === null || typeof val === \'undefined\' })')

@@ -48,54 +48,18 @@

export default function () {
function plugin() {
return {
visitor: {
MemberExpression(path, state) {
const {node} = path
const {property} = node
let name = ''
if (property.name === 'isNil' && path.parentPath.type !== 'CallExpression') {
const object = flatten(node)
Object.keys(object).forEach(key => {
if (/.type$/.test(key)) {
if (object[key] === 'ThisExpression') {
name += 'this.'
}
}
if (/.name$/.test(key)) {
if (!/arguments/.test(key) && object[key] !== 'isNil') {
name += object[key] + '.'
}
}
})
name = name.replace(/.$/, '')
const isArray = _get(node, 'object.computed', false)
const parentObject = _get(path, 'parentPath.node.expression.object')
const type = _get(parentObject, 'type')
const args = _get(parentObject, 'arguments')
if (isArray) {
if (node.object.property.name && node.object.computed === true) {
name = name.replace(`.${node.object.property.name}`, '')
}
const value = _get(node, 'object.property.extra.raw', null) ||
_get(node, 'object.property.name', null)
if (value) {
name += `[${value}]`
}
} else if (type === 'CallExpression') {
name += '('
if (args !== void 0) {
args.forEach(arg => {
name += arg.name
name += ','
})
name = name.replace(/,$/, '')
}
name += ')'
}
const node = path.node
const property = node.property
const isNilWrapper = addIsNilHelper.call(state.file).name
if (property.name !== 'isNil' || path.container.type === 'CallExpression') {
return
}
/* eslint no-void: 0 */
path.replaceWithSourceString(`${isNilWrapper}(${name})`)
}
const isNilWrapper = addIsNilHelper.call(state.file).name
path.replaceWith(t.callExpression(
t.identifier(isNilWrapper),
[node.object]
))
}

@@ -105,1 +69,3 @@ }

}
module.exports = plugin

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc