@putout/printer 18.46.0 → 18.47.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,10 @@
1
+ 2026.09.30, v18.47.0
2
+
3
+ feature:
4
+ - fda0e2f3 @putout/printer: ObjectPattern: hasCoupleProperties: apply type checker
5
+ - 3301db7c @putout/printer: ObjectPattern: apply type checker
6
+ - 805d58d3 @putout/printer: ObjectPattern: nested array pattern
7
+
1
8
  2026.09.16, v18.46.0
2
9
 
3
10
  feature:
@@ -678,7 +685,7 @@ feature:
678
685
  - c6783ee @putout/printer: ExpressionStatement: hasTrailingCommentNotCoupleLines
679
686
  - 8e08572 @putout/printer: ExpressionStatement: isTopParentLast: simplify
680
687
  - fe1b0ca @putout/printer: ExpressionStatement: isTopParentLast
681
- - b84b9a6 @putout/printer: ExpressionStatement: isIndent
688
+ - b84b9a6 @putout/printer: ExpressionStatement: isInsideArrayPattern
682
689
  - d4d0106 @putout/printer: ExpressionStatement: beforeIf: simplify
683
690
  - 9a4721a @putout/printer: ExpressionStatement: afterIf: simplify
684
691
  - a9d2cf8 @putout/printer: ExpressionStatement: isBeforeElse: simplify
@@ -1,4 +1,3 @@
1
- import {types} from '@putout/babel';
2
1
  import {createTypeChecker} from '#type-checker';
3
2
  import {
4
3
  isCoupleLines,
@@ -8,39 +7,31 @@ import {
8
7
  } from '#is';
9
8
  import {hasAssign} from './has.js';
10
9
 
11
- const {
12
- isFunction,
13
- isVariableDeclarator,
14
- isObjectProperty,
15
- } = types;
16
-
17
10
  export const hasOptionIs = (a, {is}) => is;
18
11
 
19
- export const isInsideFn = (path) => {
20
- if (isFunction(path.parentPath))
21
- return true;
22
-
23
- return isFunction(path.parentPath.parentPath);
24
- };
25
-
26
- export function isIndent(path) {
27
- return !path.parentPath.isArrayPattern();
28
- }
29
-
30
- export const isCoupleProperties = ({path, valuePath, property}) => {
31
- if (!isCoupleLines(valuePath))
32
- return false;
33
-
34
- if (exists(property.getPrevSibling()))
35
- return false;
36
-
37
- const {parentPath} = path;
38
-
39
- if (isVariableDeclarator(parentPath) && !hasAssign(path))
40
- return false;
41
-
42
- return !isObjectProperty(parentPath);
43
- };
12
+ export const isInsideFn = createTypeChecker([
13
+ '+: parentPath -> FunctionDeclaration',
14
+ '+: parentPath.parentPath -> FunctionDeclaration',
15
+ ]);
16
+
17
+ export const isInsideArrayPattern = createTypeChecker([
18
+ '-: parentPath -> ArrayPattern',
19
+ '+: parentPath.parentPath -> !ArrayPattern',
20
+ ]);
21
+
22
+ const callWithValue = (fn) => (path) => fn(path.get('value'));
23
+
24
+ const isVarWithAssign = createTypeChecker([
25
+ ['-: parentPath.parentPath -> !VariableDeclarator'],
26
+ ['+: parentPath -> !', hasAssign],
27
+ ]);
28
+
29
+ export const hasCoupleProperties = createTypeChecker([
30
+ ['-: -> !', callWithValue(isCoupleLines)],
31
+ ['-', callWithPrev(exists)],
32
+ ['-', isVarWithAssign],
33
+ ['+: parentPath.parentPath -> !ObjectProperty'],
34
+ ]);
44
35
 
45
36
  export const isAssignObject = createTypeChecker([
46
37
  '-: node.value -> !AssignmentPattern',
@@ -17,14 +17,14 @@ import {
17
17
  isIndentAfterNewline,
18
18
  } from './indent.js';
19
19
  import {
20
- isCoupleProperties,
21
- isIndent,
20
+ hasCoupleProperties,
21
+ isInsideArrayPattern,
22
22
  isInsideFn,
23
23
  } from './is.js';
24
24
 
25
25
  export const ObjectPattern = {
26
26
  print: maybeTypeAnnotation((path, printer, semantics) => {
27
- const shouldIndent = isIndent(path);
27
+ const shouldIndent = isInsideArrayPattern(path);
28
28
  const {
29
29
  maxPropertiesInOneLine,
30
30
  maxPropertiesLengthInOneLine,
@@ -69,11 +69,7 @@ export const ObjectPattern = {
69
69
  const isAssign = valuePath.isAssignmentPattern();
70
70
 
71
71
  const {shorthand, computed} = property.node;
72
- const couple = isCoupleProperties({
73
- path,
74
- property,
75
- valuePath,
76
- });
72
+ const couple = hasCoupleProperties(property);
77
73
 
78
74
  if (isBreaklineBeforeProperty(property, {couple, semantics}))
79
75
  print.breakline();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.46.0",
3
+ "version": "18.47.0",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "Simplest possible opinionated Babel AST printer for 🐊Putout",