@putout/plugin-esm 2.2.0 → 2.3.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
@@ -18,6 +18,7 @@ npm i putout @putout/plugin-esm -D
18
18
 
19
19
  ## Rules
20
20
 
21
+ - ✅ [apply-export-from](#apply-export-from);
21
22
  - ✅ [declare-imports-first](#declare-imports-first);
22
23
  - ✅ [group-imports-by-source](#group-imports-by-source);
23
24
  - ✅ [merge-duplicate-imports](#merge-duplicate-imports);
@@ -31,6 +32,7 @@ npm i putout @putout/plugin-esm -D
31
32
  ```json
32
33
  {
33
34
  "rules": {
35
+ "esm/apply-export-from": "on",
34
36
  "esm/declare-imports-first": "on",
35
37
  "esm/group-imports-by-source": "on",
36
38
  "esm/merge-duplicate-imports": "on",
@@ -44,6 +46,30 @@ npm i putout @putout/plugin-esm -D
44
46
  }
45
47
  ```
46
48
 
49
+ ## apply-export-from
50
+
51
+ > The `export` declaration is used to export values from a JavaScript module.
52
+ >
53
+ > (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export)
54
+
55
+ Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/c9a3983d269745da89c1c7560f3b7fac/3ecb9aa6b910ce3816605bae11c8dd86bdc457e5).
56
+
57
+ ## ❌ Example of incorrect code
58
+
59
+ ```js
60
+ import * as ns_1 from 'x';
61
+
62
+ export {
63
+ ns_1 as ns,
64
+ };
65
+ ```
66
+
67
+ ## ✅ Example of correct code
68
+
69
+ ```js
70
+ export * as ns from 'x';
71
+ ```
72
+
47
73
  ## declare-imports-first
48
74
 
49
75
  Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/b1c18e5d726afe4ebb69d6b7a7dda82b/8189590815a1b8adb35bb8a846e28228e3c7fadf). For **CommonJS** use [nodejs/declare-after-require](https://github.com/coderaiser/putout/tree/master/packages/plugin-nodejs#declare-after-require).
@@ -0,0 +1,45 @@
1
+ 'use strict';
2
+
3
+ const {types, operator} = require('putout');
4
+
5
+ const {
6
+ compare,
7
+ getTemplateValues,
8
+ remove,
9
+ } = operator;
10
+
11
+ const {ExportNamespaceSpecifier} = types;
12
+
13
+ module.exports.report = () => `Use 'export *' instead of 'import/export'`;
14
+
15
+ const IMPORT = 'import * as __a from "__b"';
16
+
17
+ module.exports.fix = ({path, current}) => {
18
+ const {exported} = current.node.specifiers[0];
19
+
20
+ current.node.source = path.node.source;
21
+
22
+ delete current.node.local;
23
+ delete current.node.exported;
24
+
25
+ current.node.specifiers = [
26
+ ExportNamespaceSpecifier(exported),
27
+ ];
28
+
29
+ remove(path);
30
+ };
31
+
32
+ module.exports.traverse = ({push}) => ({
33
+ [IMPORT]: (path) => {
34
+ const {__a} = getTemplateValues(path, IMPORT);
35
+ const {name} = __a;
36
+
37
+ for (const current of path.parentPath.get('body')) {
38
+ if (compare(current, `export {${name} as __b}`))
39
+ push({
40
+ path,
41
+ current,
42
+ });
43
+ }
44
+ },
45
+ });
package/lib/index.js CHANGED
@@ -8,6 +8,7 @@ const removeEmptyImport = require('./remove-empty-import');
8
8
  const removeEmptyExport = require('./remove-empty-export');
9
9
  const mergeDuplicateImports = require('./merge-duplicate-imports');
10
10
  const convertAssertToWith = require('./convert-assert-to-with');
11
+ const applyExportFrom = require('./apply-export-from');
11
12
 
12
13
  module.exports.rules = {
13
14
  ...mergeDuplicateImports.rules,
@@ -18,4 +19,5 @@ module.exports.rules = {
18
19
  'remove-empty-export': removeEmptyExport,
19
20
  'sort-imports-by-specifiers': sortImportsBySpecifiers,
20
21
  'convert-assert-to-with': convertAssertToWith,
22
+ 'apply-export-from': applyExportFrom,
21
23
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-esm",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout plugin improves ability to transform ESM code",
@@ -45,12 +45,11 @@
45
45
  "@putout/plugin-reuse-duplicate-init": "*",
46
46
  "@putout/plugin-tape": "*",
47
47
  "@putout/plugin-typescript": "*",
48
- "@putout/test": "^11.0.0",
48
+ "@putout/test": "^12.0.0",
49
49
  "c8": "^10.0.0",
50
50
  "eslint": "^9.0.0",
51
51
  "eslint-plugin-n": "^17.0.0",
52
- "eslint-plugin-putout": "^24.0.0",
53
- "lerna": "^6.0.1",
52
+ "eslint-plugin-putout": "^25.0.1",
54
53
  "madrun": "^10.0.0",
55
54
  "montag": "^1.2.1",
56
55
  "nodemon": "^3.0.1",