@putout/plugin-nodejs 18.13.0 → 18.15.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.
@@ -154,6 +154,9 @@ function addExportToBinding(name, path) {
154
154
  return exportNamedDeclaration(null, [exportSpecifier(imported, imported)]);
155
155
  }
156
156
 
157
+ if (binding.references > 1)
158
+ return '';
159
+
157
160
  if (isImportDefaultSpecifier(bindingPath)) {
158
161
  const {local} = bindingPath.node;
159
162
  const {source} = bindingPath.parentPath.node;
@@ -77,11 +77,14 @@ export const match = () => ({
77
77
 
78
78
  export const replace = () => ({
79
79
  'const __a = require("__b").default': 'import __a from "__b"',
80
- 'const __a = require(__b).__c': ({__c}, path) => {
80
+ 'const __a = require(__b).__c': ({__a, __c}, path) => {
81
81
  const {name} = __c;
82
- const bindingPath = path.scope.bindings[name];
82
+ const binding = path.scope.bindings[name];
83
83
 
84
- if (bindingPath)
84
+ if (binding && isIdentifier(__a))
85
+ return 'import {__c as __a} from "__b"';
86
+
87
+ if (binding && isObjectPattern(__a))
85
88
  return 'const __a = __c';
86
89
 
87
90
  return `{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-nodejs",
3
- "version": "18.13.0",
3
+ "version": "18.15.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",