@putout/plugin-esm 1.1.0 β 1.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
|
@@ -176,7 +176,7 @@ console.log(putout);
|
|
|
176
176
|
|
|
177
177
|
Checkout in π[**Putout Editor**](https://putout.cloudcmd.io/#/gist/f9f34acddbefba0ded53225ca10fa44e/7b4dba44602b9b2d28fe3a98989474a4b0d8d73d).
|
|
178
178
|
|
|
179
|
-
|
|
179
|
+
### β Example of incorrect code
|
|
180
180
|
|
|
181
181
|
```js
|
|
182
182
|
import json from './mod.json' with { type: 'json' };
|
|
@@ -192,7 +192,7 @@ import json from './mod.json' with { type: 'json' };
|
|
|
192
192
|
|
|
193
193
|
Checkout in π[**Putout Editor**](https://putout.cloudcmd.io/#/gist/521e2ff199243a7ce1f65db7140c272e/28c0588281286f8a6765b8aa2ecabbfcde2973a7).
|
|
194
194
|
|
|
195
|
-
|
|
195
|
+
### β Example of incorrect code
|
|
196
196
|
|
|
197
197
|
```js
|
|
198
198
|
import {
|
|
@@ -204,7 +204,7 @@ import {
|
|
|
204
204
|
import a1 from 'a1';
|
|
205
205
|
```
|
|
206
206
|
|
|
207
|
-
|
|
207
|
+
### β
Example of correct code
|
|
208
208
|
|
|
209
209
|
```js
|
|
210
210
|
import a1 from 'a1';
|
|
@@ -216,6 +216,38 @@ import {
|
|
|
216
216
|
} from 'd';
|
|
217
217
|
```
|
|
218
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
|
+
|
|
219
251
|
## License
|
|
220
252
|
|
|
221
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
|
@@ -7,6 +7,7 @@ const sortImportsBySpecifiers = require('./sort-imports-by-specifiers');
|
|
|
7
7
|
const removeEmptyImport = require('./remove-empty-import');
|
|
8
8
|
const removeEmptyExport = require('./remove-empty-export');
|
|
9
9
|
const mergeDuplicateImports = require('./merge-duplicate-imports');
|
|
10
|
+
const convertAssertToWith = require('./convert-assert-to-with');
|
|
10
11
|
|
|
11
12
|
module.exports.rules = {
|
|
12
13
|
...mergeDuplicateImports.rules,
|
|
@@ -16,4 +17,5 @@ module.exports.rules = {
|
|
|
16
17
|
'remove-empty-import': removeEmptyImport,
|
|
17
18
|
'remove-empty-export': removeEmptyExport,
|
|
18
19
|
'sort-imports-by-specifiers': sortImportsBySpecifiers,
|
|
20
|
+
'convert-assert-to-with': convertAssertToWith,
|
|
19
21
|
};
|
|
@@ -35,6 +35,9 @@ module.exports.traverse = ({push}) => ({
|
|
|
35
35
|
if (source.value.startsWith('node:') && !nextPath.node.source.value.startsWith('node:'))
|
|
36
36
|
return;
|
|
37
37
|
|
|
38
|
+
if (source.value.startsWith('#') && !nextPath.node.source.value.startsWith('#'))
|
|
39
|
+
return;
|
|
40
|
+
|
|
38
41
|
push({
|
|
39
42
|
path,
|
|
40
43
|
nextPath,
|
package/package.json
CHANGED