@putout/printer 13.3.0 → 13.4.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
+ 2025.03.13, v13.4.1
2
+
3
+ feature:
4
+ - 982f309 @putout/printer: is: simplify
5
+
6
+ 2025.03.13, v13.4.0
7
+
8
+ feature:
9
+ - abbfbce @putout/printer: improve support of ObjectExpressions inside ArrayExpressions
10
+
1
11
  2025.03.11, v13.3.0
2
12
 
3
13
  feature:
@@ -135,7 +135,7 @@ module.exports.ArrayExpression = {
135
135
  maybe.print(is, ',');
136
136
 
137
137
  if (!(isObjectExpression(element) && isObjectProperty(path.parentPath)))
138
- maybe.print.newline((is || isSpreadBeforeObject(element)) && !isNextObject(element));
138
+ maybe.print.newline((is || isSpreadBeforeObject(element)) && !isNextObject(element) && !isObjectExpression(element));
139
139
 
140
140
  maybe.print.space(is && isObjectAfterSimple(element));
141
141
 
@@ -4,18 +4,14 @@ const {types} = require('@putout/babel');
4
4
  const {
5
5
  isArrayExpression,
6
6
  isCallExpression,
7
+ isIdentifier,
7
8
  } = types;
8
9
 
9
- module.exports.isThirdObjectInsideArray = (path) => {
10
- const {parentPath} = path;
11
-
10
+ module.exports.isThirdObjectInsideArray = ({parentPath}) => {
12
11
  if (!isArrayExpression(parentPath))
13
12
  return false;
14
13
 
15
- const [, second, third] = parentPath.node.elements;
16
-
17
- if (!isCallExpression(second))
18
- return false;
14
+ const [, second] = parentPath.node.elements;
19
15
 
20
- return third === path.node;
16
+ return isCallExpression(second) && !!isIdentifier(second);
21
17
  };
@@ -53,10 +53,6 @@ function isInsideNestedArrayCall({parentPath}) {
53
53
 
54
54
  function isInsideNestedTuple({parentPath}) {
55
55
  const {elements} = parentPath.parentPath.node;
56
-
57
- if (!elements)
58
- return false;
59
-
60
56
  const [first] = elements;
61
57
 
62
58
  return isStringLiteral(first);
@@ -78,8 +78,21 @@ function isStringAndIdentifier([a, b]) {
78
78
  return isStringLiteral(a) && isIdentifier(b);
79
79
  }
80
80
 
81
+ const checkObject = (elements) => {
82
+ let a = elements.at(-1);
83
+
84
+ if (!isObjectExpression(a))
85
+ a = elements.at(-2);
86
+
87
+ if (!isObjectExpression(a))
88
+ return false;
89
+
90
+ return a.node.properties.length;
91
+ };
92
+
81
93
  module.exports.isSimpleAndNotEmptyObject = (elements) => {
82
- const [a, b] = elements;
94
+ const [a] = elements;
95
+
83
96
  const simpleTypes = [
84
97
  'Identifier',
85
98
  'SpreadElement',
@@ -91,10 +104,7 @@ module.exports.isSimpleAndNotEmptyObject = (elements) => {
91
104
  if (a && !simpleTypes.includes(a.type))
92
105
  return false;
93
106
 
94
- if (!isObjectExpression(b))
95
- return false;
96
-
97
- return b.node.properties.length;
107
+ return checkObject(elements);
98
108
  };
99
109
 
100
110
  module.exports.isIdentifierAndIdentifier = ([a, b]) => {
@@ -168,3 +178,4 @@ module.exports.hasLeadingComment = (path) => path.node?.leadingComments?.length;
168
178
 
169
179
  module.exports.noTrailingComment = (path) => !path.node.trailingComments?.length;
170
180
  module.exports.noLeadingComment = (path) => !path.node.leadingComments?.length;
181
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "13.3.0",
3
+ "version": "13.4.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",