@putout/plugin-nodejs 16.1.0 → 16.3.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.
@@ -27,7 +27,11 @@ export const include = () => [
27
27
  'require',
28
28
  ];
29
29
 
30
- export const filter = ({scope}) => {
30
+ export const filter = (path) => {
31
+ if (path.parentPath.isObjectProperty())
32
+ return false;
33
+
34
+ const {scope} = path;
31
35
  const isDirname = scope.hasBinding('__dirname');
32
36
  const isFilename = scope.hasBinding('__filename');
33
37
  const isRequire = scope.hasBinding('require');
@@ -1,9 +1,9 @@
1
+ import justCamelCase from 'just-camel-case';
1
2
  import {
2
3
  types,
3
4
  operator,
4
5
  template,
5
6
  } from 'putout';
6
- import justCamelCase from 'just-camel-case';
7
7
 
8
8
  const {
9
9
  awaitExpression,
@@ -63,12 +63,23 @@ export const match = () => ({
63
63
  });
64
64
 
65
65
  export const replace = () => ({
66
+ 'const __a = require(__b).__c': ({__c}, path) => {
67
+ const {name} = __c;
68
+
69
+ if (name === 'default')
70
+ return 'import __a from "__b"';
71
+
72
+ const bindingPath = path.scope.bindings[name];
73
+
74
+ if (bindingPath)
75
+ return 'const __a = __c';
76
+
77
+ return `{
78
+ const {__c} = require(__b);
79
+ const __a = __c;
80
+ }`;
81
+ },
66
82
  'const __a = require(".")': 'import __a from "./index.js"',
67
- 'const __a = require("__b").default': 'import __a from "__b"',
68
- 'const __a = require(__b).__c': `{
69
- const {__c} = require(__b);
70
- const __a = __c;
71
- }`,
72
83
  'require("__a")': 'import("__a")',
73
84
  'const __a = require(__b)': ({__a}, path) => {
74
85
  const {value} = path.get(__B).evaluate();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-nodejs",
3
- "version": "16.1.0",
3
+ "version": "16.3.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",