@putout/plugin-esm 4.10.0 → 5.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 +25 -35
- package/lib/index.js +1 -3
- package/lib/merge-declaration-with-export/index.js +71 -51
- package/package.json +2 -2
- package/lib/inline-export/index.js +0 -71
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
|
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,61 +1,81 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {types, operator} from 'putout';
|
|
2
2
|
|
|
3
|
-
const {remove, replaceWith} = operator;
|
|
4
3
|
const {
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
remove,
|
|
5
|
+
replaceWith,
|
|
6
|
+
compare,
|
|
7
|
+
} = operator;
|
|
8
|
+
const {
|
|
9
|
+
variableDeclaration,
|
|
7
10
|
isVariableDeclarator,
|
|
11
|
+
exportNamedDeclaration,
|
|
12
|
+
isFunctionDeclaration,
|
|
13
|
+
isImportSpecifier,
|
|
14
|
+
isImportDefaultSpecifier,
|
|
15
|
+
isExportNamedDeclaration,
|
|
8
16
|
} = types;
|
|
9
17
|
|
|
10
|
-
export const report = () => `
|
|
18
|
+
export const report = () => `Inline export`;
|
|
19
|
+
export const include = () => [
|
|
20
|
+
'export {__exports}',
|
|
21
|
+
];
|
|
11
22
|
|
|
12
|
-
export const
|
|
13
|
-
const {
|
|
14
|
-
const
|
|
23
|
+
export const filter = (path) => {
|
|
24
|
+
const {scope} = path;
|
|
25
|
+
const specifiers = path.get('specifiers');
|
|
15
26
|
|
|
16
|
-
|
|
17
|
-
|
|
27
|
+
for (const spec of specifiers) {
|
|
28
|
+
const {local, exported} = spec.node;
|
|
29
|
+
const {name} = local;
|
|
30
|
+
|
|
31
|
+
if (name !== exported.name)
|
|
32
|
+
return false;
|
|
33
|
+
|
|
34
|
+
const binding = scope.bindings[name];
|
|
35
|
+
|
|
36
|
+
if (!binding)
|
|
37
|
+
return false;
|
|
38
|
+
|
|
39
|
+
const bindingPath = binding.path;
|
|
40
|
+
|
|
41
|
+
if (isExportNamedDeclaration(bindingPath.parentPath.parentPath))
|
|
42
|
+
return false;
|
|
43
|
+
|
|
44
|
+
if (isImportSpecifier(bindingPath))
|
|
45
|
+
return false;
|
|
46
|
+
|
|
47
|
+
if (isImportDefaultSpecifier(bindingPath))
|
|
48
|
+
return false;
|
|
49
|
+
|
|
50
|
+
if (compare(bindingPath, 'const __a = require(__b)'))
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return true;
|
|
18
55
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
for (const spec of specifiers) {
|
|
29
|
-
if (!isExportSpecifier(spec))
|
|
30
|
-
return;
|
|
31
|
-
|
|
32
|
-
const {local, exported} = spec;
|
|
33
|
-
const {name} = local;
|
|
34
|
-
|
|
35
|
-
if (name !== exported.name)
|
|
36
|
-
return;
|
|
37
|
-
|
|
38
|
-
const binding = path.scope.bindings[name];
|
|
39
|
-
|
|
40
|
-
if (!binding)
|
|
41
|
-
return;
|
|
42
|
-
|
|
43
|
-
const {path: bindingPath} = binding;
|
|
44
|
-
|
|
45
|
-
if (!isVariableDeclarator(bindingPath))
|
|
46
|
-
return;
|
|
47
|
-
|
|
48
|
-
if (!bindingPaths.length) {
|
|
49
|
-
bindingPaths.push(bindingPath);
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
56
|
+
|
|
57
|
+
export const fix = (path) => {
|
|
58
|
+
const {scope} = path;
|
|
59
|
+
const specifiers = path.get('specifiers');
|
|
60
|
+
|
|
61
|
+
for (const spec of specifiers) {
|
|
62
|
+
const {local} = spec.node;
|
|
63
|
+
const {name} = local;
|
|
53
64
|
|
|
54
|
-
const
|
|
65
|
+
const binding = scope.bindings[name];
|
|
66
|
+
const bindingPath = binding.path;
|
|
55
67
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
68
|
+
if (isFunctionDeclaration(bindingPath)) {
|
|
69
|
+
replaceWith(bindingPath, exportNamedDeclaration(bindingPath.node));
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (isVariableDeclarator(bindingPath)) {
|
|
74
|
+
const declaration = variableDeclaration('const', [bindingPath.node]);
|
|
75
|
+
replaceWith(bindingPath.parentPath, exportNamedDeclaration(declaration));
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
remove(path);
|
|
81
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-esm",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.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",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"@putout/plugin-reuse-duplicate-init": "*",
|
|
47
47
|
"@putout/plugin-tape": "*",
|
|
48
48
|
"@putout/plugin-typescript": "*",
|
|
49
|
-
"@putout/test": "^
|
|
49
|
+
"@putout/test": "^14.0.0",
|
|
50
50
|
"c8": "^10.0.0",
|
|
51
51
|
"eslint": "^9.0.0",
|
|
52
52
|
"eslint-plugin-n": "^17.0.0",
|
|
@@ -1,71 +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, 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 (isImportSpecifier(bindingPath))
|
|
38
|
-
return false;
|
|
39
|
-
|
|
40
|
-
if (isImportDefaultSpecifier(bindingPath))
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return true;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export const fix = (path) => {
|
|
48
|
-
const {scope} = path;
|
|
49
|
-
const specifiers = path.get('specifiers');
|
|
50
|
-
|
|
51
|
-
for (const spec of specifiers) {
|
|
52
|
-
const {local} = spec.node;
|
|
53
|
-
const {name} = local;
|
|
54
|
-
|
|
55
|
-
const binding = scope.bindings[name];
|
|
56
|
-
const bindingPath = binding.path;
|
|
57
|
-
|
|
58
|
-
if (isFunctionDeclaration(bindingPath)) {
|
|
59
|
-
replaceWith(bindingPath, exportNamedDeclaration(bindingPath.node));
|
|
60
|
-
continue;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (isVariableDeclarator(bindingPath)) {
|
|
64
|
-
const declaration = variableDeclaration('const', [bindingPath.node]);
|
|
65
|
-
replaceWith(bindingPath.parentPath, exportNamedDeclaration(declaration));
|
|
66
|
-
continue;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
remove(path);
|
|
71
|
-
};
|