@putout/plugin-esm 6.1.0 β 6.2.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 +6 -18
- package/lib/apply-export-from/index.js +64 -29
- package/lib/index.js +1 -1
- package/lib/merge-declaration-with-export/index.js +3 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -93,15 +93,19 @@ export const rules = {};
|
|
|
93
93
|
>
|
|
94
94
|
> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export)
|
|
95
95
|
|
|
96
|
-
Check out
|
|
96
|
+
Check out π**Putout Editor**:
|
|
97
|
+
- [#1](https://putout.cloudcmd.io/#/gist/c9a3983d269745da89c1c7560f3b7fac/3ecb9aa6b910ce3816605bae11c8dd86bdc457e5);
|
|
98
|
+
- [#2](https://putout.cloudcmd.io/#/gist/9b2a0a51acf477291a6bbcbe7d846ddf/fa21768506f518ca0a1073beb82a9b8b8f5e7c19);
|
|
97
99
|
|
|
98
100
|
#### β Example of incorrect code
|
|
99
101
|
|
|
100
102
|
```js
|
|
101
103
|
import * as ns_1 from 'x';
|
|
104
|
+
import {createAsyncLoader} from './load/async-loader.js';
|
|
102
105
|
|
|
103
106
|
export {
|
|
104
107
|
ns_1 as ns,
|
|
108
|
+
createAsyncLoader,
|
|
105
109
|
};
|
|
106
110
|
```
|
|
107
111
|
|
|
@@ -109,6 +113,7 @@ export {
|
|
|
109
113
|
|
|
110
114
|
```js
|
|
111
115
|
export * as ns from 'x';
|
|
116
|
+
export {createAsyncLoader} from './load/async-loader.js';
|
|
112
117
|
```
|
|
113
118
|
|
|
114
119
|
### merge-declaration-with-export
|
|
@@ -117,22 +122,6 @@ Checkout in π[**Putout Editor**](https://putout.cloudcmd.io/#/gist/3fad517d76
|
|
|
117
122
|
|
|
118
123
|
#### β Example of incorrect code
|
|
119
124
|
|
|
120
|
-
```js
|
|
121
|
-
const {
|
|
122
|
-
report,
|
|
123
|
-
fix,
|
|
124
|
-
scan,
|
|
125
|
-
} = createRemoveFiles(['*.swp', '*.swo']);
|
|
126
|
-
|
|
127
|
-
export {
|
|
128
|
-
report,
|
|
129
|
-
fix,
|
|
130
|
-
scan,
|
|
131
|
-
};
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
#### β Example of incorrect code
|
|
135
|
-
|
|
136
125
|
```js
|
|
137
126
|
const stack = [];
|
|
138
127
|
|
|
@@ -287,7 +276,6 @@ import test, {stub} from 'supertape';
|
|
|
287
276
|
#### rename
|
|
288
277
|
|
|
289
278
|
Checkout in π[**Putout Editor**](https://putout.cloudcmd.io/#/gist/6604936dec6b1eed8ce0d143f2962f15/17b310a6e4d85b0b8615a8b91d0e27414e8af291).
|
|
290
|
-
|
|
291
279
|
To disable use:
|
|
292
280
|
|
|
293
281
|
```json
|
|
@@ -1,43 +1,78 @@
|
|
|
1
1
|
import {types, operator} from 'putout';
|
|
2
2
|
|
|
3
3
|
const {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
isExportSpecifier,
|
|
5
|
+
isImportSpecifier,
|
|
6
|
+
exportNamedDeclaration,
|
|
7
|
+
exportNamespaceSpecifier,
|
|
8
|
+
isImportNamespaceSpecifier,
|
|
9
|
+
} = types;
|
|
8
10
|
|
|
9
|
-
const {
|
|
11
|
+
const {values} = Object;
|
|
12
|
+
const {remove, insertAfter} = operator;
|
|
10
13
|
|
|
11
|
-
export const report = () => `Use 'export
|
|
14
|
+
export const report = () => `Use 'export from' instead of 'import' + 'export'`;
|
|
12
15
|
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
current.node.source = path.node.source;
|
|
19
|
-
|
|
20
|
-
delete current.node.local;
|
|
21
|
-
delete current.node.exported;
|
|
22
|
-
|
|
23
|
-
current.node.specifiers = [
|
|
24
|
-
exportNamespaceSpecifier(exported),
|
|
25
|
-
];
|
|
16
|
+
export const fix = ({path, reference}) => {
|
|
17
|
+
const {parentPath} = path;
|
|
18
|
+
const parentReference = reference.parentPath;
|
|
19
|
+
const exportNode = createExport(path, parentReference);
|
|
26
20
|
|
|
27
|
-
|
|
21
|
+
insertAfter(parentPath, exportNode);
|
|
22
|
+
removeSpecifier(path);
|
|
23
|
+
removeSpecifier(parentReference);
|
|
28
24
|
};
|
|
29
25
|
|
|
30
26
|
export const traverse = ({push}) => ({
|
|
31
|
-
|
|
32
|
-
const {
|
|
33
|
-
const
|
|
27
|
+
Program(path) {
|
|
28
|
+
const {bindings} = path.scope;
|
|
29
|
+
const imports = values(bindings).filter(isExported);
|
|
34
30
|
|
|
35
|
-
for (const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
31
|
+
for (const {path, referencePaths} of imports) {
|
|
32
|
+
const [reference] = referencePaths;
|
|
33
|
+
|
|
34
|
+
push({
|
|
35
|
+
path,
|
|
36
|
+
reference,
|
|
37
|
+
});
|
|
41
38
|
}
|
|
42
39
|
},
|
|
43
40
|
});
|
|
41
|
+
|
|
42
|
+
function isExported(binding) {
|
|
43
|
+
const {
|
|
44
|
+
path,
|
|
45
|
+
references,
|
|
46
|
+
referencePaths,
|
|
47
|
+
} = binding;
|
|
48
|
+
|
|
49
|
+
if (references !== 1)
|
|
50
|
+
return false;
|
|
51
|
+
|
|
52
|
+
if (!isImportSpecifier(path) && !isImportNamespaceSpecifier(path))
|
|
53
|
+
return false;
|
|
54
|
+
|
|
55
|
+
const [refPath] = referencePaths;
|
|
56
|
+
|
|
57
|
+
return isExportSpecifier(refPath.parentPath);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function removeSpecifier(path) {
|
|
61
|
+
if (path.parentPath.node.specifiers.length === 1)
|
|
62
|
+
remove(path.parentPath);
|
|
63
|
+
else
|
|
64
|
+
remove(path);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function createExport(path, parentReference) {
|
|
68
|
+
const {parentPath} = path;
|
|
69
|
+
const {source} = parentPath.node;
|
|
70
|
+
|
|
71
|
+
if (isImportSpecifier(path))
|
|
72
|
+
return exportNamedDeclaration(null, [parentReference.node], source);
|
|
73
|
+
|
|
74
|
+
const {exported} = parentReference.node;
|
|
75
|
+
const specifier = exportNamespaceSpecifier(exported);
|
|
76
|
+
|
|
77
|
+
return exportNamedDeclaration(null, [specifier], source);
|
|
78
|
+
}
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as applyExportFrom from './apply-export-from/index.js';
|
|
1
2
|
import * as mergeExportDeclarations from './merge-export-declarations/index.js';
|
|
2
3
|
import * as removeUselessExportSpecifiers from './remove-useless-export-specifiers/index.js';
|
|
3
4
|
import * as mergeDeclarationWithExport from './merge-declaration-with-export/index.js';
|
|
@@ -12,7 +13,6 @@ import * as removeEmptyImport from './remove-empty-import/index.js';
|
|
|
12
13
|
import * as removeEmptyExport from './remove-empty-export/index.js';
|
|
13
14
|
import * as mergeDuplicateImports from './merge-duplicate-imports/index.js';
|
|
14
15
|
import * as convertAssertToWith from './convert-assert-to-with/index.js';
|
|
15
|
-
import * as applyExportFrom from './apply-export-from/index.js';
|
|
16
16
|
|
|
17
17
|
export const rules = {
|
|
18
18
|
'add-index-to-import': ['off', addIndexToImport],
|
package/package.json
CHANGED