@putout/printer 1.134.0 → 1.135.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.05, v1.135.0
2
+
3
+ feature:
4
+ - 34c703e @putout/printer: ArrayExpression: Tuple: Identifier and Object
5
+
6
+ 2023.06.05, v1.134.1
7
+
8
+ feature:
9
+ - 0a80c70 @putout/printer: ArrayExpression: tuple: String, String, Object
10
+
1
11
  2023.06.05, v1.134.0
2
12
 
3
13
  feature:
@@ -21,7 +21,7 @@ const {
21
21
  } = require('../is');
22
22
 
23
23
  const isForOf = ({parentPath}) => parentPath.isForOfStatement();
24
- const SECOND = 1;
24
+
25
25
  const isStringAndArray = ([a, b]) => isStringLiteral(a) && isArrayExpression(b);
26
26
  const isStringAndString = ([a, b]) => isStringLiteral(a) && isStringLiteral(b);
27
27
  const isIdentifierAndIdentifier = ([a, b]) => isIdentifier(a) && isIdentifier(b);
@@ -29,6 +29,14 @@ const isInsideArray = (path) => path.parentPath.isArrayExpression();
29
29
  const isSimpleAndCall = ([a, b]) => isSimple(a) && isCallExpression(b);
30
30
  const isBooleanAndSimple = ([a, b]) => isBooleanLiteral(a) && isSimple(b);
31
31
  const isNullAndSimple = ([a, b]) => isNullLiteral(a) && isSimple(b);
32
+ const isSimpleAndObject = ([a, b]) => isSimple(a) && isObjectExpression(b);
33
+
34
+ const isStringAndObject = (elements) => {
35
+ const first = elements.at(0);
36
+ const last = elements.at(-1);
37
+
38
+ return isStringLiteral(first) && isObjectExpression(last);
39
+ };
32
40
 
33
41
  const isTwoLongStrings = ([a, b]) => {
34
42
  const LONG_STRING = 20;
@@ -63,12 +71,12 @@ module.exports.ArrayExpression = {
63
71
  },
64
72
  print(path, {print, maybe, indent}) {
65
73
  const elements = path.get('elements');
66
- const shouldIncreaseIndent = isIncreaseIndent(path);
74
+ const shouldIncreaseIndent = !isIncreaseIndent(path);
67
75
 
68
76
  print('[');
69
77
 
70
78
  if (!isTwoLongStrings(elements))
71
- maybe.indent.inc(!shouldIncreaseIndent);
79
+ maybe.indent.inc(shouldIncreaseIndent);
72
80
 
73
81
  const isNewLine = isNewlineBetweenElements(path, {
74
82
  elements,
@@ -91,7 +99,7 @@ module.exports.ArrayExpression = {
91
99
  }
92
100
 
93
101
  if (!isTwoLongStrings(elements))
94
- maybe.indent.dec(!shouldIncreaseIndent);
102
+ maybe.indent.dec(shouldIncreaseIndent);
95
103
 
96
104
  const parentElements = path.parentPath.get('elements');
97
105
 
@@ -164,7 +172,7 @@ function isIncreaseIndent(path) {
164
172
  if (elements[0].isObjectExpression())
165
173
  return true;
166
174
 
167
- if (elements.length > 1 && elements[SECOND].isObjectExpression())
175
+ if (isStringAndObject(elements))
168
176
  return true;
169
177
 
170
178
  return false;
@@ -253,6 +261,9 @@ function isNewlineBetweenElements(path, {elements}) {
253
261
  if (isStringAndIdentifier(elements))
254
262
  return false;
255
263
 
264
+ if (isSimpleAndObject(elements))
265
+ return false;
266
+
256
267
  if (isStringAndString(elements) && path.parentPath.isArrayExpression() && isArrayExpression(path.parentPath.node.elements[0]))
257
268
  return false;
258
269
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.134.0",
3
+ "version": "1.135.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",