@putout/plugin-putout 8.4.0 → 8.5.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/lib/check-replace-code/index.js +21 -36
- package/package.json +1 -1
|
@@ -5,16 +5,12 @@ const tryCatch = require('try-catch');
|
|
|
5
5
|
|
|
6
6
|
const generateCode = require('./generate-code');
|
|
7
7
|
|
|
8
|
-
const {operator
|
|
9
|
-
const {
|
|
10
|
-
isMemberExpression,
|
|
11
|
-
isObjectExpression,
|
|
12
|
-
} = types;
|
|
8
|
+
const {operator} = putout;
|
|
13
9
|
|
|
14
10
|
const {
|
|
15
11
|
compare,
|
|
16
12
|
extract,
|
|
17
|
-
|
|
13
|
+
compute,
|
|
18
14
|
} = operator;
|
|
19
15
|
|
|
20
16
|
const name = '__putout_plugin_check_replace_code';
|
|
@@ -33,7 +29,7 @@ module.exports.report = ({path, code, error}) => {
|
|
|
33
29
|
if (error)
|
|
34
30
|
return error.message;
|
|
35
31
|
|
|
36
|
-
const key =
|
|
32
|
+
const [, key] = parseKey(path);
|
|
37
33
|
const value = extract(path.node.value);
|
|
38
34
|
|
|
39
35
|
return `transform mismatch: "${key}" -> "${value}" !== "${code}"`;
|
|
@@ -53,13 +49,18 @@ module.exports.traverse = ({push}) => ({
|
|
|
53
49
|
continue;
|
|
54
50
|
|
|
55
51
|
const {node} = propertyPath;
|
|
56
|
-
const key =
|
|
52
|
+
const [parseError, key] = parseKey(propertyPath);
|
|
57
53
|
|
|
58
|
-
if (
|
|
59
|
-
|
|
54
|
+
if (parseError) {
|
|
55
|
+
push({
|
|
56
|
+
error: parseError,
|
|
57
|
+
mainPath: path,
|
|
58
|
+
path: propertyPath,
|
|
59
|
+
});
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
60
62
|
|
|
61
63
|
const template = extract(node.value);
|
|
62
|
-
|
|
63
64
|
const [generateError, keyCode] = generateCode(path, key);
|
|
64
65
|
|
|
65
66
|
if (generateError) {
|
|
@@ -106,34 +107,18 @@ module.exports.traverse = ({push}) => ({
|
|
|
106
107
|
},
|
|
107
108
|
});
|
|
108
109
|
|
|
109
|
-
function
|
|
110
|
-
const {
|
|
111
|
-
|
|
112
|
-
if (!computed)
|
|
113
|
-
return extract(key);
|
|
114
|
-
|
|
115
|
-
if (!isMemberExpression(key))
|
|
116
|
-
return '';
|
|
117
|
-
|
|
118
|
-
const bindingPath = getBindingPath(path, extract(key.object));
|
|
110
|
+
function parseKey(propertyPath) {
|
|
111
|
+
const {node} = propertyPath;
|
|
119
112
|
|
|
120
|
-
if (!
|
|
121
|
-
return
|
|
113
|
+
if (!node.computed)
|
|
114
|
+
return [null, extract(node.key)];
|
|
122
115
|
|
|
123
|
-
const
|
|
116
|
+
const keyPath = propertyPath.get('key');
|
|
117
|
+
const [isComputed, key] = compute(keyPath);
|
|
124
118
|
|
|
125
|
-
if (!
|
|
126
|
-
return '';
|
|
127
|
-
|
|
128
|
-
const keyPropertyValue = extract(key.property);
|
|
129
|
-
|
|
130
|
-
for (const property of bindingNode.init.properties) {
|
|
131
|
-
const keyValue = extract(property.key);
|
|
132
|
-
|
|
133
|
-
if (keyValue === keyPropertyValue)
|
|
134
|
-
return extract(property.value);
|
|
135
|
-
}
|
|
119
|
+
if (!isComputed)
|
|
120
|
+
return [Error(`Replace key cannot be computed: '${keyPath.toString()}'`)];
|
|
136
121
|
|
|
137
|
-
return
|
|
122
|
+
return [null, key];
|
|
138
123
|
}
|
|
139
124
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-putout",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.5.0",
|
|
4
4
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
5
5
|
"description": "putout plugin helps with plugins development",
|
|
6
6
|
"homepage": "https://github.com/coderaiser/putout/tree/master/packages/plugin-putout",
|