@putout/engine-runner 12.0.0 → 12.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 CHANGED
@@ -170,34 +170,40 @@ module.exports.traverse = ({push}) => ({
170
170
  });
171
171
  ```
172
172
 
173
- #### listStore
173
+ #### Storages
174
174
 
175
- To keep things during traverse in a safe way `listStore` can be used.
175
+ Storages is preferred way of keeping data 🐊`Putout`, `traverse` init function called only once, and any other way
176
+ of handling variables will most likely will lead to bugs.
177
+
178
+ ##### listStore
179
+
180
+ To keep things and save them as a list during traverse in a safe way `listStore` can be used for code:
181
+
182
+ ```js
183
+ debugger;
184
+ const hello = '';
185
+ debugger;
186
+ const world = '';
187
+ ```
176
188
 
177
189
  ```js
178
- module.exports.traverse = ({push, listStore}) => ({
190
+ module.exports.traverse = ({listStore}) => ({
179
191
  'debugger'(path) {
180
192
  listStore('x');
181
- push(path);
182
193
  },
183
194
 
184
195
  Program: {
185
196
  exit() {
186
197
  console.log(listStore());
187
198
  // returns
188
- ['x', 'x', 'x'];
199
+ ['x', 'x'];
189
200
  // for code
190
- 'debugger; debugger; debugger';
201
+ 'debugger; debugger';
191
202
  },
192
203
  },
193
204
  });
194
205
  ```
195
206
 
196
- `store` is preferred way of keeping data, because of caching 🐊`putout`, `traverse` init function called only once, and any other way
197
- of handling variables will most likely will lead to bugs.
198
-
199
- #### Store
200
-
201
207
  When you need `key-value` storage `store` can be used.
202
208
 
203
209
  ```js
@@ -262,24 +268,6 @@ module.exports.traverse = ({push, store}) => ({
262
268
  });
263
269
  ```
264
270
 
265
- #### ListStore
266
-
267
- When you need to track list of elements, use `listStore`:
268
-
269
- ```
270
- module.exports.traverse = ({push, listStore}) => ({
271
- ImportDeclaration(path) {
272
- listStore(path);
273
- },
274
-
275
- Program: {
276
- exit: () => {
277
- processImports(push, listStore());
278
- },
279
- },
280
- });
281
- ```
282
-
283
271
  ### Finder
284
272
 
285
273
  `Find plugins` gives you all the control over traversing, but it's the slowest format.
package/lib/index.js CHANGED
@@ -41,6 +41,8 @@ module.exports.runPlugins = ({ast, shebang, fix, fixCount, plugins, template = r
41
41
 
42
42
  if (!fix || !places.length)
43
43
  return places;
44
+
45
+ replace.clearWatermark(ast);
44
46
  }
45
47
 
46
48
  return places;
@@ -61,6 +61,10 @@ module.exports = ({rule, plugin, msg, options}) => {
61
61
  };
62
62
  };
63
63
 
64
+ module.exports.clearWatermark = (ast) => {
65
+ delete ast.program[watermark.REPLACE_WATERMARK];
66
+ };
67
+
64
68
  const isFn = (a) => typeof a === 'function';
65
69
 
66
70
  const fix = (from, to, path) => {
@@ -30,6 +30,8 @@ module.exports = (from, to, path) => {
30
30
  };
31
31
  };
32
32
 
33
+ module.exports.REPLACE_WATERMARK = name;
34
+
33
35
  module.exports.create = create;
34
36
  function create(from, to, path) {
35
37
  const watermark = `${from} -> ${to}`;
@@ -52,6 +54,7 @@ function init({path, program}) {
52
54
  module.exports.add = add;
53
55
  function add({path, program, watermark, highWatermark}) {
54
56
  init({path, program});
57
+
55
58
  path.node[name].add(watermark);
56
59
  program.node[name].add(highWatermark);
57
60
  }
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@putout/engine-runner",
3
- "version": "12.0.0",
3
+ "version": "12.1.0",
4
+ "type": "commonjs",
4
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
5
6
  "description": "run putout plugins",
6
7
  "homepage": "https://github.com/coderaiser/putout/tree/master/packages/engine-runner#readme",