@putout/printer 18.3.3 → 18.3.5

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
+ 2026.03.10, v18.3.5
2
+
3
+ feature:
4
+ - 8a3ffb9 @putout/printer: ObjectExpression: isIndentBeforeProperty
5
+ - 3d450fc @putout/printer: ObjectExpression: indent
6
+
7
+ 2026.03.10, v18.3.4
8
+
9
+ feature:
10
+ - d3410bd @putout/printer: BlockStatement: simplify
11
+
1
12
  2026.03.09, v18.3.3
2
13
 
3
14
  feature:
@@ -1,5 +1,9 @@
1
- import {isNewlineBetweenSiblings} from '#is';
1
+ import {
2
+ isNewlineBetweenSiblings,
3
+ isNext,
4
+ } from '#is';
2
5
  import {printParams} from '#print-params';
6
+ import {markAfter} from '#mark';
3
7
  import {printKey} from '../object-expression/print-key.js';
4
8
  import {printKind} from './kind.js';
5
9
 
@@ -11,6 +15,7 @@ export const ObjectMethod = {
11
15
  write('async ');
12
16
  },
13
17
  print(path, printer, semantics) {
18
+ const {trailingComma} = semantics;
14
19
  const {print} = printer;
15
20
 
16
21
  printKind(path, printer);
@@ -19,6 +24,12 @@ export const ObjectMethod = {
19
24
 
20
25
  print.space();
21
26
  print('__body');
27
+
28
+ if (isNext(path) || trailingComma)
29
+ print(',');
30
+
31
+ print.newline();
32
+ markAfter(path);
22
33
  },
23
34
  afterIf(path) {
24
35
  return isNewlineBetweenSiblings(path);
@@ -6,7 +6,6 @@ import {
6
6
  isIf,
7
7
  noTrailingComment,
8
8
  isNewlineBetweenSiblings,
9
- noLeadingComment,
10
9
  hasLeadingComment,
11
10
  exists,
12
11
  isInsideCall,
@@ -32,12 +31,7 @@ const notLastArgInsideCall = (path) => {
32
31
  const hasNoProperties = (path) => !path.node.properties.length;
33
32
  const hasValue = (path) => path.node.properties[0].value;
34
33
 
35
- const {
36
- isMemberExpression,
37
- isLogicalExpression,
38
- } = types;
39
-
40
- const isLogicalArgument = (path) => isLogicalExpression(path.node.argument);
34
+ const {isMemberExpression} = types;
41
35
 
42
36
  const isParens = createTypeChecker([isInsideBody, isInsideExpression]);
43
37
 
@@ -72,6 +66,13 @@ export const isManyLines = createTypeChecker([
72
66
  ['+', hasValue],
73
67
  ]);
74
68
 
69
+ const isManyLinesOption = (a, {manyLines}) => manyLines;
70
+
71
+ const isIndentBeforeProperty = createTypeChecker([
72
+ ['-: -> !', isManyLinesOption],
73
+ ['+: -> !', hasLeadingComment],
74
+ ]);
75
+
75
76
  export const ObjectExpression = (path, printer, semantics) => {
76
77
  const {trailingComma} = semantics;
77
78
  const {
@@ -100,39 +101,37 @@ export const ObjectExpression = (path, printer, semantics) => {
100
101
  maybe.indent.inc(memberCallee);
101
102
 
102
103
  for (const [index, property] of properties.entries()) {
104
+ const couple = length > 1;
105
+ const isLast = index === n;
106
+
107
+ if (isIndentBeforeProperty(property, {manyLines}))
108
+ indent();
109
+
110
+ print(property);
111
+
112
+ if (property.isObjectMethod())
113
+ continue;
114
+
103
115
  if (property.isSpreadElement()) {
104
- const logical = isLogicalArgument(property);
105
-
106
- if (noLeadingComment(property))
107
- maybe.indent(length > 1 || logical || manyLines);
108
-
109
- print(property);
110
-
111
- if (noTrailingComment(property) && (length > 1 || manyLines)) {
112
- maybe.print(index !== n || trailingComma, ',');
116
+ if (noTrailingComment(property) && (couple || manyLines)) {
117
+ maybe.print(!isLast || trailingComma, ',');
113
118
  print.newline();
114
119
  }
115
120
 
116
121
  continue;
117
122
  }
118
123
 
119
- maybe.indent(manyLines && noLeadingComment(property));
120
- print(property);
121
-
122
- if (property.isObjectMethod())
123
- continue;
124
-
125
124
  if (noTrailingComment(property) && !hasNextLeadingComment(property)) {
126
125
  maybe.print.newline(manyLines);
127
126
  maybe.print.linebreak(isNewlineBetweenSiblings(property));
128
127
  }
129
128
  }
130
129
 
130
+ indent.dec();
131
+
131
132
  if (!insideNestedArrayCall) {
132
- indent.dec();
133
133
  maybe.indent(manyLines);
134
134
  } else if (isInsideTupleLike(path)) {
135
- indent.dec();
136
135
  indent();
137
136
  indent.inc();
138
137
  }
@@ -209,4 +209,3 @@ export const hasTrailingComment = (path) => {
209
209
  export const hasLeadingComment = (path) => path.node?.leadingComments?.length;
210
210
 
211
211
  export const noTrailingComment = (path) => !path.node.trailingComments?.length;
212
- export const noLeadingComment = (path) => !path.node.leadingComments?.length;
@@ -68,6 +68,7 @@ export const shouldAddNewlineAfter = createTypeChecker([
68
68
  ['-', isLooksLikeInsideFn],
69
69
  ['-', isLast],
70
70
  ['-', isExportFunction],
71
+ ['-: parentPath -> ObjectMethod'],
71
72
  ['+: -> !', isNextIfAlternate],
72
73
  ]);
73
74
 
@@ -1,15 +1,11 @@
1
1
  import {types} from '@putout/babel';
2
2
  import {markAfter} from '#mark';
3
- import {isNext} from '#is';
4
3
  import {parseComments} from '../../comment/comment.js';
5
4
  import {getDirectives} from './get-directives.js';
6
5
  import {isCallInsideChain} from './is-call-inside-chain.js';
7
6
  import {shouldAddNewlineAfter} from './block-statement-newline.js';
8
7
 
9
- const {
10
- isObjectMethod,
11
- isArrayExpression,
12
- } = types;
8
+ const {isArrayExpression} = types;
13
9
 
14
10
  const isFirstStatement = (path) => path.node.body[0];
15
11
  const isFirstDirective = (path) => path.node.directives?.[0];
@@ -27,7 +23,6 @@ const isInsideArrayTupleOfThree = (path) => {
27
23
 
28
24
  export const BlockStatement = {
29
25
  print(path, printer, semantics) {
30
- const {trailingComma} = semantics;
31
26
  const {
32
27
  indent,
33
28
  maybe,
@@ -70,11 +65,6 @@ export const BlockStatement = {
70
65
  write('}');
71
66
 
72
67
  maybe.indent.dec(callInsideChain);
73
-
74
- const {parentPath} = path;
75
-
76
- if (isObjectMethod(parentPath))
77
- maybe.write(isNext(parentPath) || trailingComma, ',');
78
68
  },
79
69
  afterIf: shouldAddNewlineAfter,
80
70
  after(path, {write}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.3.3",
3
+ "version": "18.3.5",
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",