@putout/plugin-nodejs 18.7.0 → 18.8.1
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.
|
@@ -7,6 +7,8 @@ const {
|
|
|
7
7
|
exportNamedDeclaration,
|
|
8
8
|
isObjectExpression,
|
|
9
9
|
isStringLiteral,
|
|
10
|
+
isImportDefaultSpecifier,
|
|
11
|
+
exportNamespaceSpecifier,
|
|
10
12
|
} = types;
|
|
11
13
|
|
|
12
14
|
const {replaceWith} = operator;
|
|
@@ -102,6 +104,18 @@ function addExportToBinding(name, path) {
|
|
|
102
104
|
return exportNamedDeclaration(null, [exportSpecifier(imported, imported)]);
|
|
103
105
|
}
|
|
104
106
|
|
|
107
|
+
if (isImportDefaultSpecifier(bindingPath)) {
|
|
108
|
+
const {local} = bindingPath.node;
|
|
109
|
+
const {source} = bindingPath.parentPath.node;
|
|
110
|
+
const specifiers = [
|
|
111
|
+
exportNamespaceSpecifier(local),
|
|
112
|
+
];
|
|
113
|
+
const exportNode = exportNamedDeclaration(null, specifiers, source);
|
|
114
|
+
|
|
115
|
+
replaceWith(bindingPath.parentPath, exportNode);
|
|
116
|
+
return '';
|
|
117
|
+
}
|
|
118
|
+
|
|
105
119
|
const exportNode = exportNamedDeclaration(bindingPath.node);
|
|
106
120
|
|
|
107
121
|
replaceWith(bindingPath, exportNode);
|
|
@@ -16,6 +16,7 @@ const {
|
|
|
16
16
|
isStringLiteral,
|
|
17
17
|
importDefaultSpecifier,
|
|
18
18
|
isProgram,
|
|
19
|
+
isExportNamedDeclaration,
|
|
19
20
|
} = types;
|
|
20
21
|
|
|
21
22
|
const {replaceWith, insertBefore} = operator;
|
|
@@ -45,6 +46,9 @@ export const match = () => ({
|
|
|
45
46
|
return isProgram(path.parentPath.parentPath);
|
|
46
47
|
},
|
|
47
48
|
'const __a = require(__b)': ({__b}, path) => {
|
|
49
|
+
if (isExportNamedDeclaration(path.parentPath))
|
|
50
|
+
return false;
|
|
51
|
+
|
|
48
52
|
if (path.scope.getBinding('require'))
|
|
49
53
|
return false;
|
|
50
54
|
|
|
@@ -83,7 +87,6 @@ export const replace = () => ({
|
|
|
83
87
|
'require("__a")': 'import("__a")',
|
|
84
88
|
'const __a = require(__b)': ({__a}, path) => {
|
|
85
89
|
const {value} = path.get(__B).evaluate();
|
|
86
|
-
|
|
87
90
|
const fnPath = path.findParent(isFunction);
|
|
88
91
|
|
|
89
92
|
if (fnPath) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-nodejs",
|
|
3
|
-
"version": "18.
|
|
3
|
+
"version": "18.8.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "🐊Putout plugin adds ability to transform code to new API of Node.js",
|