@putout/printer 18.3.6 → 18.4.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,20 @@
1
+ 2026.03.10, v18.4.1
2
+
3
+ feature:
4
+ - 4f2fb23 @putout/printer: is-concatenation
5
+ - 9c1917c @putout/printer: BinaryExpression: concatenate: simplify
6
+ - a8f5542 @putout/printer: ObjectExpression: ObjectProperty: isSpaceAfterComma
7
+ - e79a33c @putout/printer: ObjectExpression: ObjectProperty: space
8
+ - d206ffa @putout/printer: ObjectProperty: isCommaAfterProperty
9
+
10
+ 2026.03.10, v18.4.0
11
+
12
+ feature:
13
+ - 3bcdf4b @putout/printer: ObjectExpression: callWithCallee
14
+ - e205336 @putout/printer: ObjectExpression: isNewlineAfterProperty
15
+ - c4f998d @putout/printer: ObjectExpression: comma: simplify
16
+ - 2a49a3f @putout/printer: ObjectExpression: isLinebreakAfterProperty
17
+
1
18
  2026.03.10, v18.3.6
2
19
 
3
20
  feature:
@@ -1,8 +1,6 @@
1
1
  import {maybeParens} from '#maybe-parens';
2
- import {
3
- concatenate,
4
- isConcatenation,
5
- } from './concatenate.js';
2
+ import {isConcatenation} from '#is-concatenation';
3
+ import {concatenate} from './concatenate.js';
6
4
  import {maybeSpace} from './maybe-space.js';
7
5
 
