@putout/plugin-esm 6.0.0 → 6.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
@@ -25,6 +25,7 @@ npm i putout @putout/plugin-esm -D
25
25
  - ✅ [group-imports-by-source](#group-imports-by-source);
26
26
  - ✅ [merge-duplicate-imports](#merge-duplicate-imports);
27
27
  - ✅ [merge-declaration-with-export](#merge-declaration-with-export);
28
+ - ✅ [merge-export-declarations](#merge-export-declarations);
28
29
  - ✅ [remove-quotes-from-import-assertions](#remove-quotes-from-import-assertions);
29
30
  - ✅ [remove-empty-import](#remove-empty-import);
30
31
  - ✅ [remove-empty-export](#remove-empty-export);
@@ -47,6 +48,7 @@ npm i putout @putout/plugin-esm -D
47
48
  "esm/group-imports-by-source": "on",
48
49
  "esm/merge-duplicate-imports": "on",
49
50
  "esm/merge-declaration-with-export": "off",
51
+ "esm/merge-export-declaration": "off",
50
52
  "esm/remove-quotes-from-import-assertions": "on",
51
53
  "esm/remove-empty-export": "on",
52
54
  "esm/remove-empty-import": ["on", {
@@ -160,6 +162,30 @@ export const {
160
162
  } = createRemoveFiles(['*.swp', '*.swo']);
161
163
  ```
162
164
 
165
+ ### merge-export-declarations
166
+
167
+ Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/d3e490352bd4a98033de89db670b4737/3ff4803578bf39f8587cb578a103e5d92dd92050).
168
+
169
+ #### ❌ Example of incorrect code
170
+
171
+ ```js
172
+ export {
173
+ loadPlugins,
174
+ };
175
+ export {
176
+ loadPluginsAsync,
177
+ };
178
+ ```
179
+
180
+ #### ❌ Example of incorrect code
181
+
182
+ ```js
183
+ export {
184
+ loadPlugins,
185
+ loadPluginsAsync,
186
+ };
187
+ ```
188
+
163
189
  ### remove-useless-export-specifiers
164
190
 
165
191
  Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/e5c3ea469437ade0f4467323dcec9a36/7c298c7078b004ae3aba2a29e38579bf8f48a098).
package/lib/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import * as mergeExportDeclarations from './merge-export-declarations/index.js';
1
2
  import * as removeUselessExportSpecifiers from './remove-useless-export-specifiers/index.js';
2
3
  import * as mergeDeclarationWithExport from './merge-declaration-with-export/index.js';
3
4
  import * as applyNamespaceImportToFile from './apply-namespace-import-to-file/index.js';
@@ -28,4 +29,5 @@ export const rules = {
28
29
  'apply-namespace-import-to-file': ['off', applyNamespaceImportToFile],
29
30
  'merge-declaration-with-export': mergeDeclarationWithExport,
30
31
  'remove-useless-export-specifiers': removeUselessExportSpecifiers,
32
+ 'merge-export-declarations': mergeExportDeclarations,
31
33
  };
@@ -0,0 +1,45 @@
1
+ import {operator, types} from 'putout';
2
+
3
+ const {isExportNamedDeclaration} = types;
4
+ const {remove} = operator;
5
+
6
+ export const report = () => `Merge export declarations`;
7
+
8
+ export const fix = ({path, count, exports}) => {
9
+ const all = [];
10
+
11
+ for (const [index, path] of exports.entries()) {
12
+ const {node} = path;
13
+ const {specifiers} = node;
14
+
15
+ all.push(...specifiers);
16
+
17
+ if (index < count - 1)
18
+ remove(path);
19
+ }
20
+
21
+ path.node.specifiers = all;
22
+ };
23
+
24
+ export const traverse = ({push}) => ({
25
+ Program(path) {
26
+ const exports = path.get('body').filter(hasSpecifiers);
27
+ const count = exports.length;
28
+
29
+ if (count < 2)
30
+ return;
31
+
32
+ push({
33
+ path: exports.at(-1),
34
+ exports,
35
+ count,
36
+ });
37
+ },
38
+ });
39
+
40
+ function hasSpecifiers(path) {
41
+ if (!isExportNamedDeclaration(path))
42
+ return false;
43
+
44
+ return path.node.specifiers.length;
45
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-esm",
3
- "version": "6.0.0",
3
+ "version": "6.1.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",
@@ -40,7 +40,7 @@
40
40
  "@putout/eslint-flat": "^3.0.0",
41
41
  "@putout/plugin-declare": "*",
42
42
  "@putout/plugin-declare-before-reference": "*",
43
- "@putout/plugin-merge-destructuring-properties": "*",
43
+ "@putout/plugin-destructuring": "*",
44
44
  "@putout/plugin-nodejs": "*",
45
45
  "@putout/plugin-putout": "*",
46
46
  "@putout/plugin-reuse-duplicate-init": "*",
@@ -48,9 +48,9 @@
48
48
  "@putout/plugin-typescript": "*",
49
49
  "@putout/test": "^14.0.0",
50
50
  "c8": "^10.0.0",
51
- "eslint": "v10.0.0-alpha.0",
51
+ "eslint": "^10.0.0-alpha.0",
52
52
  "eslint-plugin-n": "^17.0.0",
53
- "eslint-plugin-putout": "^28.0.0",
53
+ "eslint-plugin-putout": "^29.0.0",
54
54
  "madrun": "^11.0.0",
55
55
  "montag": "^1.2.1",
56
56
  "nodemon": "^3.0.1",