@putout/plugin-esm 4.4.0 → 4.6.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
@@ -27,6 +27,7 @@ npm i putout @putout/plugin-esm -D
27
27
  - ✅ [remove-quotes-from-import-assertions](#remove-quotes-from-import-assertions);
28
28
  - ✅ [remove-empty-import](#remove-empty-import);
29
29
  - ✅ [remove-empty-export](#remove-empty-export);
30
+ - ✅ [remove-useless-export-specifiers](#remove-useless-export-specifiers);
30
31
  - ✅ [sort-imports-by-specifiers](#sort-imports-by-specifiers);
31
32
  - ✅ [inline-export](#inline-export);
32
33
 
@@ -54,7 +55,8 @@ npm i putout @putout/plugin-esm -D
54
55
  "esm/sort-imports-by-specifiers": "on",
55
56
  "esm/resolve-imported-file": "off",
56
57
  "esm/apply-namespace-of-file": "off",
57
- "esm/inline-export": "off"
58
+ "esm/inline-export": "off",
59
+ "esm/remove-useless-export-specifiers": "off"
58
60
  }
59
61
  }
60
62
  ```
@@ -137,6 +139,19 @@ export function sum(a, b) {
137
139
  }
138
140
  ```
139
141
 
142
+ ### remove-useless-export-specifiers
143
+
144
+ Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/e5c3ea469437ade0f4467323dcec9a36/7c298c7078b004ae3aba2a29e38579bf8f48a098).
145
+
146
+ #### ❌ Example of incorrect code
147
+
148
+ ```diff
149
+ export const hello = () => 'world';
150
+ export const {
151
+ - hello,
152
+ }
153
+ ```
154
+
140
155
  ### declare-imports-first
141
156
 
142
157
  Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/b1c18e5d726afe4ebb69d6b7a7dda82b/8189590815a1b8adb35bb8a846e28228e3c7fadf). For **CommonJS** use [nodejs/declare-after-require](https://github.com/coderaiser/putout/tree/master/packages/plugin-nodejs#declare-after-require).
package/lib/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import * as removeUselessExportSpecifiers from './remove-useless-export-specifiers/index.js';
1
2
  import * as inlineExport from './inline-export/index.js';
2
3
  import * as applyNamespaceImportToFile from './apply-namespace-import-to-file/index.js';
3
4
  import * as resolveImportedFile from './resolve-imported-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
  'inline-export': inlineExport,
32
+ 'remove-useless-export-specifiers': removeUselessExportSpecifiers,
31
33
  };
@@ -0,0 +1,32 @@
1
+ import {types, operator} from 'putout';
2
+
3
+ const {remove} = operator;
4
+ const {isExportNamedDeclaration} = types;
5
+
6
+ export const report = () => `Avoid useless export specifier`;
7
+
8
+ export const fix = (path) => {
9
+ remove(path);
10
+ };
11
+
12
+ export const traverse = ({push}) => ({
13
+ ExportSpecifier(path) {
14
+ const {node, scope} = path;
15
+ const {local} = node;
16
+ const {name} = local;
17
+
18
+ if (path.parentPath.node.source)
19
+ return;
20
+
21
+ const binding = scope.bindings[name];
22
+
23
+ if (binding) {
24
+ if (isExportNamedDeclaration(binding.path.parentPath.parentPath))
25
+ push(path);
26
+
27
+ return;
28
+ }
29
+
30
+ push(path);
31
+ },
32
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-esm",
3
- "version": "4.4.0",
3
+ "version": "4.6.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",
@@ -49,7 +49,7 @@
49
49
  "c8": "^10.0.0",
50
50
  "eslint": "^9.0.0",
51
51
  "eslint-plugin-n": "^17.0.0",
52
- "eslint-plugin-putout": "^26.0.0",
52
+ "eslint-plugin-putout": "^27.0.0",
53
53
  "madrun": "^11.0.0",
54
54
  "montag": "^1.2.1",
55
55
  "nodemon": "^3.0.1",