@putout/plugin-putout 18.5.0 → 18.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.
|
@@ -9,7 +9,6 @@ const {replaceWith} = operator;
|
|
|
9
9
|
|
|
10
10
|
const {
|
|
11
11
|
ArrayPattern,
|
|
12
|
-
ObjectPattern,
|
|
13
12
|
BlockStatement,
|
|
14
13
|
ObjectExpression,
|
|
15
14
|
} = types;
|
|
@@ -54,17 +53,11 @@ module.exports = (rootPath, key) => {
|
|
|
54
53
|
}
|
|
55
54
|
|
|
56
55
|
if (name === '__array') {
|
|
57
|
-
if (path.parentPath.isVariableDeclarator())
|
|
58
|
-
return replaceWith(path, ArrayPattern([]));
|
|
59
|
-
|
|
60
56
|
if (path.parentPath.isCallExpression())
|
|
61
57
|
return replaceWith(path, ArrayPattern([]));
|
|
62
58
|
|
|
63
59
|
if (path.parentPath.isFunction())
|
|
64
60
|
return replaceWith(path, ArrayPattern([]));
|
|
65
|
-
|
|
66
|
-
if (path.parentPath.isAssignmentExpression())
|
|
67
|
-
return replaceWith(path, ArrayPattern([]));
|
|
68
61
|
}
|
|
69
62
|
|
|
70
63
|
if (name === '__object')
|
|
@@ -98,11 +91,14 @@ function createVarStore(path) {
|
|
|
98
91
|
|
|
99
92
|
function objectify(path) {
|
|
100
93
|
const {parentPath} = path;
|
|
101
|
-
|
|
94
|
+
|
|
102
95
|
const isAssign = parentPath.isAssignmentExpression();
|
|
103
96
|
|
|
104
|
-
if (
|
|
105
|
-
return replaceWith(path,
|
|
97
|
+
if (path.parentPath.isExportDeclaration())
|
|
98
|
+
return replaceWith(path, ObjectExpression([]));
|
|
99
|
+
|
|
100
|
+
if (path.parentPath.isCallExpression())
|
|
101
|
+
return replaceWith(path, ObjectExpression([]));
|
|
106
102
|
|
|
107
103
|
if (isAssign && parentPath.get('right') === path)
|
|
108
104
|
return replaceWith(path, ObjectExpression([]));
|
|
@@ -9,6 +9,7 @@ const {
|
|
|
9
9
|
compare,
|
|
10
10
|
extract,
|
|
11
11
|
compute,
|
|
12
|
+
__json,
|
|
12
13
|
} = operator;
|
|
13
14
|
|
|
14
15
|
const name = '__putout_plugin_check_replace_code';
|
|
@@ -45,10 +46,11 @@ module.exports.traverse = ({push}) => ({
|
|
|
45
46
|
return;
|
|
46
47
|
|
|
47
48
|
for (const propertyPath of path.get('right.body.properties')) {
|
|
48
|
-
|
|
49
|
+
const template = extractValue(propertyPath);
|
|
50
|
+
|
|
51
|
+
if (!template)
|
|
49
52
|
continue;
|
|
50
53
|
|
|
51
|
-
const {node} = propertyPath;
|
|
52
54
|
const [parseError, key] = parseKey(propertyPath);
|
|
53
55
|
|
|
54
56
|
if (parseError) {
|
|
@@ -61,7 +63,6 @@ module.exports.traverse = ({push}) => ({
|
|
|
61
63
|
return;
|
|
62
64
|
}
|
|
63
65
|
|
|
64
|
-
const template = extract(node.value);
|
|
65
66
|
const [generateError, keyCode] = generateCode(path, key);
|
|
66
67
|
|
|
67
68
|
if (generateError) {
|
|
@@ -113,6 +114,10 @@ module.exports.traverse = ({push}) => ({
|
|
|
113
114
|
|
|
114
115
|
function parseKey(propertyPath) {
|
|
115
116
|
const keyPath = propertyPath.get('key');
|
|
117
|
+
|
|
118
|
+
if (keyPath.isIdentifier({name: '__json'}))
|
|
119
|
+
return [null, __json];
|
|
120
|
+
|
|
116
121
|
const [isComputed, key] = compute(keyPath);
|
|
117
122
|
|
|
118
123
|
if (!isComputed)
|
|
@@ -133,3 +138,15 @@ function hasMatch(path) {
|
|
|
133
138
|
|
|
134
139
|
return false;
|
|
135
140
|
}
|
|
141
|
+
|
|
142
|
+
function extractValue(path) {
|
|
143
|
+
const valuePath = path.get('value');
|
|
144
|
+
|
|
145
|
+
if (valuePath.isIdentifier({name: '__json'}))
|
|
146
|
+
return __json;
|
|
147
|
+
|
|
148
|
+
if (valuePath.isStringLiteral())
|
|
149
|
+
return valuePath.node.value;
|
|
150
|
+
|
|
151
|
+
return null;
|
|
152
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-putout",
|
|
3
|
-
"version": "18.
|
|
3
|
+
"version": "18.6.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "🐊Putout plugin helps with plugins development",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@putout/plugin-tape": "*",
|
|
41
41
|
"@putout/test": "^8.0.0",
|
|
42
|
-
"c8": "^
|
|
43
|
-
"eslint": "^
|
|
42
|
+
"c8": "^9.0.0",
|
|
43
|
+
"eslint": "^9.0.0-alpha.0",
|
|
44
44
|
"eslint-plugin-n": "^16.0.0",
|
|
45
45
|
"eslint-plugin-putout": "^22.0.0",
|
|
46
46
|
"lerna": "^6.0.1",
|