@putout/plugin-esm 6.0.0 → 6.1.1
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 +26 -17
- package/lib/index.js +2 -0
- package/lib/merge-export-declarations/index.js +45 -0
- package/package.json +4 -4
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", {
|
|
@@ -115,22 +117,6 @@ Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/3fad517d76
|
|
|
115
117
|
|
|
116
118
|
#### ❌ Example of incorrect code
|
|
117
119
|
|
|
118
|
-
```js
|
|
119
|
-
const {
|
|
120
|
-
report,
|
|
121
|
-
fix,
|
|
122
|
-
scan,
|
|
123
|
-
} = createRemoveFiles(['*.swp', '*.swo']);
|
|
124
|
-
|
|
125
|
-
export {
|
|
126
|
-
report,
|
|
127
|
-
fix,
|
|
128
|
-
scan,
|
|
129
|
-
};
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
#### ❌ Example of incorrect code
|
|
133
|
-
|
|
134
120
|
```js
|
|
135
121
|
const stack = [];
|
|
136
122
|
|
|
@@ -160,6 +146,30 @@ export const {
|
|
|
160
146
|
} = createRemoveFiles(['*.swp', '*.swo']);
|
|
161
147
|
```
|
|
162
148
|
|
|
149
|
+
### merge-export-declarations
|
|
150
|
+
|
|
151
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/d3e490352bd4a98033de89db670b4737/3ff4803578bf39f8587cb578a103e5d92dd92050).
|
|
152
|
+
|
|
153
|
+
#### ❌ Example of incorrect code
|
|
154
|
+
|
|
155
|
+
```js
|
|
156
|
+
export {
|
|
157
|
+
loadPlugins,
|
|
158
|
+
};
|
|
159
|
+
export {
|
|
160
|
+
loadPluginsAsync,
|
|
161
|
+
};
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
#### ❌ Example of incorrect code
|
|
165
|
+
|
|
166
|
+
```js
|
|
167
|
+
export {
|
|
168
|
+
loadPlugins,
|
|
169
|
+
loadPluginsAsync,
|
|
170
|
+
};
|
|
171
|
+
```
|
|
172
|
+
|
|
163
173
|
### remove-useless-export-specifiers
|
|
164
174
|
|
|
165
175
|
Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/e5c3ea469437ade0f4467323dcec9a36/7c298c7078b004ae3aba2a29e38579bf8f48a098).
|
|
@@ -261,7 +271,6 @@ import test, {stub} from 'supertape';
|
|
|
261
271
|
#### rename
|
|
262
272
|
|
|
263
273
|
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/6604936dec6b1eed8ce0d143f2962f15/17b310a6e4d85b0b8615a8b91d0e27414e8af291).
|
|
264
|
-
|
|
265
274
|
To disable use:
|
|
266
275
|
|
|
267
276
|
```json
|
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.
|
|
3
|
+
"version": "6.1.1",
|
|
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-
|
|
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": "
|
|
51
|
+
"eslint": "^10.0.0-alpha.0",
|
|
52
52
|
"eslint-plugin-n": "^17.0.0",
|
|
53
|
-
"eslint-plugin-putout": "^
|
|
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",
|