@putout/plugin-types 2.4.0 → 2.6.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.
- package/README.md +1 -0
- package/lib/convert-typeof-to-is-type/index.js +14 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,7 +13,8 @@ const NAMES = {
|
|
|
13
13
|
bigint: 'isBigInt',
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
const
|
|
16
|
+
const EQUAL = 'typeof __a === "__b"';
|
|
17
|
+
const NOT_EQUAL = 'typeof __a !== "__b"';
|
|
17
18
|
|
|
18
19
|
const BODIES = {
|
|
19
20
|
function: `typeof __a === 'function'`,
|
|
@@ -37,18 +38,8 @@ const NOT_BODIES = {
|
|
|
37
38
|
|
|
38
39
|
module.exports.report = () => `Use function to check type instead of 'typeof'`;
|
|
39
40
|
module.exports.match = () => ({
|
|
40
|
-
[
|
|
41
|
-
|
|
42
|
-
return false;
|
|
43
|
-
|
|
44
|
-
if (path.parentPath.isVariableDeclarator())
|
|
45
|
-
return false;
|
|
46
|
-
|
|
47
|
-
if (isBind(path, __b.value))
|
|
48
|
-
return false;
|
|
49
|
-
|
|
50
|
-
return Boolean(getBindingPath(path, __a));
|
|
51
|
-
},
|
|
41
|
+
[EQUAL]: check,
|
|
42
|
+
[NOT_EQUAL]: check,
|
|
52
43
|
});
|
|
53
44
|
|
|
54
45
|
module.exports.replace = () => ({
|
|
@@ -68,6 +59,16 @@ module.exports.replace = () => ({
|
|
|
68
59
|
[NOT_BODIES.bigint]: '!isBigInt(__a)',
|
|
69
60
|
});
|
|
70
61
|
|
|
62
|
+
function check({__a, __b}, path) {
|
|
63
|
+
if (path.parentPath.isFunction())
|
|
64
|
+
return false;
|
|
65
|
+
|
|
66
|
+
if (isBind(path, __b.value))
|
|
67
|
+
return false;
|
|
68
|
+
|
|
69
|
+
return getBindingPath(path, __a);
|
|
70
|
+
}
|
|
71
|
+
|
|
71
72
|
function isBind(path, name) {
|
|
72
73
|
const fnName = NAMES[name];
|
|
73
74
|
const fnBody = BODIES[name];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-types",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.0",
|
|
4
4
|
"type": "commonjs",
|
|
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",
|