@putout/plugin-esm 4.4.0 → 4.5.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 +17 -1
- package/lib/index.js +2 -0
- package/lib/remove-useless-export-specifiers/index.js +29 -0
- package/package.json +1 -1
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,20 @@ export function sum(a, b) {
|
|
|
137
139
|
}
|
|
138
140
|
```
|
|
139
141
|
|
|
142
|
+
|
|
143
|
+
### remove-useless-export-specifiers
|
|
144
|
+
|
|
145
|
+
Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/e5c3ea469437ade0f4467323dcec9a36/7c298c7078b004ae3aba2a29e38579bf8f48a098).
|
|
146
|
+
|
|
147
|
+
#### ❌ Example of incorrect code
|
|
148
|
+
|
|
149
|
+
```diff
|
|
150
|
+
export const hello = () => 'world';
|
|
151
|
+
export const {
|
|
152
|
+
- hello,
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
140
156
|
### declare-imports-first
|
|
141
157
|
|
|
142
158
|
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,29 @@
|
|
|
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
|
+
const binding = scope.bindings[name];
|
|
19
|
+
|
|
20
|
+
if (binding) {
|
|
21
|
+
if (isExportNamedDeclaration(binding.path.parentPath.parentPath))
|
|
22
|
+
push(path);
|
|
23
|
+
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
push(path);
|
|
28
|
+
},
|
|
29
|
+
});
|
package/package.json
CHANGED