@putout/plugin-putout 18.4.1 β 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.
- package/README.md +18 -7
- package/lib/apply-for-of-to-track-file/index.js +7 -0
- package/lib/check-replace-code/generate-code.js +6 -10
- package/lib/check-replace-code/index.js +20 -3
- package/lib/index.js +4 -2
- package/package.json +3 -3
- /package/lib/{apply-namaspace-specifier β apply-namespace-specifier}/index.js +0 -0
package/README.md
CHANGED
|
@@ -25,7 +25,8 @@ npm i @putout/plugin-putout -D
|
|
|
25
25
|
"putout/apply-insert-before": "on",
|
|
26
26
|
"putout/apply-insert-after": "on",
|
|
27
27
|
"putout/apply-short-processors": "on",
|
|
28
|
-
"putout/apply-
|
|
28
|
+
"putout/apply-namespace-specifier": "on",
|
|
29
|
+
"putout/apply-for-of-to-track-file": "on",
|
|
29
30
|
"putout/add-args": "on",
|
|
30
31
|
"putout/add-push": "on",
|
|
31
32
|
"putout/add-track-file": "on",
|
|
@@ -276,22 +277,32 @@ const test = createTest({
|
|
|
276
277
|
});
|
|
277
278
|
```
|
|
278
279
|
|
|
279
|
-
## apply-
|
|
280
|
+
## apply-for-of-to-track-file
|
|
280
281
|
|
|
281
|
-
|
|
282
|
+
> The **Generator** object is returned by a `generator function` and it conforms to both the iterable protocol and the `iterator` protocol.
|
|
283
|
+
>
|
|
284
|
+
> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator)
|
|
285
|
+
|
|
286
|
+
`trackFile` is generator function used to count progress that can be used in [**Scanner**](https://github.com/coderaiser/putout/tree/master/packages/engine-runner#scanner).
|
|
287
|
+
|
|
288
|
+
Checkout in π[**Putout Editor**](https://putout.cloudcmd.io/#/gist/5ec6c384aa6e4471aab17efb86e185f3/e749c7d649ef2da76410a5964e7c875d10538789)
|
|
282
289
|
|
|
283
290
|
### β Example of incorrect code
|
|
284
291
|
|
|
285
292
|
```js
|
|
286
|
-
|
|
287
|
-
|
|
293
|
+
module.exports.scan = (path, {push, trackFile}) => {
|
|
294
|
+
trackFile(path, '*.swp').map(push);
|
|
295
|
+
};
|
|
288
296
|
```
|
|
289
297
|
|
|
290
298
|
### β
Example of correct code
|
|
291
299
|
|
|
292
300
|
```js
|
|
293
|
-
|
|
294
|
-
|
|
301
|
+
module.exports.scan = (path, {push, trackFile}) => {
|
|
302
|
+
for (const file of trackFile(path, '*.swp')) {
|
|
303
|
+
push(file);
|
|
304
|
+
}
|
|
305
|
+
};
|
|
295
306
|
```
|
|
296
307
|
|
|
297
308
|
## create-test
|
|
@@ -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/lib/index.js
CHANGED
|
@@ -39,7 +39,7 @@ const addPush = require('./add-push');
|
|
|
39
39
|
const moveRequireOnTopLevel = require('./move-require-on-top-level');
|
|
40
40
|
const includer = require('./includer');
|
|
41
41
|
const createTest = require('./create-test');
|
|
42
|
-
const
|
|
42
|
+
const applyNamespaceSpecifier = require('./apply-namespace-specifier');
|
|
43
43
|
const convertGetRuleToRequire = require('./convert-get-rule-to-require');
|
|
44
44
|
const addIndexToImport = require('./add-index-to-import');
|
|
45
45
|
const applyRename = require('./apply-rename');
|
|
@@ -47,6 +47,7 @@ const applyShortProcessors = require('./apply-short-processors');
|
|
|
47
47
|
const addTrackFile = require('./add-track-file');
|
|
48
48
|
const convertProgressToTrackFile = require('./convert-progress-to-track-file');
|
|
49
49
|
const addAwaitToProgress = require('./add-await-to-progress');
|
|
50
|
+
const applyForOfToTrackFile = require('./apply-for-of-to-track-file');
|
|
50
51
|
|
|
51
52
|
module.exports.rules = {
|
|
52
53
|
'apply-processors-destructuring': applyProcessorsDestructuring,
|
|
@@ -87,7 +88,7 @@ module.exports.rules = {
|
|
|
87
88
|
'move-require-on-top-level': moveRequireOnTopLevel,
|
|
88
89
|
includer,
|
|
89
90
|
'create-test': createTest,
|
|
90
|
-
'apply-
|
|
91
|
+
'apply-namespace-specifier': applyNamespaceSpecifier,
|
|
91
92
|
'convert-get-rule-to-require': convertGetRuleToRequire,
|
|
92
93
|
'add-index-to-import': addIndexToImport,
|
|
93
94
|
'apply-rename': applyRename,
|
|
@@ -96,4 +97,5 @@ module.exports.rules = {
|
|
|
96
97
|
'add-track-file': addTrackFile,
|
|
97
98
|
'convert-progress-to-track-file': convertProgressToTrackFile,
|
|
98
99
|
'add-await-to-progress': addAwaitToProgress,
|
|
100
|
+
'apply-for-of-to-track-file': applyForOfToTrackFile,
|
|
99
101
|
};
|
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",
|
|
File without changes
|