@putout/plugin-esm 4.9.0 → 5.0.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 +37 -39
- package/lib/index.js +1 -3
- package/lib/merge-declaration-with-export/index.js +63 -47
- package/package.json +3 -2
- package/lib/inline-export/index.js +0 -67
package/README.md
CHANGED
|
@@ -29,7 +29,6 @@ npm i putout @putout/plugin-esm -D
|
|
|
29
29
|
- ✅ [remove-empty-export](#remove-empty-export);
|
|
30
30
|
- ✅ [remove-useless-export-specifiers](#remove-useless-export-specifiers);
|
|
31
31
|
- ✅ [sort-imports-by-specifiers](#sort-imports-by-specifiers);
|
|
32
|
-
- ✅ [inline-export](#inline-export);
|
|
33
32
|
|
|
34
33
|
## File rules
|
|
35
34
|
|
|
@@ -46,7 +45,7 @@ npm i putout @putout/plugin-esm -D
|
|
|
46
45
|
"esm/declare-imports-first": "on",
|
|
47
46
|
"esm/group-imports-by-source": "on",
|
|
48
47
|
"esm/merge-duplicate-imports": "on",
|
|
49
|
-
"esm/merge-declaration-with-export": "
|
|
48
|
+
"esm/merge-declaration-with-export": "off",
|
|
50
49
|
"esm/remove-quotes-from-import-assertions": "on",
|
|
51
50
|
"esm/remove-empty-export": "on",
|
|
52
51
|
"esm/remove-empty-import": ["on", {
|
|
@@ -55,7 +54,6 @@ npm i putout @putout/plugin-esm -D
|
|
|
55
54
|
"esm/sort-imports-by-specifiers": "on",
|
|
56
55
|
"esm/resolve-imported-file": "off",
|
|
57
56
|
"esm/apply-namespace-of-file": "off",
|
|
58
|
-
"esm/inline-export": "off",
|
|
59
57
|
"esm/remove-useless-export-specifiers": "off"
|
|
60
58
|
}
|
|
61
59
|
}
|
|
@@ -110,9 +108,25 @@ export {
|
|
|
110
108
|
export * as ns from 'x';
|
|
111
109
|
```
|
|
112
110
|
|
|
113
|
-
###
|
|
111
|
+
### merge-declaration-with-export
|
|
114
112
|
|
|
115
|
-
|
|
113
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/3fad517d76942d0a1f51d7f58a2799af/7a052ab18a31fa382228d6513c412be37091cfb8).
|
|
114
|
+
|
|
115
|
+
#### ❌ Example of incorrect code
|
|
116
|
+
|
|
117
|
+
```js
|
|
118
|
+
const {
|
|
119
|
+
report,
|
|
120
|
+
fix,
|
|
121
|
+
scan,
|
|
122
|
+
} = createRemoveFiles(['*.swp', '*.swo']);
|
|
123
|
+
|
|
124
|
+
export {
|
|
125
|
+
report,
|
|
126
|
+
fix,
|
|
127
|
+
scan,
|
|
128
|
+
};
|
|
129
|
+
```
|
|
116
130
|
|
|
117
131
|
#### ❌ Example of incorrect code
|
|
118
132
|
|
|
@@ -137,6 +151,12 @@ export const stack = [];
|
|
|
137
151
|
export function sum(a, b) {
|
|
138
152
|
i32.add(local.get(), local.get());
|
|
139
153
|
}
|
|
154
|
+
|
|
155
|
+
export const {
|
|
156
|
+
report,
|
|
157
|
+
fix,
|
|
158
|
+
scan,
|
|
159
|
+
} = createRemoveFiles(['*.swp', '*.swo']);
|
|
140
160
|
```
|
|
141
161
|
|
|
142
162
|
### remove-useless-export-specifiers
|
|
@@ -210,36 +230,6 @@ import ss from '../../bb/ss.js';
|
|
|
210
230
|
const c = 5;
|
|
211
231
|
```
|
|
212
232
|
|
|
213
|
-
### merge-declaration-with-export
|
|
214
|
-
|
|
215
|
-
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/3fad517d76942d0a1f51d7f58a2799af/7a052ab18a31fa382228d6513c412be37091cfb8).
|
|
216
|
-
|
|
217
|
-
#### ❌ Example of incorrect code
|
|
218
|
-
|
|
219
|
-
```js
|
|
220
|
-
const {
|
|
221
|
-
report,
|
|
222
|
-
fix,
|
|
223
|
-
scan,
|
|
224
|
-
} = createRemoveFiles(['*.swp', '*.swo']);
|
|
225
|
-
|
|
226
|
-
export {
|
|
227
|
-
report,
|
|
228
|
-
fix,
|
|
229
|
-
scan,
|
|
230
|
-
};
|
|
231
|
-
```
|
|
232
|
-
|
|
233
|
-
##### ✅ Example of correct code
|
|
234
|
-
|
|
235
|
-
```js
|
|
236
|
-
export const {
|
|
237
|
-
report,
|
|
238
|
-
fix,
|
|
239
|
-
scan,
|
|
240
|
-
} = createRemoveFiles(['*.swp', '*.swo']);
|
|
241
|
-
```
|
|
242
|
-
|
|
243
233
|
### merge-duplicate-imports
|
|
244
234
|
|
|
245
235
|
#### join
|
|
@@ -320,13 +310,17 @@ Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/f9f34acddb
|
|
|
320
310
|
#### ❌ Example of incorrect code
|
|
321
311
|
|
|
322
312
|
```js
|
|
323
|
-
import json from './mod.json' with {
|
|
313
|
+
import json from './mod.json' with {
|
|
314
|
+
type: 'json',
|
|
315
|
+
};
|
|
324
316
|
```
|
|
325
317
|
|
|
326
318
|
#### ✅ Example of correct code
|
|
327
319
|
|
|
328
320
|
```js
|
|
329
|
-
import json from './mod.json' with {
|
|
321
|
+
import json from './mod.json' with {
|
|
322
|
+
type: 'json',
|
|
323
|
+
};
|
|
330
324
|
```
|
|
331
325
|
|
|
332
326
|
### sort-imports-by-specifiers
|
|
@@ -368,7 +362,9 @@ Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/9f85897b9
|
|
|
368
362
|
#### ❌ Example of incorrect code
|
|
369
363
|
|
|
370
364
|
```js
|
|
371
|
-
import json from './foo.json' assert {
|
|
365
|
+
import json from './foo.json' assert {
|
|
366
|
+
type: 'json',
|
|
367
|
+
};
|
|
372
368
|
|
|
373
369
|
import('foo.json', {
|
|
374
370
|
assert: {
|
|
@@ -380,7 +376,9 @@ import('foo.json', {
|
|
|
380
376
|
#### ✅ Example of correct code
|
|
381
377
|
|
|
382
378
|
```js
|
|
383
|
-
import json from './foo.json' with {
|
|
379
|
+
import json from './foo.json' with {
|
|
380
|
+
type: 'json',
|
|
381
|
+
};
|
|
384
382
|
|
|
385
383
|
import('foo.json', {
|
|
386
384
|
with: {
|
package/lib/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as removeUselessExportSpecifiers from './remove-useless-export-specifiers/index.js';
|
|
2
|
-
import * as
|
|
2
|
+
import * as mergeDeclarationWithExport from './merge-declaration-with-export/index.js';
|
|
3
3
|
import * as applyNamespaceImportToFile from './apply-namespace-import-to-file/index.js';
|
|
4
4
|
import * as resolveImportedFile from './resolve-imported-file/index.js';
|
|
5
5
|
import * as addIndexToImport from './add-index-to-import/index.js';
|
|
@@ -10,7 +10,6 @@ import * as sortImportsBySpecifiers from './sort-imports-by-specifiers/index.js'
|
|
|
10
10
|
import * as removeEmptyImport from './remove-empty-import/index.js';
|
|
11
11
|
import * as removeEmptyExport from './remove-empty-export/index.js';
|
|
12
12
|
import * as mergeDuplicateImports from './merge-duplicate-imports/index.js';
|
|
13
|
-
import * as mergeDeclarationWithExport from './merge-declaration-with-export/index.js';
|
|
14
13
|
import * as convertAssertToWith from './convert-assert-to-with/index.js';
|
|
15
14
|
import * as applyExportFrom from './apply-export-from/index.js';
|
|
16
15
|
|
|
@@ -28,6 +27,5 @@ export const rules = {
|
|
|
28
27
|
'resolve-imported-file': ['off', resolveImportedFile],
|
|
29
28
|
'apply-namespace-import-to-file': ['off', applyNamespaceImportToFile],
|
|
30
29
|
'merge-declaration-with-export': mergeDeclarationWithExport,
|
|
31
|
-
'inline-export': inlineExport,
|
|
32
30
|
'remove-useless-export-specifiers': removeUselessExportSpecifiers,
|
|
33
31
|
};
|
|
@@ -1,58 +1,74 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {types, operator} from 'putout';
|
|
2
2
|
|
|
3
3
|
const {remove, replaceWith} = operator;
|
|
4
4
|
const {
|
|
5
|
-
|
|
6
|
-
isExportSpecifier,
|
|
5
|
+
variableDeclaration,
|
|
7
6
|
isVariableDeclarator,
|
|
7
|
+
exportNamedDeclaration,
|
|
8
|
+
isFunctionDeclaration,
|
|
9
|
+
isImportSpecifier,
|
|
10
|
+
isImportDefaultSpecifier,
|
|
11
|
+
isExportNamedDeclaration,
|
|
8
12
|
} = types;
|
|
9
13
|
|
|
10
|
-
export const report = () => `
|
|
14
|
+
export const report = () => `Inline export`;
|
|
15
|
+
export const include = () => [
|
|
16
|
+
'export {__exports}',
|
|
17
|
+
];
|
|
11
18
|
|
|
12
|
-
export const
|
|
13
|
-
const {
|
|
14
|
-
const
|
|
19
|
+
export const filter = (path) => {
|
|
20
|
+
const {scope} = path;
|
|
21
|
+
const specifiers = path.get('specifiers');
|
|
15
22
|
|
|
16
|
-
|
|
17
|
-
|
|
23
|
+
for (const spec of specifiers) {
|
|
24
|
+
const {local, exported} = spec.node;
|
|
25
|
+
const {name} = local;
|
|
26
|
+
|
|
27
|
+
if (name !== exported.name)
|
|
28
|
+
return false;
|
|
29
|
+
|
|
30
|
+
const binding = scope.bindings[name];
|
|
31
|
+
|
|
32
|
+
if (!binding)
|
|
33
|
+
return false;
|
|
34
|
+
|
|
35
|
+
const bindingPath = binding.path;
|
|
36
|
+
|
|
37
|
+
if (isExportNamedDeclaration(bindingPath.parentPath.parentPath))
|
|
38
|
+
return false;
|
|
39
|
+
|
|
40
|
+
if (isImportSpecifier(bindingPath))
|
|
41
|
+
return false;
|
|
42
|
+
|
|
43
|
+
if (isImportDefaultSpecifier(bindingPath))
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return true;
|
|
18
48
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return;
|
|
31
|
-
|
|
32
|
-
const {local} = spec;
|
|
33
|
-
|
|
34
|
-
const {name} = local;
|
|
35
|
-
const binding = path.scope.bindings[name];
|
|
36
|
-
|
|
37
|
-
if (!binding)
|
|
38
|
-
return;
|
|
39
|
-
|
|
40
|
-
const {path: bindingPath} = binding;
|
|
41
|
-
|
|
42
|
-
if (!isVariableDeclarator(bindingPath))
|
|
43
|
-
return;
|
|
44
|
-
|
|
45
|
-
if (!bindingPaths.length) {
|
|
46
|
-
bindingPaths.push(bindingPath);
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
49
|
+
|
|
50
|
+
export const fix = (path) => {
|
|
51
|
+
const {scope} = path;
|
|
52
|
+
const specifiers = path.get('specifiers');
|
|
53
|
+
|
|
54
|
+
for (const spec of specifiers) {
|
|
55
|
+
const {local} = spec.node;
|
|
56
|
+
const {name} = local;
|
|
57
|
+
|
|
58
|
+
const binding = scope.bindings[name];
|
|
59
|
+
const bindingPath = binding.path;
|
|
50
60
|
|
|
51
|
-
|
|
61
|
+
if (isFunctionDeclaration(bindingPath)) {
|
|
62
|
+
replaceWith(bindingPath, exportNamedDeclaration(bindingPath.node));
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
52
65
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
bindingPath,
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
66
|
+
if (isVariableDeclarator(bindingPath)) {
|
|
67
|
+
const declaration = variableDeclaration('const', [bindingPath.node]);
|
|
68
|
+
replaceWith(bindingPath.parentPath, exportNamedDeclaration(declaration));
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
remove(path);
|
|
74
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-esm",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.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,6 +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
44
|
"@putout/plugin-nodejs": "*",
|
|
44
45
|
"@putout/plugin-putout": "*",
|
|
45
46
|
"@putout/plugin-reuse-duplicate-init": "*",
|
|
@@ -49,7 +50,7 @@
|
|
|
49
50
|
"c8": "^10.0.0",
|
|
50
51
|
"eslint": "^9.0.0",
|
|
51
52
|
"eslint-plugin-n": "^17.0.0",
|
|
52
|
-
"eslint-plugin-putout": "^
|
|
53
|
+
"eslint-plugin-putout": "^28.0.0",
|
|
53
54
|
"madrun": "^11.0.0",
|
|
54
55
|
"montag": "^1.2.1",
|
|
55
56
|
"nodemon": "^3.0.1",
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import {types, operator} from 'putout';
|
|
2
|
-
|
|
3
|
-
const {remove, replaceWith} = operator;
|
|
4
|
-
const {
|
|
5
|
-
variableDeclaration,
|
|
6
|
-
isVariableDeclarator,
|
|
7
|
-
exportNamedDeclaration,
|
|
8
|
-
isFunctionDeclaration,
|
|
9
|
-
isImportSpecifier,
|
|
10
|
-
isImportDefaultSpecifier,
|
|
11
|
-
} = types;
|
|
12
|
-
|
|
13
|
-
export const report = () => `Inline export`;
|
|
14
|
-
export const include = () => [
|
|
15
|
-
'export {__exports}',
|
|
16
|
-
];
|
|
17
|
-
export const exclude = () => [`export * as __a from '__b'`];
|
|
18
|
-
|
|
19
|
-
export const filter = (path) => {
|
|
20
|
-
const {scope} = path;
|
|
21
|
-
const specifiers = path.get('specifiers');
|
|
22
|
-
|
|
23
|
-
for (const spec of specifiers) {
|
|
24
|
-
const {local} = spec.node;
|
|
25
|
-
const {name} = local;
|
|
26
|
-
const binding = scope.bindings[name];
|
|
27
|
-
|
|
28
|
-
if (!binding)
|
|
29
|
-
return false;
|
|
30
|
-
|
|
31
|
-
const bindingPath = binding.path;
|
|
32
|
-
|
|
33
|
-
if (isImportSpecifier(bindingPath))
|
|
34
|
-
return false;
|
|
35
|
-
|
|
36
|
-
if (isImportDefaultSpecifier(bindingPath))
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return true;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export const fix = (path) => {
|
|
44
|
-
const {scope} = path;
|
|
45
|
-
const specifiers = path.get('specifiers');
|
|
46
|
-
|
|
47
|
-
for (const spec of specifiers) {
|
|
48
|
-
const {local} = spec.node;
|
|
49
|
-
const {name} = local;
|
|
50
|
-
|
|
51
|
-
const binding = scope.bindings[name];
|
|
52
|
-
const bindingPath = binding.path;
|
|
53
|
-
|
|
54
|
-
if (isFunctionDeclaration(bindingPath)) {
|
|
55
|
-
replaceWith(bindingPath, exportNamedDeclaration(bindingPath.node));
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (isVariableDeclarator(bindingPath)) {
|
|
60
|
-
const declaration = variableDeclaration('const', [bindingPath.node]);
|
|
61
|
-
replaceWith(bindingPath.parentPath, exportNamedDeclaration(declaration));
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
remove(path);
|
|
67
|
-
};
|