@putout/printer 18.29.0 → 18.31.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,13 @@
1
+ 2026.07.07, v18.31.0
2
+
3
+ feature:
4
+ - e626cdfd @putout/printer: WhileStatement: inside LabeledStatement
5
+
6
+ 2026.07.03, v18.30.0
7
+
8
+ feature:
9
+ - 3d01c7f0 @putout/printer: ExpressionStatement: comments: line: same
10
+
1
11
  2026.07.03, v18.29.0
2
12
 
3
13
  feature:
@@ -1,13 +1,11 @@
1
1
  const isArg = (path) => path.parentPath.isFunction();
2
2
 
3
- export const AssignmentPattern = {
4
- print(path, {print, maybe}) {
5
- maybe.print(shouldPrint(path), '__left');
6
- print.space();
7
- print('=');
8
- print.space();
9
- print('__right');
10
- },
3
+ export const AssignmentPattern = (path, {print, maybe}) => {
4
+ maybe.print(shouldPrint(path), '__left');
5
+ print.space();
6
+ print('=');
7
+ print.space();
8
+ print('__right');
11
9
  };
12
10
 
13
11
  function shouldPrint(path) {
@@ -21,30 +21,28 @@ const isNotJSX = ({parentPath}) => {
21
21
  return !grandPath.isLogicalExpression();
22
22
  };
23
23
 
24
- export const JSXOpeningElement = {
25
- print(path, {print, maybe}) {
26
- maybe.indent(isNotJSX(path));
27
- print('<');
28
- print('__name');
29
-
30
- const coupleLines = isCoupleLines(path);
31
- const noCoupleLines = !coupleLines;
32
- const shouldIndent = coupleLines && path.parentPath.parentPath.isJSXElement();
33
-
34
- maybe.indent.inc(shouldIndent);
35
-
36
- for (const attr of path.get('attributes')) {
37
- maybe.print.space(noCoupleLines);
38
- print(attr);
39
- }
40
-
41
- if (isCoupleLines(path))
42
- print.breakline();
43
-
44
- if (path.node.selfClosing)
45
- print('/');
46
-
47
- print('>');
48
- maybe.indent.dec(shouldIndent);
49
- },
24
+ export const JSXOpeningElement = (path, {print, maybe}) => {
25
+ maybe.indent(isNotJSX(path));
26
+ print('<');
27
+ print('__name');
28
+
29
+ const coupleLines = isCoupleLines(path);
30
+ const noCoupleLines = !coupleLines;
31
+ const shouldIndent = coupleLines && path.parentPath.parentPath.isJSXElement();
32
+
33
+ maybe.indent.inc(shouldIndent);
34
+
35
+ for (const attr of path.get('attributes')) {
36
+ maybe.print.space(noCoupleLines);
37
+ print(attr);
38
+ }
39
+
40
+ if (isCoupleLines(path))
41
+ print.breakline();
42
+
43
+ if (path.node.selfClosing)
44
+ print('/');
45
+
46
+ print('>');
47
+ maybe.indent.dec(shouldIndent);
50
48
  };
@@ -36,10 +36,8 @@ export const printTrailingCommentLine = (path, printer, semantics, {isSameLine,
36
36
 
37
37
  if (isSameLine)
38
38
  print.space();
39
- else if (!isNext(path) || isNextNotSimple(path))
40
- print.breakline();
41
39
  else
42
- print.indent();
40
+ print.breakline();
43
41
 
44
42
  printComment();
45
43
 
@@ -54,9 +52,7 @@ const isSimple = createTypeChecker([
54
52
  '+: node.expression -> BooleanLiteral',
55
53
  ]);
56
54
 
57
- const isNextNotSimple = createTypeChecker([
58
- ['+: -> !', callWithNext(isSimple)],
59
- ]);
55
+ export const isNextSimple = callWithNext(isSimple);
60
56
 
61
57
  export const printLeadingCommentBlock = (path, printer, semantics, {printComment}) => {
62
58
  const {indent} = printer;
@@ -16,6 +16,7 @@ import {
16
16
  printLeadingCommentBlock,
17
17
  printTrailingCommentLine,
18
18
  printTrailingCommentBlock,
19
+ isNextSimple,
19
20
  } from './comments.js';
20
21
 
21
22
  const {isIfStatement} = types;
@@ -29,7 +30,16 @@ const isNextToAssignmentCall = createTypeChecker([
29
30
  ['+', callWithNext(isCallInsideExpression)],
30
31
  ]);
31
32
 
33
+ const hasTrailingCommentOnTheSameLine = createTypeChecker([
34
+ ['-: node.trailingComments.length -> -'],
35
+ ['-: -> !', hasLeadingComment],
36
+ ['+', isSameLine],
37
+ ]);
38
+
32
39
  const isBreakline = createTypeChecker([
40
+ ['+: node.expression -> ArrayExpression'],
41
+ ['-', callWithNext(hasTrailingCommentOnTheSameLine)],
42
+ ['-', isNextSimple],
33
43
  ['+', isNewlineBetweenSiblings],
34
44
  ['+', callWithNext(isIfStatement)],
35
45
  ]);
@@ -97,4 +107,3 @@ export const ExpressionStatement = {
97
107
  export const isNewlineAfter = createTypeChecker([
98
108
  ['+: -> !', hasTrailingComment],
99
109
  ]);
100
-
@@ -1,15 +1,20 @@
1
- import {isNext} from '#is';
1
+ import {isInsideLabel, isNext} from '#is';
2
2
  import {markAfter} from '#mark';
3
3
  import {
4
4
  printTrailingCommentBlock,
5
5
  printTrailingCommentLine,
6
6
  } from './while-statement-comments.js';
7
7
 
8
+ const not = (fn) => (...a) => !fn(...a);
9
+
8
10
  export const WhileStatement = {
9
11
  printTrailingCommentBlock,
10
12
  printTrailingCommentLine,
11
- print(path, {print, indent}) {
13
+ beforeIf: not(isInsideLabel),
14
+ before: (path, {indent}) => {
12
15
  indent();
16
+ },
17
+ print(path, {print, indent}) {
13
18
  print('while');
14
19
  print.space();
15
20
  print('(');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.29.0",
3
+ "version": "18.31.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",