@putout/plugin-types 8.0.0 → 8.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,10 @@
1
1
  import {operator} from 'putout';
2
2
 
3
- const {compare, getBindingPath} = operator;
3
+ const {
4
+ compare,
5
+ getBindingPath,
6
+ extract,
7
+ } = operator;
4
8
 
5
9
  const NAMES = {
6
10
  function: 'isFn',
@@ -10,6 +14,7 @@ const NAMES = {
10
14
  undefined: 'isUndefined',
11
15
  symbol: 'isSymbol',
12
16
  bigint: 'isBigInt',
17
+ Object: 'isObject',
13
18
  };
14
19
 
15
20
  const EQUAL = 'typeof __a === "__b"';
@@ -53,10 +58,11 @@ export const report = () => `Use function to check type instead of 'typeof' or '
53
58
  export const match = () => ({
54
59
  [EQUAL]: check,
55
60
  [NOT_EQUAL]: check,
56
- [EQUAL_INSTANCE_OF]: check,
61
+
57
62
  [NOT_EQUAL_INSTANCE_OF]: check,
58
63
  [EQUAL_UNDEFINED]: check,
59
64
  [NOT_EQUAL_UNDEFINED]: check,
65
+ [EQUAL_INSTANCE_OF]: check,
60
66
  });
61
67
 
62
68
  export const replace = () => ({
@@ -88,7 +94,7 @@ function check({__a, __b}, path) {
88
94
  if (path.parentPath.isFunction())
89
95
  return false;
90
96
 
91
- if (__b && isBind(path, __b.value))
97
+ if (__b && isBind(path, extract(__b)))
92
98
  return false;
93
99
 
94
100
  return getBindingPath(path, __a);
@@ -103,7 +109,13 @@ function isBind(path, name) {
103
109
  return false;
104
110
 
105
111
  if (bindingPath.isVariableDeclarator()) {
106
- const {body} = bindingPath.node.init;
112
+ const initPath = bindingPath.get('init');
113
+
114
+ if (!initPath.isFunction())
115
+ return true;
116
+
117
+ const {body} = initPath.node;
118
+
107
119
  return !compare(body, fnBody);
108
120
  }
109
121
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-types",
3
- "version": "8.0.0",
3
+ "version": "8.1.0",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout plugin adds ability to transform code related to types assertions",
@@ -32,12 +32,13 @@
32
32
  ],
33
33
  "devDependencies": {
34
34
  "@putout/eslint-flat": "^3.0.0",
35
+ "@putout/plugin-declare-before-reference": "*",
35
36
  "@putout/plugin-putout": "*",
36
- "@putout/test": "^13.0.0",
37
+ "@putout/test": "^14.0.0",
37
38
  "c8": "^10.0.0",
38
39
  "eslint": "^9.0.0",
39
40
  "eslint-plugin-n": "^17.0.0",
40
- "eslint-plugin-putout": "^26.0.0",
41
+ "eslint-plugin-putout": "^28.0.0",
41
42
  "madrun": "^11.0.0",
42
43
  "montag": "^1.2.1",
43
44
  "nodemon": "^3.0.1"