@putout/plugin-esm 5.2.0 → 5.3.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.
@@ -1,7 +1,8 @@
1
1
  import {parseImportSpecifiers} from 'parse-import-specifiers';
2
- import {operator} from 'putout';
2
+ import {operator, types} from 'putout';
3
3
 
4
4
  const {insertBefore, remove} = operator;
5
+ const {isImportDeclaration} = types;
5
6
 
6
7
  export const report = () => `Sort imports by specifiers count`;
7
8
 
@@ -12,44 +13,52 @@ export const fix = ({path, nextPath}) => {
12
13
  };
13
14
 
14
15
  export const traverse = ({push}) => ({
15
- ImportDeclaration(path) {
16
- const {node} = path;
17
- const {source, specifiers} = node;
18
- const {imports} = parseImportSpecifiers(specifiers);
16
+ Program(mainPath) {
17
+ const paths = mainPath.get('body').filter(isImportDeclaration);
19
18
 
20
- if (imports.length < 4)
21
- return;
22
-
23
- const nextPath = path.getNextSibling();
24
-
25
- if (!nextPath.isImportDeclaration())
26
- return;
27
-
28
- if (nextPath.node.specifiers.length !== 1)
29
- return;
30
-
31
- const first = source.value;
32
- const second = nextPath.node.source.value;
33
-
34
- const is = isExcluded(first, second, {
35
- direct: [
36
- ['node:', 'node:'],
37
- ['#', '#'],
38
- ],
39
- reversed: [
40
- ['./', './'],
41
- ['../', '../'],
42
- ['#', '#'],
43
- ],
44
- });
45
-
46
- if (is)
47
- return;
48
-
49
- push({
50
- path,
51
- nextPath,
52
- });
19
+ for (const path of paths) {
20
+ const {node} = path;
21
+
22
+ if (!node)
23
+ continue;
24
+
25
+ const {source, specifiers} = node;
26
+ const {imports} = parseImportSpecifiers(specifiers);
27
+
28
+ if (imports.length < 4)
29
+ continue;
30
+
31
+ const nextPath = path.getNextSibling();
32
+
33
+ if (!nextPath.isImportDeclaration())
34
+ continue;
35
+
36
+ if (nextPath.node.specifiers.length !== 1)
37
+ continue;
38
+
39
+ const first = source.value;
40
+ const second = nextPath.node.source.value;
41
+
42
+ const is = isExcluded(first, second, {
43
+ direct: [
44
+ ['node:', 'node:'],
45
+ ['#', '#'],
46
+ ],
47
+ reversed: [
48
+ ['./', './'],
49
+ ['../', '../'],
50
+ ['#', '#'],
51
+ ],
52
+ });
53
+
54
+ if (is)
55
+ continue;
56
+
57
+ push({
58
+ path,
59
+ nextPath,
60
+ });
61
+ }
53
62
  },
54
63
  });
55
64
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-esm",
3
- "version": "5.2.0",
3
+ "version": "5.3.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",
@@ -48,7 +48,7 @@
48
48
  "@putout/plugin-typescript": "*",
49
49
  "@putout/test": "^14.0.0",
50
50
  "c8": "^10.0.0",
51
- "eslint": "^9.0.0",
51
+ "eslint": "v10.0.0-alpha.0",
52
52
  "eslint-plugin-n": "^17.0.0",
53
53
  "eslint-plugin-putout": "^28.0.0",
54
54
  "madrun": "^11.0.0",