8
6
  export const BinaryExpression = maybeParens((path, {print, indent, maybe}) => {
@@ -1,52 +1,9 @@
1
- import {types} from '@putout/babel';
1
+ import {maybeInsideBinary} from './maybe-inside-binary.js';
2
2
 
3
- const {
4
- isStringLiteral,
5
- isTemplateLiteral,
6
- isBinaryExpression,
7
- } = types;
8
-
9
- const isStringLike = (a) => {
10
- if (isStringLiteral(a))
11
- return true;
12
-
13
- return isTemplateLiteral(a);
14
- };
15
-
16
- export const isConcatenation = (path) => {
17
- const {parentPath} = path;
18
- const {operator} = path.node;
19
-
20
- if (operator !== '+')
21
- return false;
22
-
23
- const startLine = path.node.loc?.start.line;
24
- const endLine = path.node.loc?.end.line;
25
-
26
- if (startLine === endLine)
27
- return false;
28
-
29
- const left = path.get('left');
30
- const right = path.get('right');
31
-
32
- if (isStringLike(left) && isStringLike(right) && isBinaryExpression(parentPath))
33
- return true;
34
-
35
- return isBinaryExpression(left) && isStringLike(right);
36
- };
37
-
38
- export const concatenate = (path, {print, indent}) => {
39
- if (!path.parentPath.isBinaryExpression()) {
40
- indent.inc();
41
- print.breakline();
42
- }
43
-
3
+ export const concatenate = maybeInsideBinary((path, {print}) => {
44
4
  print('__left');
45
5
  print.space();
46
6
  print('+');
47
7
  print.breakline();
48
8
  print('__right');
49
-
50
- if (!path.parentPath.isBinaryExpression())
51
- indent.dec();
52
- };
9
+ });
@@ -0,0 +1,16 @@
1
+ import {types} from '@putout/babel';
2
+ import {createTypeChecker} from '#type-checker';
3
+
4
+ const {isBinaryExpression} = types;
5
+
6
+ export const isConcatenation = createTypeChecker([
7
+ ['-: node.loc', isSameLine],
8
+ ['+', isBinaryExpression],
9
+ ]);
10
+
11
+ function isSameLine(loc) {
12
+ const startLine = loc?.start.line;
13
+ const endLine = loc?.end.line;
14
+
15
+ return startLine === endLine;
16
+ }
@@ -0,0 +1,20 @@
1
+ import {types} from '@putout/babel';
2
+
3
+ const {isBinaryExpression} = types;
4
+ const isInsideBinary = ({parentPath}) => isBinaryExpression(parentPath);
5
+
6
+ export const maybeInsideBinary = (fn) => (path, printer, semantics) => {
7
+ const {indent, print} = printer;
8
+ const insideBinary = isInsideBinary(path);
9
+
10
+ if (!insideBinary) {
11
+ indent.inc();
12
+ print.breakline();
13
+ }
14
+
15
+ fn(path, printer, semantics);
16
+
17
+ if (!insideBinary)
18
+ indent.dec();
19
+ };
20
+
@@ -4,21 +4,15 @@ import {
4
4
  isTrailingCommaOption,
5
5
  } from '../array-expression/is.js';
6
6
 
7
- const isCouple = (a) => a > 1;
8
7
  const isLastProperty = ({node, parentPath}) => node === parentPath.node.properties.at(-1);
9
8
 
10
- const isCoupleOrManyLines = createTypeChecker([
11
- ['+: parentPath.node.properties.length ->', isCouple],
12
- ['+', isMultilineOption],
13
- ]);
14
-
15
- const isLastOrTrailingComma = createTypeChecker([
9
+ export const isCommaAfterProperty = createTypeChecker([
16
10
  ['+: -> !', isLastProperty],
11
+ ['-: -> !', isMultilineOption],
17
12
  ['+', isTrailingCommaOption],
18
13
  ]);
19
14
 
20
- export const isCommaAfterProperty = createTypeChecker([
15
+ export const isCommaAfterSpread = createTypeChecker([
21
16
  ['-: -> !SpreadElement'],
22
- ['-: -> !', isCoupleOrManyLines],
23
- ['+', isLastOrTrailingComma],
17
+ ['+', isCommaAfterProperty],
24
18
  ]);
@@ -0,0 +1,12 @@
1
+ import {createTypeChecker} from '#type-checker';
2
+ import {
3
+ callWithNext,
4
+ hasLeadingComment,
5
+ isNewlineBetweenSiblings,
6
+ } from '#is';
7
+
8
+ export const isLinebreakAfterProperty = createTypeChecker([
9
+ ['-: -> SpreadElement'],
10
+ ['-', callWithNext(hasLeadingComment)],
11
+ ['+', isNewlineBetweenSiblings],
12
+ ]);
@@ -0,0 +1,12 @@
1
+ import {createTypeChecker} from '#type-checker';
2
+ import {
3
+ callWithNext,
4
+ hasLeadingComment,
5
+ } from '#is';
6
+ import {isMultilineOption} from '../array-expression/is.js';
7
+
8
+ export const isNewlineAfterProperty = createTypeChecker([
9
+ ['-: -> !', isMultilineOption],
10
+ ['+: -> SpreadElement'],
11
+ ['+: -> !', callWithNext(hasLeadingComment)],
12
+ ]);
@@ -4,21 +4,19 @@ import {
4
4
  isCoupleLines,
5
5
  isForOf,
6
6
  isIf,
7
- isNewlineBetweenSiblings,
8
7
  hasLeadingComment,
9
8
  isInsideCall,
10
9
  isInsideBody,
11
10
  isInsideExpression,
12
- callWithNext,
13
11
  hasTrailingComment,
14
12
  } from '#is';
15
13
  import {parseComments} from '../../comment/comment.js';
16
14
  import {isInsideTuple} from './is-inside-tuple.js';
17
15
  import {isLooksLikeChain} from '../member-expression/is-looks-like-chain.js';
18
- import {isCommaAfterProperty} from './comma.js';
16
+ import {isCommaAfterSpread} from './comma.js';
19
17
  import {isMultilineOption} from '../array-expression/is.js';
20
-
21
- const hasNextLeadingComment = callWithNext(hasLeadingComment);
18
+ import {isLinebreakAfterProperty} from './linebreak.js';
19
+ import {isNewlineAfterProperty} from './newline.js';
22
20
 
23
21
  const notLastArgInsideCall = (path) => {
24
22
  const {parentPath} = path;
@@ -35,19 +33,16 @@ const notLastArgInsideCall = (path) => {
35
33
  const hasNoProperties = (path) => !path.node.properties.length;
36
34
  const hasValue = (path) => path.node.properties[0].value;
37
35
 
38
- const {
39
- isMemberExpression,
40
- isSpreadElement,
41
- } = types;
36
+ const {isMemberExpression} = types;
42
37
 
43
38
  const isParens = createTypeChecker([isInsideBody, isInsideExpression]);
44
39
 
45
- const getCallee = (fn) => (a) => fn(a.get('callee'));
40
+ const callWithCallee = (fn) => (a) => fn(a.get('callee'));
46
41
 
47
42
  const isMemberExpressionCallee = createTypeChecker([
48
43
  ['-: parentPath -> !CallExpression'],
49
- ['-: parentPath -> !', getCallee(isMemberExpression)],
50
- ['+: parentPath', getCallee(isLooksLikeChain)],
44
+ ['-: parentPath -> !', callWithCallee(isMemberExpression)],
45
+ ['+: parentPath', callWithCallee(isLooksLikeChain)],
51
46
  ]);
52
47
 
53
48
  const isInsideNestedArrayCall = createTypeChecker([
@@ -65,10 +60,10 @@ const isInsideTupleLike = createTypeChecker([
65
60
  export const isMultiline = createTypeChecker([
66
61
  ['-', hasNoProperties],
67
62
  ['-: parentPath -> ForOfStatement'],
68
- ['+: node.properties.0 -> SpreadElement'],
69
63
  ['-', notLastArgInsideCall],
70
64
  ['-', isForOf],
71
65
  ['-', isIf],
66
+ ['+: node.properties.0 -> SpreadElement'],
72
67
  ['+', isCoupleLines],
73
68
  ['+', hasValue],
74
69
  ]);
@@ -91,7 +86,7 @@ export const ObjectExpression = (path, printer, semantics) => {
91
86
  maybe.indent.inc(!insideNestedArrayCall);
92
87
 
93
88
  const properties = path.get('properties');
94
- const {length} = properties;
89
+
95
90
  const parens = isParens(path);
96
91
  const multiline = isMultiline(path);
97
92
 
@@ -104,8 +99,6 @@ export const ObjectExpression = (path, printer, semantics) => {
104
99
  maybe.indent.inc(memberCallee);
105
100
 
106
101
  for (const property of properties) {
107
- const couple = length > 1;
108
-
109
102
  if (isIndentBeforeProperty(property, {multiline}))
110
103
  indent();
111
104
 
@@ -117,15 +110,15 @@ export const ObjectExpression = (path, printer, semantics) => {
117
110
  if (hasTrailingComment(property))
118
111
  continue;
119
112
 
120
- maybe.print(isCommaAfterProperty(property, {
113
+ maybe.print(isCommaAfterSpread(property, {
121
114
  multiline,
122
115
  trailingComma,
123
116
  }), ',');
124
117
 
125
- if (!isSpreadElement(property) && !hasNextLeadingComment(property) && multiline || property.isSpreadElement() && (couple || multiline))
118
+ if (isNewlineAfterProperty(property, {multiline}))
126
119
  print.newline();
127
120
 
128
- if (!isSpreadElement(property) && !hasNextLeadingComment(property) && isNewlineBetweenSiblings(property))
121
+ if (isLinebreakAfterProperty(property))
129
122
  print.linebreak();
130
123
  }
131
124
 
@@ -1,6 +1,8 @@
1
- import {isConcatenation} from '../binary-expression/concatenate.js';
1
+ import {isConcatenation} from '#is-concatenation';
2
2
  import {isMultiline} from './object-expression.js';
3
3
  import {printKey} from './print-key.js';
4
+ import {isCommaAfterProperty} from './comma.js';
5
+ import {isSpaceAfterComma} from './space.js';
4
6
 
5
7
  export const ObjectProperty = (path, printer, semantics) => {
6
8
  const {trailingComma} = semantics;
@@ -12,8 +14,6 @@ export const ObjectProperty = (path, printer, semantics) => {
12
14
  } = printer;
13
15
 
14
16
  const value = path.get('value');
15
- const properties = path.parentPath.get('properties');
16
- const isLast = path === properties.at(-1);
17
17
  const multiline = isMultiline(path.parentPath);
18
18
 
19
19
  printKey(path, printer);
@@ -24,11 +24,9 @@ export const ObjectProperty = (path, printer, semantics) => {
24
24
  traverse(value);
25
25
  }
26
26
 
27
- if (multiline) {
28
- maybe.write(!isLast || trailingComma, ',');
29
- return;
30
- }
27
+ if (isCommaAfterProperty(path, {multiline, trailingComma}))
28
+ write(',');
31
29
 
32
- if (!isLast && properties.length)
33
- write(', ');
30
+ if (isSpaceAfterComma(path, {multiline}))
31
+ write.space();
34
32
  };
@@ -0,0 +1,9 @@
1
+ import {createTypeChecker} from '#type-checker';
2
+ import {isMultilineOption} from '../array-expression/is.js';
3
+
4
+ const isLast = ({node, parentPath}) => node === parentPath.node.properties.at(-1);
5
+
6
+ export const isSpaceAfterComma = createTypeChecker([
7
+ ['-', isMultilineOption],
8
+ ['+: -> !', isLast],
9
+ ]);
@@ -1,6 +1,7 @@
1
1
  import {types} from '@putout/babel';
2
2
  import {hasPrevNewline} from '#mark';
3
3
  import {createTypeChecker} from '#type-checker';
4
+ import {isConcatenation} from '#is-concatenation';
4
5
  import {
5
6
  isNext,
6
7
  isCoupleLines,
@@ -17,7 +18,6 @@ import {
17
18
  callWithParent,
18
19
  } from '#is';
19
20
  import {maybeSpaceAfterKeyword} from './maybe-space-after-keyword.js';
20
- import {isConcatenation} from '../../expressions/binary-expression/concatenate.js';
21
21
  import {parseLeadingComments} from '../../comment/comment.js';
22
22
  import {maybeDeclare} from '../../maybe/maybe-declare.js';
23
23
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.3.6",
3
+ "version": "18.4.1",
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",
@@ -68,7 +68,8 @@
68
68
  "#types": "./lib/types.js",
69
69
  "#type-checker": "./lib/tokenize/type-checker/type-checker.js",
70
70
  "#type-checker/instrument": "./lib/tokenize/type-checker/instrument.js",
71
- "#type-checker/report": "./lib/tokenize/type-checker/report.js"
71
+ "#type-checker/report": "./lib/tokenize/type-checker/report.js",
72
+ "#is-concatenation": "./lib/tokenize/expressions/binary-expression/is-contatenation.js"
72
73
  },
73
74
  "devDependencies": {
74
75
  "@babel/parser": "^7.28.5",