@putout/engine-runner 15.0.0 β 15.1.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 +4 -4
- package/lib/replace/index.js +23 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ npm i @putout/engine-runner
|
|
|
13
13
|
|
|
14
14
|
## Supported Plugin Types
|
|
15
15
|
|
|
16
|
-
There is a couple plugin types
|
|
16
|
+
There is a couple plugin types available in π**Putout**:
|
|
17
17
|
|
|
18
18
|
- β
[**Declarator**](#Declarator)
|
|
19
19
|
- β
[**Replacer**](#replacer)
|
|
@@ -23,11 +23,11 @@ There is a couple plugin types supported by π**Putout**:
|
|
|
23
23
|
|
|
24
24
|
All of them supports subset of **JavaScript** π¦[**PutoutScript**](https://github.com/coderaiser/putout/blob/master/docs/putout-script.md#-putoutscript) described in [`@putout/compare`](https://github.com/coderaiser/putout/tree/master/packages/compare#readme).
|
|
25
25
|
|
|
26
|
-
They goes from simplest to hardest. Let's start from **
|
|
26
|
+
They goes from simplest to hardest. Let's start from **Declarator**.
|
|
27
27
|
|
|
28
28
|
### Declarator
|
|
29
29
|
|
|
30
|
-
The simplest possible type of plugin, even simpler then `Replacer
|
|
30
|
+
The simplest possible type of plugin, even simpler then [`Replacer`](#replacer):
|
|
31
31
|
|
|
32
32
|
```js
|
|
33
33
|
module.exports.declare = () => ({
|
|
@@ -158,7 +158,7 @@ module.exports.replace = () => ({
|
|
|
158
158
|
|
|
159
159
|
### Includer
|
|
160
160
|
|
|
161
|
-
**Includer** is the most preferable format of a plugin, simplest to use (after `Replacer`):
|
|
161
|
+
**Includer** is the most preferable format of a plugin, simplest to use (after [`Replacer`](#replacer)):
|
|
162
162
|
|
|
163
163
|
```js
|
|
164
164
|
module.exports.report = () => 'debugger statement should not be used';
|
package/lib/replace/index.js
CHANGED
|
@@ -2,16 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
const {template} = require('@putout/engine-parser');
|
|
4
4
|
|
|
5
|
+
const {
|
|
6
|
+
isExpression,
|
|
7
|
+
isStatement,
|
|
8
|
+
isExpressionStatement,
|
|
9
|
+
} = require('@babel/types');
|
|
10
|
+
|
|
5
11
|
const {
|
|
6
12
|
remove,
|
|
7
13
|
replaceWith,
|
|
8
14
|
} = require('@putout/operate');
|
|
15
|
+
|
|
9
16
|
const {
|
|
10
17
|
compare,
|
|
11
18
|
findVarsWays,
|
|
12
19
|
getValues,
|
|
13
20
|
setValues,
|
|
14
21
|
} = require('@putout/compare');
|
|
22
|
+
|
|
15
23
|
const debug = require('debug')('putout:runner:replace');
|
|
16
24
|
const maybeArray = require('../maybe-array');
|
|
17
25
|
|
|
@@ -94,6 +102,8 @@ const fix = (from, to, path) => {
|
|
|
94
102
|
return remove(path);
|
|
95
103
|
}
|
|
96
104
|
|
|
105
|
+
checkExpressionStatement(nodeFrom, nodeTo, path);
|
|
106
|
+
|
|
97
107
|
const waysTo = findVarsWays(nodeTo);
|
|
98
108
|
const newPath = replaceWith(path, nodeTo);
|
|
99
109
|
|
|
@@ -169,3 +179,16 @@ const validateTemplateValues = (a, b) => {
|
|
|
169
179
|
}
|
|
170
180
|
};
|
|
171
181
|
|
|
182
|
+
function checkExpressionStatement(nodeFrom, nodeTo, path) {
|
|
183
|
+
if (!isExpression(nodeFrom))
|
|
184
|
+
return;
|
|
185
|
+
|
|
186
|
+
if (!isStatement(nodeTo) || isExpressionStatement(nodeTo))
|
|
187
|
+
return;
|
|
188
|
+
|
|
189
|
+
if (isExpressionStatement(path) || isExpressionStatement(path.parentPath))
|
|
190
|
+
return;
|
|
191
|
+
|
|
192
|
+
throw Error(`βοΈ Looks like try to put Statement in place of Expression, use 'match' to filter out such cases`);
|
|
193
|
+
}
|
|
194
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/engine-runner",
|
|
3
|
-
"version": "15.
|
|
3
|
+
"version": "15.1.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "Run πPutout plugins",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"@putout/compare": "^9.0.0",
|
|
30
30
|
"@putout/engine-parser": "^5.0.0",
|
|
31
31
|
"@putout/operate": "^8.0.0",
|
|
32
|
-
"@putout/operator-declare": "^
|
|
32
|
+
"@putout/operator-declare": "^5.0.0",
|
|
33
33
|
"debug": "^4.1.1",
|
|
34
34
|
"jessy": "^3.0.0",
|
|
35
35
|
"nessy": "^4.0.0",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"c8": "^7.5.0",
|
|
47
47
|
"eslint": "^8.0.1",
|
|
48
48
|
"eslint-plugin-n": "^15.2.4",
|
|
49
|
-
"eslint-plugin-putout": "^
|
|
49
|
+
"eslint-plugin-putout": "^17.0.0",
|
|
50
50
|
"just-camel-case": "^4.0.2",
|
|
51
51
|
"lerna": "^6.0.1",
|
|
52
52
|
"madrun": "^9.0.0",
|