@putout/plugin-putout 8.3.0 → 8.4.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.
|
@@ -5,11 +5,16 @@ const tryCatch = require('try-catch');
|
|
|
5
5
|
|
|
6
6
|
const generateCode = require('./generate-code');
|
|
7
7
|
|
|
8
|
-
const {operator} = putout;
|
|
8
|
+
const {operator, types} = putout;
|
|
9
|
+
const {
|
|
10
|
+
isMemberExpression,
|
|
11
|
+
isObjectExpression,
|
|
12
|
+
} = types;
|
|
9
13
|
|
|
10
14
|
const {
|
|
11
15
|
compare,
|
|
12
16
|
extract,
|
|
17
|
+
getBindingPath,
|
|
13
18
|
} = operator;
|
|
14
19
|
|
|
15
20
|
const name = '__putout_plugin_check_replace_code';
|
|
@@ -48,12 +53,13 @@ module.exports.traverse = ({push}) => ({
|
|
|
48
53
|
continue;
|
|
49
54
|
|
|
50
55
|
const {node} = propertyPath;
|
|
56
|
+
const key = compute(propertyPath);
|
|
51
57
|
|
|
52
|
-
if (
|
|
53
|
-
|
|
58
|
+
if (!key)
|
|
59
|
+
continue;
|
|
54
60
|
|
|
55
|
-
const key = extract(node.key);
|
|
56
61
|
const template = extract(node.value);
|
|
62
|
+
|
|
57
63
|
const [generateError, keyCode] = generateCode(path, key);
|
|
58
64
|
|
|
59
65
|
if (generateError) {
|
|
@@ -100,3 +106,34 @@ module.exports.traverse = ({push}) => ({
|
|
|
100
106
|
},
|
|
101
107
|
});
|
|
102
108
|
|
|
109
|
+
function compute(path) {
|
|
110
|
+
const {key, computed} = path.node;
|
|
111
|
+
|
|
112
|
+
if (!computed)
|
|
113
|
+
return extract(key);
|
|
114
|
+
|
|
115
|
+
if (!isMemberExpression(key))
|
|
116
|
+
return '';
|
|
117
|
+
|
|
118
|
+
const bindingPath = getBindingPath(path, extract(key.object));
|
|
119
|
+
|
|
120
|
+
if (!bindingPath)
|
|
121
|
+
return '';
|
|
122
|
+
|
|
123
|
+
const bindingNode = bindingPath.node;
|
|
124
|
+
|
|
125
|
+
if (!isObjectExpression(bindingNode.init))
|
|
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
|
+
}
|
|
136
|
+
|
|
137
|
+
return `'not found'`;
|
|
138
|
+
}
|
|
139
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-putout",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.4.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",
|