@putout/printer 1.134.0 → 1.134.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,8 @@
1
+ 2023.06.05, v1.134.1
2
+
3
+ feature:
4
+ - 0a80c70 @putout/printer: ArrayExpression: tuple: String, String, Object
5
+
1
6
  2023.06.05, v1.134.0
2
7
 
3
8
  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);
@@ -30,6 +30,13 @@ 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
32
 
33
+ const isStringAndObject = (elements) => {
34
+ const first = elements.at(0);
35
+ const last = elements.at(-1);
36
+
37
+ return isStringLiteral(first) && isObjectExpression(last);
38
+ };
39
+
33
40
  const isTwoLongStrings = ([a, b]) => {
34
41
  const LONG_STRING = 20;
35
42
 
@@ -63,12 +70,12 @@ module.exports.ArrayExpression = {
63
70
  },
64
71
  print(path, {print, maybe, indent}) {
65
72
  const elements = path.get('elements');
66
- const shouldIncreaseIndent = isIncreaseIndent(path);
73
+ const shouldIncreaseIndent = !isIncreaseIndent(path);
67
74
 
68
75
  print('[');
69
76
 
70
77
  if (!isTwoLongStrings(elements))
71
- maybe.indent.inc(!shouldIncreaseIndent);
78
+ maybe.indent.inc(shouldIncreaseIndent);
72
79
 
73
80
  const isNewLine = isNewlineBetweenElements(path, {
74
81
  elements,
@@ -91,7 +98,7 @@ module.exports.ArrayExpression = {
91
98
  }
92
99
 
93
100
  if (!isTwoLongStrings(elements))
94
- maybe.indent.dec(!shouldIncreaseIndent);
101
+ maybe.indent.dec(shouldIncreaseIndent);
95
102
 
96
103
  const parentElements = path.parentPath.get('elements');
97
104
 
@@ -164,7 +171,7 @@ function isIncreaseIndent(path) {
164
171
  if (elements[0].isObjectExpression())
165
172
  return true;
166
173
 
167
- if (elements.length > 1 && elements[SECOND].isObjectExpression())
174
+ if (isStringAndObject(elements))
168
175
  return true;
169
176
 
170
177
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.134.0",
3
+ "version": "1.134.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",