@putout/printer 12.31.0 → 12.32.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.02.15, v12.32.1
2
+
3
+ fix:
4
+ - 1ae65ad @putout/printer: DEBUG -> LOG_DEBUG
5
+
6
+ 2025.02.14, v12.32.0
7
+
8
+ feature:
9
+ - bc351a1 @putout/printer: ArrayExpression: ObjectExpression between Identifier and CallExpression
10
+
1
11
  2025.02.09, v12.31.0
2
12
 
3
13
  feature:
@@ -11,11 +11,11 @@ const {
11
11
  LOG_ALL,
12
12
  LOG_TOKENS,
13
13
  LOG_TERM,
14
- DEBUG,
14
+ LOG_DEBUG,
15
15
  } = process.env;
16
16
 
17
17
  module.exports.createDebug = (tokens) => (a) => {
18
- if (!DEBUG)
18
+ if (!LOG_DEBUG)
19
19
  return;
20
20
 
21
21
  tokens.push({
@@ -22,7 +22,10 @@ const {
22
22
  isArrayIndented,
23
23
  } = require('./indent');
24
24
 
25
- const {isObjectAfterSimple} = require('./is-object-after-simple');
25
+ const {
26
+ isObjectAfterSimple,
27
+ isNextSimple,
28
+ } = require('./is-object-after-simple');
26
29
 
27
30
  const {
28
31
  isObjectExpression,
@@ -30,6 +33,7 @@ const {
30
33
  isStringLiteral,
31
34
  isIdentifier,
32
35
  isFunction,
36
+ isCallExpression,
33
37
  } = types;
34
38
 
35
39
  const isNextString = (path) => isStringLiteral(path.getNextSibling());
@@ -60,18 +64,9 @@ const isSpreadBeforeObject = (a) => {
60
64
  return prev.get('argument').isCallExpression();
61
65
  };
62
66
 
63
- const isNextSimple = (a) => {
64
- const next = a.getNextSibling();
65
-
66
- if (next.isSpreadElement())
67
- return true;
68
-
69
- return next.isIdentifier();
70
- };
71
-
72
67
  const isNextSimpleBetweenObjects = (a) => {
73
68
  const next = a.getNextSibling();
74
- const is = next.isSpreadElement() || next.isIdentifier();
69
+ const is = next.isSpreadElement() || next.isIdentifier() || next.isCallExpression();
75
70
 
76
71
  if (!is)
77
72
  return true;
@@ -115,8 +110,7 @@ module.exports.ArrayExpression = {
115
110
 
116
111
  const indented = isArrayIndented(path);
117
112
 
118
- if (indented)
119
- maybe.indent.inc(shouldIncreaseIndent);
113
+ maybe.indent.inc(indented && shouldIncreaseIndent);
120
114
 
121
115
  const isNewLine = isMultiLine(path, {
122
116
  elements,
@@ -150,8 +144,7 @@ module.exports.ArrayExpression = {
150
144
  }
151
145
  }
152
146
 
153
- if (indented)
154
- maybe.indent.dec(shouldIncreaseIndent);
147
+ maybe.indent.dec(indented && shouldIncreaseIndent);
155
148
 
156
149
  const parentElements = path.parentPath.get('elements');
157
150
 
@@ -166,7 +159,7 @@ module.exports.ArrayExpression = {
166
159
  maybe.indent(elements.length && isNewLine);
167
160
  }
168
161
 
169
- if (isSimpleAndNotEmptyObject(elements) && !isSpreadElement(elements.at(-1))) {
162
+ if (isSimpleAndNotEmptyObject(elements) && !isSpreadElement(elements.at(-1)) && !isCallExpression(elements.at(-1))) {
170
163
  print(',');
171
164
  print.breakline();
172
165
  }
@@ -196,7 +189,7 @@ module.exports.ArrayExpression = {
196
189
  };
197
190
 
198
191
  function isSimpleAfterObject(path) {
199
- if (!isSpreadElement(path) && !isIdentifier(path))
192
+ if (!isSpreadElement(path) && !isIdentifier(path) && !isCallExpression(path))
200
193
  return;
201
194
 
202
195
  const prev = path.getPrevSibling();
@@ -19,3 +19,9 @@ module.exports.isObjectAfterSimple = (a) => {
19
19
 
20
20
  return SIMPLE_TYPES.includes(type);
21
21
  };
22
+
23
+ module.exports.isNextSimple = (a) => {
24
+ const {type} = a.getNextSibling();
25
+
26
+ return SIMPLE_TYPES.includes(type);
27
+ };
@@ -77,7 +77,8 @@ function isStringAndIdentifier([a, b]) {
77
77
  return isStringLiteral(a) && isIdentifier(b);
78
78
  }
79
79
 
80
- module.exports.isSimpleAndNotEmptyObject = ([a, b]) => {
80
+ module.exports.isSimpleAndNotEmptyObject = (elements) => {
81
+ const [a, b] = elements;
81
82
  const simpleTypes = [
82
83
  'Identifier',
83
84
  'SpreadElement',
@@ -124,7 +124,7 @@ function isNotLastBody(path) {
124
124
  }
125
125
 
126
126
  function isNotLastOrParentLast(path) {
127
- return !(isLast(path) || isParentLast(path));
127
+ return !isLast(path) && !isParentLast(path);
128
128
  }
129
129
 
130
130
  function isNextUp(path) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "12.31.0",
3
+ "version": "12.32.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",
@@ -66,6 +66,7 @@
66
66
  },
67
67
  "devDependencies": {
68
68
  "@putout/eslint": "^3.5.0",
69
+ "@putout/eslint-flat": "^2.0.0",
69
70
  "@putout/plugin-minify": "^9.0.0",
70
71
  "@putout/plugin-printer": "^4.0.0",
71
72
  "@putout/plugin-promises": "^16.0.0",
package/tsconfig.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2015",
4
+ "skipLibCheck": true
5
+ }
6
+ }