@putout/printer 8.30.0 → 8.32.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,14 @@
1
+ 2024.05.03, v8.32.0
2
+
3
+ feature:
4
+ - 4c10986 @putout/printer: ObjectPattern: used as Function param
5
+
6
+ 2024.05.03, v8.31.0
7
+
8
+ feature:
9
+ - 5fd0053 @putout/printer: ArrayExpression: is-object-after-simple: simplify
10
+ - 22dae11 @putout/printer: ArrayExpression: is-object-after-simple
11
+
1
12
  2024.05.02, v8.30.0
2
13
 
3
14
  feature:
@@ -7,6 +7,7 @@ const {
7
7
  isIdentifierAndIdentifier,
8
8
  isStringAndArray,
9
9
  isSimpleAndEmptyObject,
10
+ isNextObject,
10
11
  } = require('../../is');
11
12
 
12
13
  const {
@@ -21,46 +22,18 @@ const {
21
22
  isArrayIndented,
22
23
  } = require('./indent');
23
24
 
25
+ const {isObjectAfterSimple} = require('./is-object-after-simple');
26
+
24
27
  const {
25
28
  isObjectExpression,
26
29
  isSpreadElement,
27
30
  isStringLiteral,
28
31
  isIdentifier,
29
- isArrayExpression,
30
- isCallExpression,
31
32
  } = types;
32
33
 
33
34
  const isNextString = (path) => isStringLiteral(path.getNextSibling());
34
35
  const isPrevString = (path) => isStringLiteral(path.getPrevSibling());
35
36
  const isAroundStrings = (path) => isNextString(path) || isPrevString(path);
36
- const isNextObject = (a) => a.getNextSibling().isObjectExpression();
37
- const isPrevObject = (a) => a.getPrevSibling().isObjectExpression();
38
- const isObjectAfterSpread = (a) => isSpreadElement(a) && isNextObject(a) && !isPrevObject(a);
39
- const isObjectAfterIdentifier = (a) => isIdentifier(a) && isNextObject(a) && !isPrevObject(a);
40
-
41
- const isObjectAfterArray = (a) => {
42
- if (!isArrayExpression(a))
43
- return false;
44
-
45
- return isNextObject(a);
46
- };
47
-
48
- const isObjectAfterCall = (a) => {
49
- if (!isCallExpression(a))
50
- return false;
51
-
52
- return isNextObject(a);
53
- };
54
-
55
- const isObjectAfterSimple = (a) => {
56
- if (isObjectAfterArray(a))
57
- return true;
58
-
59
- if (isObjectAfterCall(a))
60
- return true;
61
-
62
- return isObjectAfterSpread(a) || isObjectAfterIdentifier(a);
63
- };
64
37
 
65
38
  const isSpreadBeforeObject = (a) => {
66
39
  if (!a.isObjectExpression())
@@ -0,0 +1,20 @@
1
+ 'use strict';
2
+
3
+ const {isNextObject, isPrevObject} = require('../../is');
4
+
5
+ const SIMPLE_TYPES = [
6
+ 'ArrayExpression',
7
+ 'ObjectExpression',
8
+ 'SpreadElement',
9
+ 'CallExpression',
10
+ 'Identifier',
11
+ ];
12
+
13
+ module.exports.isObjectAfterSimple = (a) => {
14
+ const {type} = a;
15
+
16
+ if (!isNextObject(a) || isPrevObject(a))
17
+ return false;
18
+
19
+ return SIMPLE_TYPES.includes(type);
20
+ };
@@ -173,14 +173,28 @@ function shouldAddNewline(path, semantics) {
173
173
  maxPropertiesInOneLine,
174
174
  });
175
175
 
176
+ const fnParam = isFunctionParam(path);
177
+
176
178
  if (moreCount && !moreLength)
177
179
  return ONE_LINE;
178
180
 
179
- if (!isForOf(path) && !path.parentPath.isFunction() && n && checkLength(properties))
181
+ if (!fnParam && n && !isForOf(path) && checkLength(properties))
180
182
  return COUPLE_LINES;
181
183
 
182
- if (hasAssign(properties))
184
+ if (!fnParam && hasAssign(properties))
183
185
  return COUPLE_LINES;
184
186
 
185
187
  return parentPath.isObjectProperty();
186
188
  }
189
+
190
+ function isFunctionParam(path) {
191
+ const {parentPath} = path;
192
+
193
+ if (parentPath.isFunction())
194
+ return true;
195
+
196
+ if (!parentPath.isAssignmentPattern())
197
+ return false;
198
+
199
+ return parentPath.parentPath.isFunction();
200
+ }
@@ -34,6 +34,9 @@ const isPrev = (path) => {
34
34
  const isNextParent = (path) => isNext(path.parentPath);
35
35
  const isLast = (path) => isParentProgram(path) && !isNext(path);
36
36
 
37
+ module.exports.isNextObject = (a) => a.getNextSibling().isObjectExpression();
38
+ module.exports.isPrevObject = (a) => a.getPrevSibling().isObjectExpression();
39
+
37
40
  module.exports.isFirst = (path) => path.node === path.parentPath.node.body?.[0];
38
41
  module.exports.isPrevBody = (path) => path.getPrevSibling().isBlockStatement();
39
42
  module.exports.isNext = isNext;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "8.30.0",
3
+ "version": "8.32.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",