@putout/plugin-printer 8.6.3 → 8.6.5

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.
@@ -6,12 +6,29 @@ const {
6
6
  isArrayExpression,
7
7
  isIdentifier,
8
8
  isCallExpression,
9
+ isStringLiteral,
9
10
  arrayExpression,
10
11
  stringLiteral,
11
12
  } = types;
12
13
 
13
14
  const {replaceWith} = operator;
14
- const instrument = process.env.PUTOUT_INSTRUMENT;
15
+
16
+ const hasResult = (value) => /^[+-]/.test(value);
17
+ const typeOptions = {
18
+ instrument: Boolean(process.env.PUTOUT_INSTRUMENT),
19
+ };
20
+
21
+ const isDsl = createTypeChecker([
22
+ ['-: -> !StringLiteral'],
23
+ ['+: node.value ->', hasResult],
24
+ ], typeOptions);
25
+
26
+ const isSimple = createTypeChecker([
27
+ ['+: -> Identifier'],
28
+ ['+: -> CallExpression'],
29
+ ['-: -> !StringLiteral'],
30
+ ['+: node.value -> !', hasResult],
31
+ ], typeOptions);
15
32
 
16
33
  export const report = (path) => {
17
34
  return `Add missing tuple around: ${path}`;
@@ -25,6 +42,13 @@ export const fix = (path) => {
25
42
  return;
26
43
  }
27
44
 
45
+ const {value} = node;
46
+
47
+ if (isStringLiteral(path) && !/^[+-]/.test(value)) {
48
+ replaceWith(path, arrayExpression([stringLiteral(`+: -> ${value}`)]));
49
+ return;
50
+ }
51
+
28
52
  replaceWith(path, arrayExpression([node]));
29
53
  };
30
54
 
@@ -50,24 +74,6 @@ export const traverse = ({push}) => ({
50
74
  },
51
75
  });
52
76
 
53
- const hasResult = (value) => /^[+-]/.test(value);
54
-
55
- const isDsl = createTypeChecker([
56
- ['-: -> !StringLiteral'],
57
- ['+: node.value ->', hasResult],
58
- ], {
59
- instrument,
60
- });
61
-
62
- const isSimple = createTypeChecker([
63
- 'Identifier',
64
- 'CallExpression',
65
- ['-: -> !StringLiteral'],
66
- ['+: node.value ->!', hasResult],
67
- ], {
68
- instrument,
69
- });
70
-
71
77
  function isConsistent(elements) {
72
78
  const arraysCount = elements.filter(isArrayExpression).length;
73
79
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-printer",
3
- "version": "8.6.3",
3
+ "version": "8.6.5",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout plugin adds support of transformations for @putout/printer",