@putout/plugin-nodejs 18.14.0 → 18.16.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.
@@ -65,9 +65,18 @@ function createDeclaration(name, value) {
65
65
  return `export const ${name} = ${value};`;
66
66
  }
67
67
 
68
+ const isNested = ({properties}) => {
69
+ for (const property of properties) {
70
+ if (isObjectExpression(property.value))
71
+ return true;
72
+ }
73
+
74
+ return false;
75
+ };
76
+
68
77
  export const replace = () => ({
69
78
  'module.exports = __a': ({__a}, path) => {
70
- if (!isObjectExpression(__a) || isStringLiteral(__a.properties[0].key))
79
+ if (!isObjectExpression(__a) || isStringLiteral(__a.properties[0].key) || isNested(__a))
71
80
  return 'export default __a';
72
81
 
73
82
  const result = ['export {'];
@@ -154,6 +163,9 @@ function addExportToBinding(name, path) {
154
163
  return exportNamedDeclaration(null, [exportSpecifier(imported, imported)]);
155
164
  }
156
165
 
166
+ if (binding.references > 1)
167
+ return '';
168
+
157
169
  if (isImportDefaultSpecifier(bindingPath)) {
158
170
  const {local} = bindingPath.node;
159
171
  const {source} = bindingPath.parentPath.node;
@@ -93,7 +93,7 @@ export const replace = () => ({
93
93
  }`;
94
94
  },
95
95
  'const __a = require(".")': 'import __a from "./index.js"',
96
- 'require("__a")': 'import("__a")',
96
+ 'require("__a")': 'import "__a"',
97
97
  'const __a = require(__b)': ({__a}, path) => {
98
98
  const {value} = path.get(__B).evaluate();
99
99
  const fnPath = path.findParent(isFunction);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-nodejs",
3
- "version": "18.14.0",
3
+ "version": "18.16.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",