@putout/plugin-esm 5.3.1 → 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 +27 -1
- package/lib/convert-assert-to-with/index.js +35 -11
- package/lib/index.js +2 -0
- package/lib/merge-export-declarations/index.js +45 -0
- package/package.json +5 -5
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).
|
|
@@ -362,7 +388,7 @@ Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/9f85897b9
|
|
|
362
388
|
|
|
363
389
|
#### ❌ Example of incorrect code
|
|
364
390
|
|
|
365
|
-
```
|
|
391
|
+
```
|
|
366
392
|
import json from './foo.json' assert {
|
|
367
393
|
type: 'json',
|
|
368
394
|
};
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {operator, types} from 'putout';
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
importAttribute,
|
|
5
|
+
identifier,
|
|
6
|
+
} = types;
|
|
7
|
+
|
|
8
|
+
const {compare, remove} = operator;
|
|
4
9
|
|
|
5
10
|
export const report = () => `Use 'with' instead of 'assert'`;
|
|
6
11
|
|
|
@@ -10,19 +15,38 @@ export const include = () => [
|
|
|
10
15
|
];
|
|
11
16
|
|
|
12
17
|
export const fix = (path) => {
|
|
13
|
-
if (path.
|
|
14
|
-
|
|
18
|
+
if (path.isImportExpression()) {
|
|
19
|
+
path.node.options.properties[0].key.name = 'with';
|
|
15
20
|
return;
|
|
16
21
|
}
|
|
17
22
|
|
|
18
|
-
|
|
23
|
+
const next = path.getNextSibling();
|
|
24
|
+
const nextNext = next.getNextSibling();
|
|
25
|
+
const nextNextNext = nextNext.getNextSibling();
|
|
26
|
+
const {body} = nextNext.node.body[0];
|
|
27
|
+
|
|
28
|
+
remove(next);
|
|
29
|
+
remove(nextNext);
|
|
30
|
+
|
|
31
|
+
if (nextNextNext.isEmptyStatement())
|
|
32
|
+
remove(nextNextNext);
|
|
33
|
+
|
|
34
|
+
path.node.attributes = [
|
|
35
|
+
importAttribute(identifier('type'), body.expression),
|
|
36
|
+
];
|
|
19
37
|
};
|
|
20
38
|
|
|
21
39
|
export const filter = (path) => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
40
|
+
if (path.isImportDeclaration()) {
|
|
41
|
+
const next = path.getNextSibling();
|
|
42
|
+
|
|
43
|
+
if (!compare(next, 'assert;'))
|
|
44
|
+
return false;
|
|
45
|
+
|
|
46
|
+
const nextNext = next.getNextSibling();
|
|
47
|
+
|
|
48
|
+
return compare(nextNext, '{type: "__";}');
|
|
49
|
+
}
|
|
26
50
|
|
|
27
|
-
return
|
|
51
|
+
return path.isImportExpression();
|
|
28
52
|
};
|
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": "
|
|
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-
|
|
43
|
+
"@putout/plugin-destructuring": "*",
|
|
44
44
|
"@putout/plugin-nodejs": "*",
|
|
45
45
|
"@putout/plugin-putout": "*",
|
|
46
46
|
"@putout/plugin-reuse-duplicate-init": "*",
|
|
@@ -48,16 +48,16 @@
|
|
|
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",
|
|
57
57
|
"supertape": "^11.0.3"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
|
-
"putout": ">=
|
|
60
|
+
"putout": ">=41"
|
|
61
61
|
},
|
|
62
62
|
"license": "MIT",
|
|
63
63
|
"engines": {
|