@putout/plugin-for-of 12.5.0 → 12.5.2

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
@@ -25,6 +25,7 @@ npm i @putout/plugin-for-of
25
25
  - ✅ [for-in-positive](#for-in-positive);
26
26
  - ✅ [for-length](#for-length);
27
27
  - ✅ [for-n](#for-n);
28
+ - ✅ [from-while](#from-while);
28
29
  - ✅ [map](#map);
29
30
  - ✅ [reduce](#reduce);
30
31
  - ✅ [remove-unused-variables](#remove-unused-variables);
@@ -32,9 +33,8 @@ npm i @putout/plugin-for-of
32
33
  - ✅ [remove-useless-array-from](#remove-useless-array-from);
33
34
  - ✅ [remove-useless-variables](#remove-useless-variables);
34
35
  - ✅ [to-for-n](#to-for-n);
35
- - ✅ [from-while](#from-while);
36
36
 
37
- ## Configuration
37
+ ## Config
38
38
 
39
39
  ```json
40
40
  {
@@ -269,15 +269,13 @@ for (const x of Array.from(y)) {}
269
269
  for (const x of y) {}
270
270
  ```
271
271
 
272
- ## for
272
+ ## for-n
273
273
 
274
274
  > The `for` statement creates a loop that consists of three optional expressions, enclosed in parentheses and separated by semicolons, followed by a statement to be executed in the loop.
275
275
  >
276
276
  > (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for)
277
277
 
278
- ### for-n
279
-
280
- #### ❌ Example of incorrect code
278
+ ### ❌ Example of incorrect code
281
279
 
282
280
  ```js
283
281
  const n = items.length;
@@ -288,7 +286,7 @@ for (let i = 0; i < n; i++) {
288
286
  }
289
287
  ```
290
288
 
291
- #### ✅ Example of correct code
289
+ ### ✅ Example of correct code
292
290
 
293
291
  ```js
294
292
  for (const item of items) {
@@ -296,9 +294,9 @@ for (const item of items) {
296
294
  }
297
295
  ```
298
296
 
299
- ### for-length
297
+ ## for-length
300
298
 
301
- #### ❌ Example of incorrect code
299
+ ### ❌ Example of incorrect code
302
300
 
303
301
  ```js
304
302
  for (let i = 0; i < array.length; i++) {
@@ -307,7 +305,7 @@ for (let i = 0; i < array.length; i++) {
307
305
  }
308
306
  ```
309
307
 
310
- #### ✅ Example of correct code
308
+ ### ✅ Example of correct code
311
309
 
312
310
  ```js
313
311
  for (const item of items) {
@@ -315,9 +313,9 @@ for (const item of items) {
315
313
  }
316
314
  ```
317
315
 
318
- ### for-entries
316
+ ## for-entries
319
317
 
320
- #### ❌ Example of incorrect code
318
+ ### ❌ Example of incorrect code
321
319
 
322
320
  ```js
323
321
  for (let i = 0; i < array.length; i++) {
@@ -326,7 +324,7 @@ for (let i = 0; i < array.length; i++) {
326
324
  }
327
325
  ```
328
326
 
329
- #### ✅ Example of correct code
327
+ ### ✅ Example of correct code
330
328
 
331
329
  ```js
332
330
  for (const [i, item] of array.entries()) {
@@ -334,9 +332,9 @@ for (const [i, item] of array.entries()) {
334
332
  }
335
333
  ```
336
334
 
337
- ### for-entries-n
335
+ ## for-entries-n
338
336
 
339
- #### ❌ Example of incorrect code
337
+ ### ❌ Example of incorrect code
340
338
 
341
339
  ```js
342
340
  const n = array.length;
@@ -347,7 +345,7 @@ for (let i = 0; i < n; i++) {
347
345
  }
348
346
  ```
349
347
 
350
- #### ✅ Example of correct code
348
+ ### ✅ Example of correct code
351
349
 
352
350
  ```js
353
351
  for (const [i, item] of array.entries()) {
@@ -381,7 +379,7 @@ for (let i = 0; i < n; i++) {
381
379
  }
382
380
  ```
383
381
 
384
- ### from-while
382
+ ## from-while
385
383
 
386
384
  > The `while` statement creates a loop that executes a specified statement as long as the test condition evaluates to true. The condition is evaluated before executing the statement.
387
385
  >
@@ -389,7 +387,7 @@ for (let i = 0; i < n; i++) {
389
387
 
390
388
  Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/e4faebbc52bc2410425facc557b9acc7/9db52e3880190fe4f898ee6ac2722598073edf01).
391
389
 
392
- #### ❌ Example of incorrect code
390
+ ### ❌ Example of incorrect code
393
391
 
394
392
  ```js
395
393
  let i = 0;
@@ -403,7 +401,7 @@ while (i < node.signature.params.length) {
403
401
  }
404
402
  ```
405
403
 
406
- #### ✅ Example of correct code
404
+ ### ✅ Example of correct code
407
405
 
408
406
  ```js
409
407
  for (const {name} of node.signature.params) {
package/lib/map/index.js CHANGED
@@ -44,7 +44,12 @@ export const match = () => ({
44
44
 
45
45
  return !isArrayPattern(__a);
46
46
  },
47
- '__a = __b.map((__c) => __d)': ({__b}) => !isCallExpression(__b),
47
+ '__a = __b.map((__c) => __d)': ({__a, __b}) => {
48
+ if (compare(__a, __b))
49
+ return false;
50
+
51
+ return !isCallExpression(__b);
52
+ },
48
53
  });
49
54
 
50
55
  export const replace = () => ({
@@ -72,17 +77,6 @@ export const replace = () => ({
72
77
  }
73
78
  }`;
74
79
  },
75
- /*
76
- '__a = __b.map((__c) => __body': ({__a}, path) => {
77
- path.traverse({
78
- ReturnStatement: createReplaceWithPush(__a)
79
- });
80
- return `{
81
- __a = [];
82
- for (const __c of __b) __body;
83
- }`;
84
- },
85
- */
86
80
  '__a = __b.map((__c) => __d)': ({__a, __d}, path) => {
87
81
  if (isBlockStatement(__d)) {
88
82
  path.traverse({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-for-of",
3
- "version": "12.5.0",
3
+ "version": "12.5.2",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout plugin adds ability to apply for...of",