@putout/plugin-esm 4.10.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 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": "on",
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
- ### inline-export
111
+ ### merge-declaration-with-export
114
112
 
115
- Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/c9a3983d269745da89c1c7560f3b7fac/3ecb9aa6b910ce3816605bae11c8dd86bdc457e5).
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 inlineExport from './inline-export/index.js';
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,74 @@
1
- import {operator, types} from 'putout';
1
+ import {types, operator} from 'putout';
2
2
 
3
3
  const {remove, replaceWith} = operator;
4
4
  const {
5
- exportNamedDeclaration,
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 = () => `Merge declaration with export`;
14
+ export const report = () => `Inline export`;
15
+ export const include = () => [
16
+ 'export {__exports}',
17
+ ];
11
18
 
12
- export const fix = ({path, bindingPath}) => {
13
- const {parentPath} = bindingPath;
14
- const {node} = parentPath;
19
+ export const filter = (path) => {
20
+ const {scope} = path;
21
+ const specifiers = path.get('specifiers');
15
22
 
16
- replaceWith(parentPath, exportNamedDeclaration(node));
17
- remove(path);
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
- export const traverse = ({push}) => ({
20
- ExportNamedDeclaration(path) {
21
- const {specifiers} = path.node;
22
-
23
- if (!specifiers.length)
24
- return;
25
-
26
- const bindingPaths = [];
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
- }
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;
53
60
 
54
- const [bindingPath] = bindingPaths;
61
+ if (isFunctionDeclaration(bindingPath)) {
62
+ replaceWith(bindingPath, exportNamedDeclaration(bindingPath.node));
63
+ continue;
64
+ }
55
65
 
56
- push({
57
- path,
58
- bindingPath,
59
- });
60
- },
61
- });
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": "4.10.0",
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",
@@ -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
- };