@putout/compare
Advanced tools
Comparing version 4.2.0 to 4.3.0
@@ -31,2 +31,3 @@ 'use strict'; | ||
isEqualBody, | ||
isEqualNop, | ||
isLinkedNode, | ||
@@ -81,2 +82,5 @@ isTemplate, | ||
if (isEqualNop(node, baseNode)) | ||
return true; | ||
if (isPath(path) && !isEqualType(node, baseNode)) { | ||
@@ -179,2 +183,5 @@ const {type} = baseNode; | ||
if (isEqualNop(nodeValue, value)) | ||
return true; | ||
if (isLinkedNode(value)) { | ||
@@ -181,0 +188,0 @@ const {name} = value; |
@@ -5,4 +5,6 @@ 'use strict'; | ||
const { | ||
isBlockStatement, | ||
isIdentifier, | ||
isLiteral, | ||
isFunction, | ||
isImportDefaultSpecifier, | ||
@@ -19,2 +21,3 @@ } = require('@babel/types'); | ||
const BODY = '__body'; | ||
const NOP = '__nop'; | ||
const ANY = '__'; | ||
@@ -61,2 +64,6 @@ | ||
const isNop = (a) => isIdentifier(a, { | ||
name: NOP, | ||
}); | ||
const isAnyObject = (a) => isIdentifier(a, { | ||
@@ -145,2 +152,17 @@ name: ANY_OBJECT, | ||
module.exports.isEqualNop = (node, baseNode) => { | ||
if (!isNop(baseNode)) | ||
return false; | ||
if (!isFunction(node)) | ||
return false; | ||
const {body} = node; | ||
if (!isBlockStatement(body)) | ||
return false; | ||
return !body.body.length; | ||
}; | ||
module.exports.isLinkedNode = (a) => { | ||
@@ -147,0 +169,0 @@ if (isIdentifier(a) && LINKED_NODE.test(a.name)) |
{ | ||
"name": "@putout/compare", | ||
"version": "4.2.0", | ||
"version": "4.3.0", | ||
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)", | ||
@@ -5,0 +5,0 @@ "description": "compare ast-nodes", |
@@ -134,2 +134,15 @@ # putout-compare [![NPM version][NPMIMGURL]][NPMURL] [![Dependency Status][DependencyStatusIMGURL]][DependencyStatusURL] | ||
##### "__nop" | ||
Any `Function` with no `arguments` and empty body; | ||
```js | ||
compare('const a = () => {}, 'const __a = __nop); | ||
// returns | ||
true | ||
compare('const a = async () => {}, 'const a = () => __nop'); | ||
// returns | ||
true | ||
``` | ||
## License | ||
@@ -136,0 +149,0 @@ |
17642
414
151