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.1 to 0.0.2

.travis.yml

26

lib/index.js

@@ -7,5 +7,3 @@ 'use strict';

exports.default = function (_ref) {
var t = _ref.types;
exports.default = function () {
return {

@@ -24,6 +22,22 @@ visitor: {

if (/.name$/.test(key)) {
if (object[key] !== 'isNil') name += object[key] + '.';
if (!/arguments/.test(key) && object[key] !== 'isNil') {
name += object[key] + '.';
}
}
});
name = name.replace(/.$/, '');
var parentObject = (0, _lodash2.default)(path, 'parentPath.node.expression.object');
var type = (0, _lodash2.default)(parentObject, 'type');
var args = (0, _lodash2.default)(parentObject, 'arguments');
if (type === 'CallExpression') {
name += '(';
if (args !== undefined) {
args.forEach(function (arg) {
name += arg.name;
name += ',';
});
name = name.replace(/,$/, '');
}
name += ')';
}
path.replaceWithSourceString('(' + name + ' === null || ' + name + ' === undefined)');

@@ -41,2 +55,6 @@ })();

var _lodash = require('lodash.get');
var _lodash2 = _interopRequireDefault(_lodash);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

20

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

@@ -16,2 +20,6 @@ "repository": {

],
"xo": {
"semicolon": false,
"space": 2
},
"author": "MaxMEllon",

@@ -24,10 +32,14 @@ "license": "MIT",

"devDependencies": {
"ava": "^0.14.0",
"ava-spec": "^1.0.0",
"babel-cli": "^6.7.7",
"babel-core": "^6.7.7",
"babel-preset-es2015": "^6.6.0",
"babel-register": "^6.7.2"
"babel-register": "^6.7.2",
"xo": "^0.15.0"
},
"dependencies": {
"flat": "^2.0.0"
"flat": "^2.0.0",
"lodash.get": "^4.2.1"
}
}

@@ -6,3 +6,10 @@ # babel-plugin-transform-isNil

</a>
<a href="https://travis-ci.org/MaxMEllon/babel-plugin-transform-isNil">
<img src="https://travis-ci.org/MaxMEllon/babel-plugin-transform-isNil.svg?branch=master"/>
</a>
<a href="https://github.com/sindresorhus/xo">
<img src="https://img.shields.io/badge/code_style-XO-5ed9c7.svg"/>
</a>
Installation

@@ -50,2 +57,52 @@ ---

**In**
```js
if (hoge.poge().isNil) {
console.log('hoge.poge and foo.bar is null or undefined');
}
```
**Out**
```js
if (hoge.poge() === null || hoge.poge() === undefined) {
console.log('hoge.poge and foo.bar is null or undefined');
}
```
**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');
}
```
## TODO
**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

@@ -52,0 +109,0 @@

import flatten from 'flat'
import _get from 'lodash.get'
export default function ({ types: t }) {
export default function () {
return {
visitor: {
MemberExpression(path) {
const { node } = path
const { property } = node
const {node} = path
const {property} = node

@@ -15,12 +16,28 @@ if (property.name === 'isNil' && path.parentPath.type !== 'CallExpression') {

if (/.name$/.test(key)) {
if (object[key] !== 'isNil') name += object[key] + '.'
if (!/arguments/.test(key) && object[key] !== 'isNil') {
name += object[key] + '.'
}
}
});
})
name = name.replace(/.$/, '')
const parentObject = _get(path, 'parentPath.node.expression.object')
const type = _get(parentObject, 'type')
const args = _get(parentObject, 'arguments')
if (type === 'CallExpression') {
name += '('
if (args !== undefined) {
args.forEach(arg => {
name += arg.name
name += ','
})
name = name.replace(/,$/, '')
}
name += ')'
}
path.replaceWithSourceString(`(${name} === null || ${name} === undefined)`)
}
},
}
}
};
}
}

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