@putout/printer 2.13.0 → 2.14.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/ChangeLog CHANGED
@@ -1,3 +1,13 @@
1
+ 2023.06.14, v2.14.0
2
+
3
+ feature:
4
+ - 0f3dbaf @putout/printer: ArrayExpression: no newline when one element with type SpreadElement
5
+
6
+ 2023.06.14, v2.13.1
7
+
8
+ fix:
9
+ - ed8870a ArrayExpression
10
+
1
11
  2023.06.13, v2.13.0
2
12
 
3
13
  feature:
@@ -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 = {
@@ -11,6 +11,7 @@ const {
11
11
  isBooleanLiteral,
12
12
  isNullLiteral,
13
13
  isStringLiteral,
14
+ isSpreadElement,
14
15
  } = require('@babel/types');
15
16
 
16
17
  const {
@@ -24,6 +25,15 @@ const {
24
25
 
25
26
  const {round} = Math;
26
27
 
28
+ const isOneSpread = (elements) => {
29
+ if (elements.length > 1)
30
+ return false;
31
+
32
+ const [first] = elements;
33
+
34
+ return isSpreadElement(first);
35
+ };
36
+
27
37
  const isSimpleAndCall = ([a, b]) => {
28
38
  if (!isSimple(a))
29
39
  return;
@@ -44,6 +54,9 @@ module.exports.isNewlineBetweenElements = (path, {elements, maxElementsInOneLine
44
54
  if (isOneSimple(path))
45
55
  return ONE_LINE;
46
56
 
57
+ if (isOneSpread(elements))
58
+ return ONE_LINE;
59
+
47
60
  if (elements.length === 2 && isIdentifierAndIdentifier(elements))
48
61
  return ONE_LINE;
49
62
 
@@ -157,10 +170,7 @@ function isTwoStringsDifferentLength(strings) {
157
170
  }
158
171
 
159
172
  function isInsideLoop(path) {
160
- if (!path.parentPath.isForOfStatement())
161
- return false;
162
-
163
- return true;
173
+ return path.parentPath.isForOfStatement();
164
174
  }
165
175
 
166
176
  function tooLong(path) {
@@ -219,20 +229,14 @@ function isIncreaseIndent(path) {
219
229
  if (elements[0].isObjectExpression())
220
230
  return true;
221
231
 
222
- if (isStringAndObject(elements))
223
- return true;
224
-
225
- return false;
232
+ return isStringAndObject(elements);
226
233
  }
227
234
 
228
235
  function isInsideCallLoop(path) {
229
236
  if (!path.parentPath.isCallExpression())
230
237
  return false;
231
238
 
232
- if (!path.parentPath.parentPath.isForOfStatement())
233
- return false;
234
-
235
- return true;
239
+ return path.parentPath.parentPath.isForOfStatement();
236
240
  }
237
241
 
238
242
  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
  }
@@ -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.13.0",
3
+ "version": "2.14.0",
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",