@putout/plugin-putout 12.1.1 → 12.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.
package/README.md CHANGED
@@ -524,6 +524,7 @@ const {
524
524
  operator,
525
525
  types,
526
526
  } = require('putout');
527
+
527
528
  const {compare} = operator;
528
529
  const {isIdentifier} = types;
529
530
 
@@ -704,9 +705,11 @@ module.exports.include = () => 'cons __a = __b';
704
705
  module.exports.exclude = () => 'var __a = __b';
705
706
  module.exports.include = 'cons __a = __b';
706
707
  module.exports.exclude = 'var __a = __b';
708
+
707
709
  module.exports.include = [
708
710
  'cons __a = __b',
709
711
  ];
712
+
710
713
  module.exports.exclude = [
711
714
  'var __a = __b',
712
715
  ];
@@ -718,18 +721,23 @@ module.exports.exclude = [
718
721
  module.exports.include = () => [
719
722
  'cons __a = __b',
720
723
  ];
724
+
721
725
  module.exports.exclude = () => [
722
726
  'var __a = __b',
723
727
  ];
728
+
724
729
  module.exports.include = () => [
725
730
  'cons __a = __b',
726
731
  ];
732
+
727
733
  module.exports.exclude = () => [
728
734
  'var __a = __b',
729
735
  ];
736
+
730
737
  module.exports.include = () => [
731
738
  'cons __a = __b',
732
739
  ];
740
+
733
741
  module.exports.exclude = () => [
734
742
  'var __a = __b',
735
743
  ];
@@ -80,10 +80,7 @@ module.exports = (rootPath, key) => {
80
80
  ],
81
81
  });
82
82
 
83
- return [
84
- transformError,
85
- result?.code,
86
- ];
83
+ return [transformError, result?.code];
87
84
  };
88
85
 
89
86
  function createVarStore(path) {
@@ -119,15 +119,11 @@ function parseKey(propertyPath) {
119
119
  Error(`Replace key cannot be computed: '${keyPath.toString()}'`),
120
120
  ];
121
121
 
122
- return [
123
- null,
124
- key,
125
- ];
122
+ return [null, key];
126
123
  }
127
124
 
