babel-plugin-transform-isnil
Advanced tools
Comparing version 0.0.8 to 1.0.0
{ | ||
"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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
131717
0
3
0
7
54
142
1
- Removedflat@^2.0.0
- Removedlodash.get@^4.2.1
- Removedflat@2.0.2(transitive)
- Removedis-buffer@1.1.6(transitive)
- Removedlodash.get@4.4.2(transitive)