@putout/plugin-esm 9.1.0 → 9.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.
|
@@ -1,8 +1,26 @@
|
|
|
1
|
-
import {types} from 'putout';
|
|
1
|
+
import {types, operator} from 'putout';
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const {getTemplateValues} = operator;
|
|
4
|
+
const {
|
|
5
|
+
isImportDefaultSpecifier,
|
|
6
|
+
isVariableDeclaration,
|
|
7
|
+
} = types;
|
|
8
|
+
|
|
9
|
+
const DYNAMIC = 'const __identifier__a = await import(__b)';
|
|
4
10
|
|
|
5
11
|
export const report = (path) => {
|
|
12
|
+
if (isVariableDeclaration(path)) {
|
|
13
|
+
const {
|
|
14
|
+
__identifier__a,
|
|
15
|
+
__b,
|
|
16
|
+
} = getTemplateValues(path, DYNAMIC);
|
|
17
|
+
|
|
18
|
+
const {name} = __identifier__a;
|
|
19
|
+
const source = __b.value;
|
|
20
|
+
|
|
21
|
+
return `'const ${name} = await import("${source}")' -> 'const {${name}} = await import("${source}")'`;
|
|
22
|
+
}
|
|
23
|
+
|
|
6
24
|
const source = path.node.source.value;
|
|
7
25
|
const {specifiers} = path.node;
|
|
8
26
|
const [first] = specifiers;
|
|
@@ -24,6 +42,7 @@ export const replace = ({options}) => {
|
|
|
24
42
|
const {name, source} = options;
|
|
25
43
|
|
|
26
44
|
return {
|
|
45
|
+
[`const ${name} = await import("${source}")`]: `const {${name}} = await import("${source}")`,
|
|
27
46
|
[`import ${name} from "${source}"`]: `import {${name}} from "${source}"`,
|
|
28
47
|
[`export * as ${name} from "${source}"`]: `export {${name}} from "${source}"`,
|
|
29
48
|
};
|
|
@@ -1,10 +1,17 @@
|
|
|
1
|
-
import {types} from 'putout';
|
|
1
|
+
import {types, operator} from 'putout';
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const {getTemplateValues} = operator;
|
|
4
|
+
const {
|
|
5
|
+
isImportDefaultSpecifier,
|
|
6
|
+
isVariableDeclaration,
|
|
7
|
+
} = types;
|
|
8
|
+
|
|
9
|
+
const DYNAMIC = 'const __identifier__a = await import(__b)';
|
|
4
10
|
|
|
5
11
|
export const include = () => [
|
|
6
12
|
'import __a from "__b"',
|
|
7
13
|
'export * as __a from "__b"',
|
|
14
|
+
DYNAMIC,
|
|
8
15
|
];
|
|
9
16
|
|
|
10
17
|
export const report = (path) => {
|
|
@@ -26,6 +33,19 @@ const CommentLine = (value) => ({
|
|
|
26
33
|
});
|
|
27
34
|
|
|
28
35
|
const getImport = (path) => {
|
|
36
|
+
if (isVariableDeclaration(path)) {
|
|
37
|
+
const {
|
|
38
|
+
__identifier__a,
|
|
39
|
+
__b,
|
|
40
|
+
} = getTemplateValues(path, DYNAMIC);
|
|
41
|
+
|
|
42
|
+
return [
|
|
43
|
+
__identifier__a.name,
|
|
44
|
+
__b.value,
|
|
45
|
+
'dynamic',
|
|
46
|
+
];
|
|
47
|
+
}
|
|
48
|
+
|
|
29
49
|
const source = path.node.source.value;
|
|
30
50
|
const [first] = path.node.specifiers;
|
|
31
51
|
|
|
@@ -17,11 +17,13 @@ const {
|
|
|
17
17
|
|
|
18
18
|
export const report = (file, {name, source, type}) => {
|
|
19
19
|
const filename = getFilename(file);
|
|
20
|
+
const reports = {
|
|
21
|
+
import: `Use \`import {${name}} from '${source}'\` in '${filename}'`,
|
|
22
|
+
dynamic: `Use \`const {${name}} = await import('${source}')\` in '${filename}'`,
|
|
23
|
+
export: `Use \`export {${name}} from '${source}'\` in '${filename}'`,
|
|
24
|
+
};
|
|
20
25
|
|
|
21
|
-
|
|
22
|
-
return `Use \`import {${name}} from '${source}'\` in '${filename}'`;
|
|
23
|
-
|
|
24
|
-
return `Use \`export {${name}} from '${source}'\` in '${filename}'`;
|
|
26
|
+
return reports[type];
|
|
25
27
|
};
|
|
26
28
|
|
|
27
29
|
export const fix = (file, {name, source, content, ast}) => {
|
package/package.json
CHANGED