@putout/engine-runner 14.1.1 β†’ 15.0.1

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 CHANGED
@@ -15,6 +15,7 @@ npm i @putout/engine-runner
15
15
 
16
16
  There is a couple plugin types supported by 🐊**Putout**:
17
17
 
18
+ - βœ… [**Declarator**](#Declarator)
18
19
  - βœ… [**Replacer**](#replacer)
19
20
  - βœ… [**Includer**](#includer)
20
21
  - βœ… [**Traverser**](#traverser)
@@ -24,6 +25,18 @@ All of them supports subset of **JavaScript** 🦎[**PutoutScript**](https://git
24
25
 
25
26
  They goes from simplest to hardest. Let's start from **Replacer**.
26
27
 
28
+ ### Declarator
29
+
30
+ The simplest possible type of plugin, even simpler then `Replacer`:
31
+
32
+ ```js
33
+ module.exports.declare = () => ({
34
+ isString: `const isString = (a) => typeof a === 'string'`,
35
+ });
36
+ ```
37
+
38
+ Based on [`@putout/operator-declare`](https://github.com/coderaiser/putout/tree/master/packages/operator-declare#readme), helps to add declaration to any referenced `Identifier`.
39
+
27
40
  ### Replacer
28
41
 
29
42
  **Replacer** converts code in declarative way. Simplest possible form, no need to use `fix`. Just `from` and `to` parts
package/lib/declare.js ADDED
@@ -0,0 +1,23 @@
1
+ 'use strict';
2
+
3
+ const {declare} = require('@putout/operator-declare');
4
+
5
+ const {stringify} = JSON;
6
+ const isFn = (a) => typeof a === 'function';
7
+
8
+ module.exports = ({rule, plugin, msg, options}) => {
9
+ validateDeclare(plugin.declare);
10
+
11
+ return {
12
+ rule,
13
+ plugin: declare(plugin.declare()),
14
+ msg,
15
+ options,
16
+ };
17
+ };
18
+
19
+ function validateDeclare(declare) {
20
+ if (!isFn(declare))
21
+ throw Error(`☝️ Looks like 'declare' property value is not a 'function', but '${typeof declare}' with value '${stringify(declare)}'.`);
22
+ }
23
+
package/lib/index.js CHANGED
@@ -9,6 +9,7 @@ const mergeVisitors = require('./merge-visitors');
9
9
  const superFind = require('./super-find');
10
10
  const include = require('./include');
11
11
  const replace = require('./replace');
12
+ const declare = require('./declare');
12
13
 
13
14
  const {
14
15
  getPath,
@@ -50,8 +51,17 @@ module.exports.getPosition = getPosition;
50
51
 
51
52
  function run({ast, fix, shebang, pluginsFind, pluginsTraverse, template, merge}) {
52
53
  return [
53
- ...runWithoutMerge({ast, fix, shebang, template, pluginsFind}),
54
- ...runWithMerge({ast, fix, shebang, template, pluginsTraverse, merge}),
54
+ ...runWithoutMerge({ast,
55
+ fix,
56
+ shebang,
57
+ template,
58
+ pluginsFind}),
59
+ ...runWithMerge({ast,
60
+ fix,
61
+ shebang,
62
+ template,
63
+ pluginsTraverse,
64
+ merge}),
55
65
  ];
56
66
  }
57
67
 
@@ -152,6 +162,11 @@ function splitPlugins(plugins) {
152
162
  continue;
153
163
  }
154
164
 
165
+ if (plugin.declare) {
166
+ pluginsTraverse.push(include(declare(item)));
167
+ continue;
168
+ }
169
+
155
170
  if (plugin.include) {
156
171
  pluginsTraverse.push(include(item));
157
172
  continue;
@@ -1,11 +1,12 @@
1
1
  'use strict';
2
2
 
3
3
  const {isArray} = Array;
4
+ const maybeArray = (a) => isArray(a) ? a : [a];
4
5
 
5
6
  module.exports = (a) => {
6
7
  if (!a)
7
8
  return [];
8
9
 
9
- return isArray(a) ? a : [a];
10
+ return maybeArray(a);
10
11
  };
11
12
 
package/package.json CHANGED
@@ -1,12 +1,11 @@
1
1
  {
2
2
  "name": "@putout/engine-runner",
3
- "version": "14.1.1",
3
+ "version": "15.0.1",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "Run 🐊Putout plugins",
7
7
  "homepage": "https://github.com/coderaiser/putout/tree/master/packages/engine-runner#readme",
8
8
  "main": "lib/index.js",
9
- "commitType": "colon",
10
9
  "release": false,
11
10
  "tag": false,
12
11
  "changelog": false,
@@ -30,6 +29,7 @@
30
29
  "@putout/compare": "^9.0.0",
31
30
  "@putout/engine-parser": "^5.0.0",
32
31
  "@putout/operate": "^8.0.0",
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",