@putout/plugin-esm 5.1.0 → 5.2.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
@@ -20,6 +20,7 @@ npm i putout @putout/plugin-esm -D
20
20
 
21
21
  - ✅ [add-index-to-import](#add-index-to-import);
22
22
  - ✅ [apply-export-from](#apply-export-from);
23
+ - ✅ [convert-assert-to-with](#convert-assert-to-with);
23
24
  - ✅ [declare-imports-first](#declare-imports-first);
24
25
  - ✅ [group-imports-by-source](#group-imports-by-source);
25
26
  - ✅ [merge-duplicate-imports](#merge-duplicate-imports);
@@ -69,8 +70,8 @@ Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/b7c4897107
69
70
  #### ❌ Example of incorrect code
70
71
 
71
72
  ```js
72
- import insertRust from './insert-rust.js';
73
- import addAction from './add-action.js';
73
+ import insertRust from './insert-rust';
74
+ import addAction from './add-action';
74
75
 
75
76
  export const rules = {};
76
77
  ```
@@ -23,54 +23,51 @@ export const fix = ({grouped}) => {
23
23
  replaceWithMultiple(first, nodes);
24
24
  };
25
25
 
26
- export const traverse = ({pathStore, push}) => ({
27
- ImportDeclaration: pathStore,
28
- Program: {
29
- exit(path) {
30
- const external = [];
31
- const internal = [];
32
- const builtin = [];
33
- const hashed = [];
34
- const all = pathStore().filter(isImportDeclaration);
26
+ export const traverse = ({push}) => ({
27
+ Program(path) {
28
+ const external = [];
29
+ const internal = [];
30
+ const builtin = [];
31
+ const hashed = [];
32
+ const all = path.get('body').filter(isImportDeclaration);
33
+
34
+ if (!all.length)
35
+ return;
36
+
37
+ for (const current of all) {
38
+ const {value} = current.node.source;
35
39
 
36
- if (!all.length)
37
- return;
38
-
39
- for (const current of all) {
40
- const {value} = current.node.source;
41
-
42
- if (value.startsWith('.')) {
43
- internal.push(current);
44
- continue;
45
- }
46
-
47
- if (value.startsWith('node:')) {
48
- builtin.push(current);
49
- continue;
50
- }
51
-
52
- if (value.startsWith('#')) {
53
- hashed.push(current);
54
- continue;
55
- }
56
-
57
- external.push(current);
40
+ if (value.startsWith('.')) {
41
+ internal.push(current);
42
+ continue;
58
43
  }
59
44
 
60
- const grouped = [
61
- ...builtin,
62
- ...external,
63
- ...hashed,
64
- ...internal,
65
- ];
45
+ if (value.startsWith('node:')) {
46
+ builtin.push(current);
47
+ continue;
48
+ }
66
49
 
67
- if (isDeepStrictEqual(all, grouped))
68
- return;
50
+ if (value.startsWith('#')) {
51
+ hashed.push(current);
52
+ continue;
53
+ }
69
54
 
70
- push({
71
- path,
72
- grouped,
73
- });
74
- },
55
+ external.push(current);
56
+ }
57
+
58
+ const grouped = [
59
+ ...builtin,
60
+ ...external,
61
+ ...hashed,
62
+ ...internal,
63
+ ];
64
+
65
+ if (isDeepStrictEqual(all, grouped))
66
+ return;
67
+
68
+ push({
69
+ path,
70
+ grouped,
71
+ });
75
72
  },
76
73
  });
@@ -5,6 +5,7 @@ const {
5
5
  replaceWith,
6
6
  compare,
7
7
  } = operator;
8
+
8
9
  const {
9
10
  variableDeclaration,
10
11
  isVariableDeclarator,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-esm",
3
- "version": "5.1.0",
3
+ "version": "5.2.0",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout plugin improves ability to transform ESM code",