@putout/plugin-nodejs 18.8.1 → 18.10.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.
|
@@ -9,6 +9,7 @@ const {
|
|
|
9
9
|
isStringLiteral,
|
|
10
10
|
isImportDefaultSpecifier,
|
|
11
11
|
exportNamespaceSpecifier,
|
|
12
|
+
isSpreadElement,
|
|
12
13
|
} = types;
|
|
13
14
|
|
|
14
15
|
const {replaceWith} = operator;
|
|
@@ -21,6 +22,17 @@ export const exclude = () => [
|
|
|
21
22
|
];
|
|
22
23
|
|
|
23
24
|
export const match = () => ({
|
|
25
|
+
'module.exports = __a': ({__a}) => {
|
|
26
|
+
if (!isObjectExpression(__a))
|
|
27
|
+
return true;
|
|
28
|
+
|
|
29
|
+
for (const property of __a.properties) {
|
|
30
|
+
if (isSpreadElement(property))
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return true;
|
|
35
|
+
},
|
|
24
36
|
'module.exports.__a = __b': ({__a, __b}, path) => {
|
|
25
37
|
const {name} = __a;
|
|
26
38
|
|
|
@@ -110,6 +122,7 @@ function addExportToBinding(name, path) {
|
|
|
110
122
|
const specifiers = [
|
|
111
123
|
exportNamespaceSpecifier(local),
|
|
112
124
|
];
|
|
125
|
+
|
|
113
126
|
const exportNode = exportNamedDeclaration(null, specifiers, source);
|
|
114
127
|
|
|
115
128
|
replaceWith(bindingPath.parentPath, exportNode);
|
|
@@ -39,6 +39,12 @@ const createFnDeclaration = template('const NAME1 = FN(NAME2)');
|
|
|
39
39
|
const isPackage = ({value}) => /package(\.json)?$/.test(value);
|
|
40
40
|
|
|
41
41
|
export const match = () => ({
|
|
42
|
+
'export const __a = require("__b")': ({__a}, path) => {
|
|
43
|
+
if (!isIdentifier(__a))
|
|
44
|
+
return true;
|
|
45
|
+
|
|
46
|
+
return path.scope.bindings[__a.name].references === 1;
|
|
47
|
+
},
|
|
42
48
|
'const __a = require("__b").default': (vars, path) => {
|
|
43
49
|
if (isProgram(path.parentPath))
|
|
44
50
|
return true;
|
|
@@ -159,6 +165,12 @@ export const replace = () => ({
|
|
|
159
165
|
const __a = ${name}.__c(__args);
|
|
160
166
|
}`;
|
|
161
167
|
},
|
|
168
|
+
'export const __a = require("__b")': ({__a}) => {
|
|
169
|
+
if (isObjectPattern(__a))
|
|
170
|
+
return 'export __a from "__b"';
|
|
171
|
+
|
|
172
|
+
return 'export * as __a from "__b"';
|
|
173
|
+
},
|
|
162
174
|
});
|
|
163
175
|
|
|
164
176
|
function checkCall({__b}, path) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-nodejs",
|
|
3
|
-
"version": "18.
|
|
3
|
+
"version": "18.10.0",
|
|
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",
|