@putout/engine-runner 13.2.1 → 13.4.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
@@ -245,7 +245,7 @@ Let's talk about each of them.
245
245
 
246
246
  ### `listStore`
247
247
 
248
- To save things as a list use `listStore`.
248
+ To save things as a list without duplicates use `listStore`.
249
249
  Let's suppose you have such code:
250
250
 
251
251
  ```js
@@ -260,14 +260,14 @@ Let's process it!
260
260
  ```js
261
261
  module.exports.traverse = ({listStore}) => ({
262
262
  'debugger'(path) {
263
- listStore('x');
263
+ listStore(path);
264
264
  },
265
265
 
266
266
  Program: {
267
267
  exit() {
268
268
  console.log(listStore());
269
269
  // returns
270
- ['x', 'x'];
270
+ [{type: 'DebuggerStatement'}, {type: 'DebuggerStatement'}];
271
271
  // for code
272
272
  'debugger; debugger';
273
273
  },
@@ -4,7 +4,11 @@ const getPath = (item) => item.path || item;
4
4
 
5
5
  module.exports.getPath = getPath;
6
6
  module.exports.getPosition = (path, shebang) => {
7
- const {node} = getPath(path);
7
+ const parsedPath = getPath(path);
8
+
9
+ validatePath(parsedPath);
10
+
11
+ const {node} = parsedPath;
8
12
  const {loc} = node;
9
13
 
10
14
  if (!loc)
@@ -24,3 +28,7 @@ module.exports.getPosition = (path, shebang) => {
24
28
  };
25
29
  };
26
30
 
31
+ function validatePath(path) {
32
+ if (!path.node)
33
+ throw Error(`☝️ Looks like 'push' called without a 'path' argument.`);
34
+ }
package/lib/index.js CHANGED
@@ -65,8 +65,10 @@ function runWithMerge({ast, fix, shebang, template, pluginsTraverse, merge}) {
65
65
  traverse(ast, visitor);
66
66
 
67
67
  const places = [];
68
+
68
69
  for (const [rule, pull] of entries) {
69
70
  const items = pull();
71
+
70
72
  for (const {message, position} of items) {
71
73
  places.push({
72
74
  rule,
package/lib/store.js CHANGED
@@ -8,21 +8,21 @@ const {
8
8
 
9
9
  const toArray = (a) => Array.from(a);
10
10
 
11
- module.exports.listStore = (list = []) => {
11
+ module.exports.listStore = (list = new Set()) => {
12
12
  const fn = (...args) => {
13
13
  if (!args.length)
14
- return list;
14
+ return Array.from(list);
15
15
 
16
16
  const [a] = args;
17
- list.push(a);
17
+ list.add(a);
18
18
 
19
- return list;
19
+ return Array.from(list);
20
20
  };
21
21
 
22
22
  fn.clear = () => {
23
23
  const a = list;
24
- list = [];
25
- return a;
24
+ list = new Set();
25
+ return Array.from(a);
26
26
  };
27
27
 
28
28
  return fn;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/engine-runner",
3
- "version": "13.2.1",
3
+ "version": "13.4.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "run putout plugins",
@@ -28,7 +28,7 @@
28
28
  "@babel/types": "^7.12.7",
29
29
  "@putout/compare": "^9.0.0",
30
30
  "@putout/engine-parser": "^5.0.0",
31
- "@putout/operate": "^7.0.0",
31
+ "@putout/operate": "^8.0.0",
32
32
  "debug": "^4.1.1",
33
33
  "jessy": "^3.0.0",
34
34
  "nessy": "^4.0.0",