@putout/printer 18.7.8 → 18.7.9

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
+ 2026.03.18, v18.7.9
2
+
3
+ feature:
4
+ - 3e47d13f @putout/printer: ObjectPattern: comma: simplify
5
+
1
6
  2026.03.18, v18.7.8
2
7
 
3
8
  feature:
@@ -39,6 +39,7 @@ const isLastArgInCall = createTypeChecker([
39
39
  ]);
40
40
 
41
41
  const callWithRoot = (fn) => (a, {root}) => fn(root);
42
+
42
43
  const isExcludedFromChain = createTypeChecker([
43
44
  '+: -> UnaryExpression',
44
45
  '+: -> IfStatement',
@@ -93,4 +94,3 @@ const isIfUp = (path) => {
93
94
 
94
95
  return is;
95
96
  };
96
-
@@ -0,0 +1,28 @@
1
+ import {types} from '@putout/babel';
2
+ import {createTypeChecker} from '#type-checker';
3
+
4
+ const {
5
+ isForOfStatement,
6
+ isAssignmentPattern,
7
+ } = types;
8
+
9
+ const isCoupleOption = (a, {couple}) => couple;
10
+
11
+ export function isInsideForOf({parentPath}) {
12
+ return isForOfStatement(parentPath.parentPath.parentPath);
13
+ }
14
+
15
+ export function isPrevAssign(path) {
16
+ const prev = path.getPrevSibling();
17
+
18
+ return isAssignmentPattern(prev.node.value);
19
+ }
20
+
21
+ export const isCommaAfterProperty = createTypeChecker([
22
+ ['+', isCoupleOption],
23
+ ['-: key -> -'],
24
+ ['-', isPrevAssign],
25
+ ['-: parentPath', isInsideForOf],
26
+ ['+: node.value.right -> ObjectExpression'],
27
+ ]);
28
+
@@ -5,7 +5,6 @@ import {hasAssign} from './has.js';
5
5
  const {
6
6
  isObjectExpression,
7
7
  isAssignmentPattern,
8
- isForOfStatement,
9
8
  isFunction,
10
9
  isVariableDeclarator,
11
10
  isObjectProperty,
@@ -38,16 +37,6 @@ export const isCoupleProperties = ({path, valuePath, property}) => {
38
37
  return !isObjectProperty(parentPath);
39
38
  };
40
39
 
41
- export function isInsideForOf({parentPath}) {
42
- return isForOfStatement(parentPath.parentPath.parentPath);
43
- }
44
-
45
- export function isPrevAssign(path) {
46
- const prev = path.getPrevSibling();
47
-
48
- return isAssignmentPattern(prev.node.value);
49
- }
50
-
51
40
  export function isPrevAssignObject(path) {
52
41
  const prev = path.getPrevSibling();
53
42
 
@@ -1,4 +1,3 @@
1
- import {types} from '@putout/babel';
2
1
  import {wrongShorthand} from './wrong-shorthand.js';
3
2
  import {maybeTypeAnnotation} from '../../maybe/maybe-type-annotation.js';
4
3
  import {printKey} from '../object-expression/print-key.js';
@@ -12,18 +11,15 @@ import {
12
11
  hasAssignObject,
13
12
  hasObjectPattern,
14
13
  } from './has.js';
14
+ import {isCommaAfterProperty} from './comma.js';
15
15
  import {
16
16
  isCoupleProperties,
17
17
  isIndent,
18
18
  isInsideFn,
19
- isInsideForOf,
20
19
  isNextAssignObject,
21
- isPrevAssign,
22
20
  isPrevAssignObject,
23
21
  } from './is.js';
24
22
 
25
- const {isObjectExpression} = types;
26
-
27
23
  export const ObjectPattern = {
28
24
  print: maybeTypeAnnotation((path, printer, semantics) => {
29
25
  const shouldIndent = isIndent(path);
@@ -97,12 +93,7 @@ export const ObjectPattern = {
97
93
  } else if (isAssign) {
98
94
  print(valuePath);
99
95
 
100
- maybe.print(couple, ',');
101
- maybe.print.newline(couple);
102
-
103
- const {right} = valuePath.node;
104
-
105
- if (i && !isPrevAssign(property) && !isInsideForOf(path) && isObjectExpression(right)) {
96
+ if (isCommaAfterProperty(property, {couple})) {
106
97
  print(',');
107
98
  print.newline();
108
99
  continue;
@@ -137,3 +128,4 @@ export const ObjectPattern = {
137
128
  print('}');
138
129
  }),
139
130
  };
131
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.7.8",
3
+ "version": "18.7.9",
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",