128
125
  function hasMatch(path) {
129
- const {body} = path.scope
130
- .getProgramParent().path.node;
126
+ const {body} = path.scope.getProgramParent().path.node;
131
127
 
132
128
  for (const current of body) {
133
129
  if (compare(current, 'module.exports.match = __a'))
@@ -17,17 +17,20 @@ module.exports.report = () => {
17
17
 
18
18
  function isRequire(path) {
19
19
  return path
20
- .get('callee').isIdentifier({
20
+ .get('callee')
21
+ .isIdentifier({
21
22
  name: 'require',
22
23
  });
23
24
  }
24
25
 
25
26
  function isBabelTypes(path) {
26
27
  return path
27
- .get('arguments.0').isStringLiteral({
28
+ .get('arguments.0')
29
+ .isStringLiteral({
28
30
  value: '@babel/types',
29
31
  });
30
32
  }
33
+
31
34
  module.exports.traverse = ({push}) => ({
32
35
  CallExpression(path) {
33
36
  if (!isRequire(path))
@@ -73,9 +73,7 @@ function getTraverseCall(path) {
73
73
 
74
74
  path.traverse({
75
75
  CallExpression(path) {
76
- if (!path.get('callee').isIdentifier({
77
- name: 'traverse',
78
- }))
76
+ if (!path.get('callee').isIdentifier({name: 'traverse'}))
79
77
  return;
80
78
 
81
79
  result = path;
@@ -64,6 +64,7 @@ function getVarPath(bindings) {
64
64
 
65
65
  return insertAfter.path;
66
66
  }
67
+
67
68
  module.exports.traverse = ({push}) => {
68
69
  const isInserted = fullstore();
69
70
 
@@ -54,6 +54,7 @@ function getVarPath(bindings) {
54
54
 
55
55
  return insertAfter.path;
56
56
  }
57
+
57
58
  module.exports.traverse = ({push}) => ({
58
59
  CallExpression(path) {
59
60
  const calleePath = path.get('callee');
@@ -10,7 +10,8 @@ const {StringLiteral} = types;
10
10
  const {compare} = operator;
11
11
 
12
12
  const isPush = (path) => path
13
- .get('value').isIdentifier({
13
+ .get('value')
14
+ .isIdentifier({
14
15
  name: 'push',
15
16
  });
16
17
 
@@ -12,9 +12,7 @@ module.exports.match = () => ({
12
12
  'module.exports.traverse = (__args) => __a': ({__args}, path) => {
13
13
  const program = path.scope.getProgramParent().path;
14
14
 
15
- const withFix = contains(program, [
16
- 'module.exports.fix = __a',
17
- ]);
15
+ const withFix = contains(program, ['module.exports.fix = __a']);
18
16
 
19
17
  if (withFix)
20
18
  return false;
@@ -25,9 +23,7 @@ module.exports.match = () => ({
25
23
  if (!__args.length)
26
24
  return true;
27
25
 
28
- const withPush = contains(__args[0], [
29
- 'push',
30
- ]);
26
+ const withPush = contains(__args[0], ['push']);
31
27
 
32
28
  if (withPush)
33
29
  return false;
@@ -11,6 +11,7 @@ const {
11
11
  Identifier,
12
12
  ObjectProperty,
13
13
  ObjectExpression,
14
+ isIdentifier,
14
15
  } = types;
15
16
 
16
17
  const {
@@ -55,6 +56,13 @@ module.exports.filter = (path, {options}) => {
55
56
  return false;
56
57
  };
57
58
 
59
+ const maybeLiteral = (a) => {
60
+ if (isIdentifier(a))
61
+ return StringLiteral(a.name);
62
+
63
+ return a;
64
+ };
65
+
58
66
  function convert(objectPath) {
59
67
  const {
60
68
  key,
@@ -64,7 +72,7 @@ function convert(objectPath) {
64
72
  replaceWith(objectPath, ObjectExpression([
65
73
  ObjectProperty(Identifier('plugins'), ArrayExpression([
66
74
  ArrayExpression([
67
- key,
75
+ maybeLiteral(key),
68
76
  value,
69
77
  ]),
70
78
  ])),
@@ -61,8 +61,7 @@ module.exports.replace = () => ({
61
61
  const buildRequire = template(`const NAME = REQUIRE`);
62
62
 
63
63
  function declareRequire({__a, __b}, path) {
64
- const shortName = __a.value || __a.name
65
- .split('/').pop();
64
+ const shortName = __a.value || __a.name.split('/').pop();
66
65
 
67
66
  const name = justCamelCase(shortName);
68
67
 
@@ -74,8 +73,7 @@ function declareRequire({__a, __b}, path) {
74
73
  if (path.scope.hasBinding(name))
75
74
  return name;
76
75
 
77
- const programPath = path.scope
78
- .getProgramParent().path;
76
+ const programPath = path.scope.getProgramParent().path;
79
77
 
80
78
  programPath.node.body.unshift(requireNode);
81
79
 
@@ -10,6 +10,7 @@ module.exports.report = ({correct, operatorPath}) => {
10
10
 
11
11
  module.exports.fix = ({path, incorrect, correct}) => {
12
12
  path.node.value = path.node.value.replace(incorrect, correct);
13
+ path.node.raw = path.node.raw.replace(incorrect, correct);
13
14
  };
14
15
 
15
16
  module.exports.traverse = ({push}) => ({
@@ -72,8 +73,5 @@ function isCorrect({path, incorrect}) {
72
73
  const {value} = messagePath.node;
73
74
  const is = !incorrect.test(value);
74
75
 
75
- return [
76
- is,
77
- messagePath,
78
- ];
76
+ return [is, messagePath];
79
77
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-putout",
3
- "version": "12.1.1",
3
+ "version": "12.3.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout plugin helps with plugins development",