@putout/printer 2.12.0 → 2.13.1

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/ChangeLog CHANGED
@@ -1,3 +1,13 @@
1
+ 2023.06.14, v2.13.1
2
+
3
+ fix:
4
+ - ed8870a ArrayExpression
5
+
6
+ 2023.06.13, v2.13.0
7
+
8
+ feature:
9
+ - 1e77dca @putout/printer: ArrayExpression: one string literal
10
+
1
11
  2023.06.13, v2.12.0
2
12
 
3
13
  feature:
package/README.md CHANGED
@@ -35,9 +35,7 @@ And update `.putout.json`:
35
35
  ```json
36
36
  {
37
37
  "printer": "putout",
38
- "plugins": [
39
- "printer"
40
- ]
38
+ "plugins": ["printer"]
41
39
  }
42
40
  ```
43
41
 
@@ -268,9 +266,7 @@ function speed(printer) {
268
266
  for (let i = 0; i < 1000; i++) {
269
267
  putout(code, {
270
268
  printer,
271
- plugins: [
272
- 'remove-unused-variables',
273
- ],
269
+ plugins: ['remove-unused-variables'],
274
270
  });
275
271
  }
276
272
 
@@ -21,10 +21,7 @@ const isTwoLongStrings = ([a, b]) => {
21
21
  if (!a?.isStringLiteral() || !b?.isStringLiteral())
22
22
  return false;
23
23
 
24
- if (a.node.value.length > LONG_STRING)
25
- return true;
26
-
27
- return false;
24
+ return a.node.value.length > LONG_STRING;
28
25
  };
29
26
 
30
27
  module.exports.ArrayExpression = {
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const {isSimple} = require('@putout/operate');
4
+
4
5
  const {
5
6
  isObjectExpression,
6
7
  isArrayExpression,
@@ -10,8 +11,8 @@ const {
10
11
  isBooleanLiteral,
11
12
  isNullLiteral,
12
13
  isStringLiteral,
13
-
14
14
  } = require('@babel/types');
15
+
15
16
  const {
16
17
  isStringAndMember,
17
18
  isStringAndIdentifier,
@@ -19,7 +20,6 @@ const {
19
20
  isCoupleLines,
20
21
  isStringAndArray,
21
22
  isIdentifierAndIdentifier,
22
-
23
23
  } = require('../../is');
24
24
 
25
25
  const {round} = Math;
@@ -129,6 +129,9 @@ function isOneSimple(path) {
129
129
  if (first.isIdentifier() && first.node.name.length < 5)
130
130
  return true;
131
131
 
132
+ if (first.isStringLiteral() && first.node.value.length > 10)
133
+ return false;
134
+
132
135
  if (!first.isIdentifier() && isSimple(first))
133
136
  return true;
134
137
 
@@ -154,10 +157,7 @@ function isTwoStringsDifferentLength(strings) {
154
157
  }
155
158
 
156
159
  function isInsideLoop(path) {
157
- if (!path.parentPath.isForOfStatement())
158
- return false;
159
-
160
- return true;
160
+ return path.parentPath.isForOfStatement();
161
161
  }
162
162
 
163
163
  function tooLong(path) {
@@ -202,6 +202,7 @@ function isLastArg({parentPath}) {
202
202
  function isParentProperty(path) {
203
203
  return path.find(isObjectProperty);
204
204
  }
205
+
205
206
  module.exports.isIncreaseIndent = isIncreaseIndent;
206
207
  function isIncreaseIndent(path) {
207
208
  const elements = path.get('elements');
@@ -215,20 +216,14 @@ function isIncreaseIndent(path) {
215
216
  if (elements[0].isObjectExpression())
216
217
  return true;
217
218
 
218
- if (isStringAndObject(elements))
219
- return true;
220
-
221
- return false;
219
+ return isStringAndObject(elements);
222
220
  }
223
221
 
224
222
  function isInsideCallLoop(path) {
225
223
  if (!path.parentPath.isCallExpression())
226
224
  return false;
227
225
 
228
- if (!path.parentPath.parentPath.isForOfStatement())
229
- return false;
230
-
231
- return true;
226
+ return path.parentPath.parentPath.isForOfStatement();
232
227
  }
233
228
 
234
229
  const isStringAndObject = (elements) => {
@@ -10,10 +10,7 @@ const isStringLike = (a) => {
10
10
  if (isStringLiteral(a))
11
11
  return true;
12
12
 
13
- if (isTemplateLiteral(a))
14
- return true;
15
-
16
- return false;
13
+ return isTemplateLiteral(a);
17
14
  };
18
15
 
19
16
  module.exports.isConcatenation = (path) => {
@@ -132,8 +132,5 @@ function isParens(path) {
132
132
  if (isBodyOfArrow(path))
133
133
  return true;
134
134
 
135
- if (isParentExpression(path))
136
- return true;
137
-
138
- return false;
135
+ return isParentExpression(path);
139
136
  }
@@ -128,8 +128,5 @@ function shouldAddNewline(path) {
128
128
  if (!isForOf(path) && !path.parentPath.isFunction() && n && checkLength(properties))
129
129
  return true;
130
130
 
131
- if (parentPath.isObjectProperty())
132
- return true;
133
-
134
- return false;
131
+ return parentPath.isObjectProperty();
135
132
  }
@@ -9,7 +9,6 @@ const {
9
9
  isVariableDeclaration,
10
10
  isMemberExpression,
11
11
  isArrayExpression,
12
-
13
12
  } = require('@babel/types');
14
13
 
15
14
  const isParentProgram = (path) => path.parentPath?.isProgram();
@@ -79,10 +79,7 @@ function shouldAddNewlineAfter(path) {
79
79
  if (isLast(path))
80
80
  return false;
81
81
 
82
- if (isNextIfAlternate(path))
83
- return false;
84
-
85
- return true;
82
+ return !isNextIfAlternate(path);
86
83
  }
87
84
 
88
85
  function isNextIfAlternate(path) {
@@ -103,8 +100,5 @@ function isTry({parentPath}) {
103
100
  if (parentPath.isTryStatement())
104
101
  return true;
105
102
 
106
- if (parentPath.parentPath?.isTryStatement())
107
- return true;
108
-
109
- return false;
103
+ return parentPath.parentPath?.isTryStatement();
110
104
  }
@@ -13,10 +13,7 @@ function shouldAddSemi(path) {
13
13
  if (path.isClassDeclaration())
14
14
  return false;
15
15
 
16
- if (path.isFunctionDeclaration())
17
- return false;
18
-
19
- return true;
16
+ return !path.isFunctionDeclaration();
20
17
  }
21
18
 
22
19
  module.exports.ExportDefaultDeclaration = {
@@ -57,10 +57,7 @@ module.exports.ExpressionStatement = {
57
57
  if (hasTrailingComment(path) && isLast(path))
58
58
  return true;
59
59
 
60
- if (isBeforeElse(path))
61
- return true;
62
-
63
- return false;
60
+ return isBeforeElse(path);
64
61
  },
65
62
  after(path, {print, maybe, store}) {
66
63
  if (hasTrailingComment(path) && isLast(path) && isCoupleLines(path)) {
@@ -55,12 +55,7 @@ module.exports.ForOfStatement = {
55
55
 
56
56
  maybe.markAfter(isMarkedAfter(bodyPath), path);
57
57
  },
58
- afterIf: (path) => {
59
- if (isNext(path))
60
- return true;
61
-
62
- return false;
63
- },
58
+ afterIf: (path) => isNext(path),
64
59
  after(path, {print}) {
65
60
  print.linebreak();
66
61
  markAfter(path);
@@ -57,10 +57,7 @@ module.exports.IfStatement = {
57
57
  if (!exists(next))
58
58
  return false;
59
59
 
60
- if (next.isReturnStatement())
61
- return false;
62
-
63
- return true;
60
+ return !next.isReturnStatement();
64
61
  },
65
62
  after: (path, {print}) => {
66
63
  print.linebreak();
@@ -96,10 +96,7 @@ module.exports.ImportDeclaration = {
96
96
  if (isLast(path))
97
97
  return false;
98
98
 
99
- if (path.getNextSibling().isImportDeclaration())
100
- return false;
101
-
102
- return true;
99
+ return !path.getNextSibling().isImportDeclaration();
103
100
  },
104
101
  after(path, {print}) {
105
102
  print.newline();
@@ -149,10 +149,7 @@ function shouldAddNewlineBefore(path) {
149
149
  if (prevPath.isStatement() && !prevPath.isExpressionStatement() && !prevPath.isBlockStatement())
150
150
  return false;
151
151
 
152
- if (!isExportDeclaration(path.parentPath) && isCoupleLines(path))
153
- return true;
154
-
155
- return false;
152
+ return !isExportDeclaration(path.parentPath) && isCoupleLines(path);
156
153
  }
157
154
 
158
155
  function isFirst(path) {
@@ -20,10 +20,7 @@ module.exports.WhileStatement = {
20
20
  }
21
21
  },
22
22
  afterIf(path) {
23
- if (isLast(path))
24
- return false;
25
-
26
- return true;
23
+ return !isLast(path);
27
24
  },
28
25
  after(path, {print}) {
29
26
  print.linebreak();
@@ -29,10 +29,7 @@ module.exports.TSTypeAliasDeclaration = {
29
29
  if (last)
30
30
  return false;
31
31
 
32
- if (isNextType(path))
33
- return false;
34
-
35
- return true;
32
+ return !isNextType(path);
36
33
  },
37
34
  after(path, {print}) {
38
35
  print.newline();
@@ -33,8 +33,5 @@ module.exports.TSTypeLiteral = (path, {indent, traverse, write, maybe}) => {
33
33
  function isNewline(path) {
34
34
  const members = path.get('members');
35
35
 
36
- if (members.length && members[0].node.typeAnnotation)
37
- return true;
38
-
39
- return false;
36
+ return members.length && members[0].node.typeAnnotation;
40
37
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "2.12.0",
3
+ "version": "2.13.1",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "Simplest possible opinionated Babel AST printer for 🐊Putout",