@putout/plugin-esm 1.0.1 → 1.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 CHANGED
@@ -8,7 +8,6 @@
8
8
  >
9
9
  > (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import)
10
10
 
11
-
12
11
  🐊[**Putout**](https://github.com/coderaiser/putout) plugin adds ability to transform to new **Node.js** API and apply best practices.
13
12
 
14
13
  ## Install
@@ -173,12 +172,11 @@ console.log(putout);
173
172
  -import 'abc';
174
173
  ```
175
174
 
176
-
177
175
  ## remove-quotes-from-import-assertions
178
176
 
179
177
  Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/f9f34acddbefba0ded53225ca10fa44e/7b4dba44602b9b2d28fe3a98989474a4b0d8d73d).
180
178
 
181
- ## ❌ Example of incorrect code
179
+ ### ❌ Example of incorrect code
182
180
 
183
181
  ```js
184
182
  import json from './mod.json' with { type: 'json' };
@@ -194,7 +192,7 @@ import json from './mod.json' with { type: 'json' };
194
192
 
195
193
  Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/521e2ff199243a7ce1f65db7140c272e/28c0588281286f8a6765b8aa2ecabbfcde2973a7).
196
194
 
197
- ## ❌ Example of incorrect code
195
+ ### ❌ Example of incorrect code
198
196
 
199
197
  ```js
200
198
  import {
@@ -206,7 +204,7 @@ import {
206
204
  import a1 from 'a1';
207
205
  ```
208
206
 
209
- ## ✅ Example of correct code
207
+ ### ✅ Example of correct code
210
208
 
211
209
  ```js
212
210
  import a1 from 'a1';
@@ -218,6 +216,38 @@ import {
218
216
  } from 'd';
219
217
  ```
220
218
 
219
+ ## convert-assert-to-with
220
+
221
+ > This feature would ideally use the `with` keyword to denote attributes, but there are existing implementations based on a previous version of the proposal using the `assert` keyword. Due to potential web compatibility risks, the proposal still includes `assert` marked as deprecated. Usage of the old syntax is discouraged, and its removal is being investigated.
222
+ >
223
+ > (c) [tc39](https://tc39.es/proposal-import-attributes/)
224
+
225
+ Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/9f85897b998c6458efc19db6a5414b79/57ef7cdd113c7a0087e0f7a6e70522f60baa04f4).
226
+
227
+ ## ❌ Example of incorrect code
228
+
229
+ ```js
230
+ import json from './foo.json' assert { type: 'json' };
231
+
232
+ import('foo.json', {
233
+ assert: {
234
+ type: 'json',
235
+ },
236
+ });
237
+ ```
238
+
239
+ ## ✅ Example of correct code
240
+
241
+ ```js
242
+ import json from './foo.json' with { type: 'json' };
243
+
244
+ import('foo.json', {
245
+ with: {
246
+ type: 'json',
247
+ },
248
+ });
249
+ ```
250
+
221
251
  ## License
222
252
 
223
253
  MIT
@@ -0,0 +1,30 @@
1
+ 'use strict';
2
+
3
+ const setImportType = (path, type) => {
4
+ path.node.options.properties[0].key.name = type;
5
+ };
6
+
7
+ module.exports.report = () => `Use 'with' instead of 'assert'`;
8
+
9
+ module.exports.include = () => [
10
+ 'ImportDeclaration',
11
+ 'import(__a, {assert: {type: "json"}})',
12
+ ];
13
+
14
+ module.exports.fix = (path) => {
15
+ if (path.isImportDeclaration()) {
16
+ delete path.node.extra.deprecatedAssertSyntax;
17
+ return;
18
+ }
19
+
20
+ setImportType(path, 'with');
21
+ };
22
+
23
+ module.exports.filter = (path) => {
24
+ const {extra} = path.node;
25
+
26
+ if (path.isImportDeclaration())
27
+ return extra?.deprecatedAssertSyntax;
28
+
29
+ return true;
30
+ };
package/lib/index.js CHANGED
@@ -2,20 +2,20 @@
2
2
 
3
3
  const declareImportsFirst = require('./declare-imports-first');
4
4
  const groupImportsBySource = require('./group-imports-by-source');
5
- const mergeDuplicateImportsJoin = require('./merge-duplicate-imports-join');
6
- const mergeDuplicateImportsRename = require('./merge-duplicate-imports-rename');
7
5
  const removeQuotesFromImportAssertions = require('./remove-quotes-from-import-assertions');
8
6
  const sortImportsBySpecifiers = require('./sort-imports-by-specifiers');
9
7
  const removeEmptyImport = require('./remove-empty-import');
10
8
  const removeEmptyExport = require('./remove-empty-export');
9
+ const mergeDuplicateImports = require('./merge-duplicate-imports');
10
+ const convertAssertToWith = require('./convert-assert-to-with');
11
11
 
12
12
  module.exports.rules = {
13
+ ...mergeDuplicateImports.rules,
13
14
  'declare-imports-first': declareImportsFirst,
14
15
  'group-imports-by-source': groupImportsBySource,
15
- 'merge-duplicate-imports-join': mergeDuplicateImportsJoin,
16
- 'merge-duplicate-imports-rename': mergeDuplicateImportsRename,
17
16
  'remove-quotes-from-import-assertions': removeQuotesFromImportAssertions,
18
17
  'remove-empty-import': removeEmptyImport,
19
18
  'remove-empty-export': removeEmptyExport,
20
19
  'sort-imports-by-specifiers': sortImportsBySpecifiers,
20
+ 'convert-assert-to-with': convertAssertToWith,
21
21
  };
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ const mergeDuplicateImportsJoin = require('./join');
4
+ const mergeDuplicateImportsRename = require('./rename');
5
+
6
+ module.exports.rules = {
7
+ 'merge-duplicate-imports-join': mergeDuplicateImportsJoin,
8
+ 'merge-duplicate-imports-rename': mergeDuplicateImportsRename,
9
+ };
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@putout/plugin-esm",
3
- "version": "1.0.1",
3
+ "version": "1.2.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",
7
7
  "homepage": "https://github.com/coderaiser/putout/tree/master/packages/plugin-esm#readme",
8
8
  "main": "lib/index.js",
9
9
  "exports": {
10
- ".": "./lib/index.js"
10
+ ".": "./lib/index.js",
11
+ "./merge-duplicate-imports": "./lib/merge-duplicate-imports/index.js"
11
12
  },
12
13
  "release": false,
13
14
  "tag": false,
@@ -52,7 +53,8 @@
52
53
  "lerna": "^6.0.1",
53
54
  "madrun": "^10.0.0",
54
55
  "montag": "^1.2.1",
55
- "nodemon": "^3.0.1"
56
+ "nodemon": "^3.0.1",
57
+ "supertape": "^10.8.0"
56
58
  },
57
59
  "peerDependencies": {
58
60
  "putout": ">=37"