@putout/printer 17.10.1 → 17.12.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,18 @@
1
+ 2026.03.03, v17.12.0
2
+
3
+ feature:
4
+ - aa951ef @putout/printer: IfStatement: trailing comments
5
+ - 3c15683 @putout/printer: isParentBlock: reuse
6
+
7
+ 2026.03.03, v17.11.0
8
+
9
+ feature:
10
+ - 08981fd @putout/printer: WhileStatement: trailng comments: improve support
11
+ - abfacc7 @putout/printer: superc8 v12.2.4
12
+ - 0ff4fb3 @putout/printer: @putout/eslint v6.0.0
13
+ - aa35981 @putout/printer: #mark: add
14
+ - 52f16d2 @putout/printer: IfStatement: comments with next sibling
15
+
1
16
  2026.03.03, v17.10.1
2
17
 
3
18
  feature:
@@ -1,4 +1,8 @@
1
1
  import {maybeParens} from '#maybe-parens';
2
+ import {
3
+ isParentBlock,
4
+ isParentProgram,
5
+ } from '#is';
2
6
  import {condition} from './maybe-parens-condition.js';
3
7
  import {printSeparator} from './print-separator.js';
4
8
  import {
@@ -8,8 +12,6 @@ import {
8
12
  printLeadingCommentBlock,
9
13
  } from './assignment-expression-comments.js';
10
14
 
11
- const isInsideBlock = ({parentPath}) => /BlockStatement|Program/.test(parentPath.type);
12
-
13
15
  export const AssignmentExpression = maybeParens({
14
16
  checkParens: false,
15
17
  condition,
@@ -25,7 +27,7 @@ export const AssignmentExpression = maybeParens({
25
27
  printSeparator(path, printer);
26
28
  print('__right');
27
29
 
28
- if (isInsideBlock(path)) {
30
+ if (isParentBlock(path) || isParentProgram(path)) {
29
31
  print(';');
30
32
  print.breakline();
31
33
  }
@@ -36,3 +38,4 @@ export const AssignmentExpression = maybeParens({
36
38
 
37
39
  AssignmentExpression.printLeadingCommentLine = printLeadingCommentLine;
38
40
  AssignmentExpression.printLeadingCommentBlock = printLeadingCommentBlock;
41
+
@@ -51,7 +51,7 @@ export const FunctionDeclaration = {
51
51
  print.space();
52
52
  print('__body');
53
53
  },
54
- afterSatisfy: () => [isNext, isNextParent, isInsideBlockStatement],
54
+ afterSatisfy: () => [isNext, isNextParent, isInsideBlockLike],
55
55
  after(path, {indent, maybe}) {
56
56
  if (isNextAssign(path) || isNextFunction(path) || isNext(path))
57
57
  indent();
@@ -75,7 +75,7 @@ const isNextAssign = (path) => {
75
75
  return isAssignmentExpression(next.node.expression);
76
76
  };
77
77
 
78
- function isInsideBlockStatement(path) {
78
+ function isInsideBlockLike(path) {
79
79
  const {parentPath} = path;
80
80
 
81
81
  if (isTSModuleBlock(parentPath.parentPath))
@@ -16,6 +16,7 @@ const {
16
16
 
17
17
  export const isParentProgram = (path) => path.parentPath?.isProgram();
18
18
  export const isParentBlock = (path) => path.parentPath.isBlockStatement();
19
+ export const isInsideBlockLike = (path) => /^(Program|BlockStatement|TSModuleBlock|SwitchCase)$/.test(path.parentPath.type);
19
20
 
20
21
  export const isNext = (path) => {
21
22
  const next = path.getNextSibling();
@@ -177,3 +178,4 @@ export const hasLeadingComment = (path) => path.node?.leadingComments?.length;
177
178
 
178
179
  export const noTrailingComment = (path) => !path.node.trailingComments?.length;
179
180
  export const noLeadingComment = (path) => !path.node.leadingComments?.length;
181
+
@@ -6,6 +6,7 @@ import {
6
6
  isLast,
7
7
  exists,
8
8
  satisfy,
9
+ isParentBlock,
9
10
  } from '#is';
10
11
  import {parseComments} from '../../comment/comment.js';
11
12
  import {insideIfWithNoBody} from './inside-if-with-no-body.js';
@@ -18,7 +19,6 @@ const {
18
19
  isFunctionDeclaration,
19
20
  isExportDeclaration,
20
21
  isDoWhileStatement,
21
- isBlockStatement,
22
22
  isArrayExpression,
23
23
  } = types;
24
24
 
@@ -127,7 +127,6 @@ const NEWLINE = true;
127
127
  const NO_NEWLINE = false;
128
128
 
129
129
  const isInsideDoWhile = ({parentPath}) => isDoWhileStatement(parentPath);
130
- const isInsideBlock = ({parentPath}) => isBlockStatement(parentPath);
131
130
 
132
131
  const isNoNewline = satisfy([
133
132
  isInsideDoWhile,
@@ -136,7 +135,7 @@ const isNoNewline = satisfy([
136
135
  ]);
137
136
 
138
137
  function shouldAddNewlineAfter(path) {
139
- if (isInsideBlock(path))
138
+ if (isParentBlock(path))
140
139
  return NEWLINE;
141
140
 
142
141
  if (isNoNewline(path))
@@ -1,6 +1,8 @@
1
- import {isNext, isInsideIf} from '#is';
2
-
3
- const isInsideBlock = (path) => path.parentPath.isBlockStatement();
1
+ import {
2
+ isNext,
3
+ isInsideIf,
4
+ isParentBlock,
5
+ } from '#is';
4
6
 
5
7
  export const DebuggerStatement = {
6
8
  print(path, {print, indent}) {
@@ -9,7 +11,7 @@ export const DebuggerStatement = {
9
11
  },
10
12
  afterSatisfy: () => [
11
13
  isNext,
12
- isInsideBlock,
14
+ isParentBlock,
13
15
  isInsideIf,
14
16
  ],
15
17
  after(path, {print}) {
@@ -1,5 +1,5 @@
1
1
  import {types} from '@putout/babel';
2
- import {isNext} from '#is';
2
+ import {isNext, isParentBlock} from '#is';
3
3
 
4
4
  const {isBlockStatement} = types;
5
5
 
@@ -9,17 +9,21 @@ export const printTrailingCommentBlock = (path, printer, semantics, {printCommen
9
9
 
10
10
  maybe.print.breakline(!hasNext);
11
11
  printComment();
12
- //maybe.print.breakline(hasNext);
13
12
  };
14
13
 
15
14
  export const printTrailingCommentLine = (path, printer, semantics, {printComment}) => {
15
+ const hasNext = isNext(path);
16
16
  const {consequent} = path.node;
17
17
  const consequentIsBlock = isBlockStatement(consequent);
18
- const {print, maybe} = printer;
18
+ const {print} = printer;
19
19
 
20
20
  print.indent();
21
- maybe.print.space(!consequentIsBlock);
21
+
22
+ if (!hasNext && !consequentIsBlock)
23
+ print.space();
22
24
 
23
25
  printComment();
24
- maybe.print.newline(consequentIsBlock);
26
+
27
+ if (hasNext || isParentBlock(path))
28
+ print.newline();
25
29
  };
@@ -1,5 +1,9 @@
1
1
  import {types} from '@putout/babel';
2
- import {isNext, isNextTry} from '#is';
2
+ import {
3
+ isNext,
4
+ isNextTry,
5
+ isParentBlock,
6
+ } from '#is';
3
7
 
4
8
  const {isExpressionStatement} = types;
5
9
 
@@ -34,6 +38,7 @@ const isNextExpression = (path) => {
34
38
  };
35
39
 
36
40
  export const CatchClause = (path, {print, maybe}) => {
41
+ const {parentPath} = path;
37
42
  const param = path.get('param');
38
43
  const body = path.get('body');
39
44
 
@@ -50,9 +55,5 @@ export const CatchClause = (path, {print, maybe}) => {
50
55
  }
51
56
 
52
57
  print(body);
53
- maybe.print.newline(isInsideBlock(path));
58
+ maybe.print.newline(isParentBlock(parentPath));
54
59
  };
55
-
56
- function isInsideBlock(path) {
57
- return path.parentPath.parentPath.isBlockStatement();
58
- }
@@ -6,6 +6,7 @@ import {
6
6
  isNewlineBetweenSiblings,
7
7
  exists,
8
8
  noTrailingComment,
9
+ isInsideBlockLike,
9
10
  } from '#is';
10
11
  import {maybeSpaceAfterKeyword} from './maybe-space-after-keyword.js';
11
12
  import {isConcatenation} from '../../expressions/binary-expression/concatenate.js';
@@ -16,7 +17,6 @@ const {isExportDeclaration} = types;
16
17
 
17
18
  const isParentTSModuleBlock = (path) => path.parentPath.isTSModuleBlock();
18
19
  const isParentBlock = (path) => /Program|BlockStatement|Export|LabeledStatement/.test(path.parentPath.type);
19
- const isInsideBlock = (path) => /^(Program|BlockStatement|TSModuleBlock|SwitchCase)$/.test(path.parentPath.type);
20
20
  const isParentSwitchCase = (path) => path.parentPath.isSwitchCase();
21
21
  const isFirstInSwitch = (path) => path.parentPath.get('consequent.0') === path;
22
22
  const isParentIf = (path) => path.parentPath.isIfStatement();
@@ -29,7 +29,7 @@ export const VariableDeclaration = {
29
29
  print: maybeDeclare((path, {maybe, store, write, traverse, print, indent}, semantics) => {
30
30
  const {maxVariablesInOneLine} = semantics;
31
31
 
32
- maybe.indent(isInsideBlock(path));
32
+ maybe.indent(isInsideBlockLike(path));
33
33
 
34
34
  write(path.node.kind);
35
35
  maybeSpaceAfterKeyword(path, {
@@ -0,0 +1,18 @@
1
+ import {isNext} from '#is';
2
+
3
+ export const printTrailingCommentBlock = (path, printer, semantics, {printComment}) => {
4
+ const {maybe} = printer;
5
+ const hasNext = isNext(path);
6
+
7
+ maybe.print.breakline(!hasNext);
8
+ printComment();
9
+ };
10
+
11
+ export const printTrailingCommentLine = (path, printer, semantics, {printComment}) => {
12
+ const {print} = printer;
13
+
14
+ print.indent();
15
+
16
+ printComment();
17
+ print.newline();
18
+ };
@@ -1,7 +1,13 @@
1
1
  import {isNext} from '#is';
2
2
  import {markAfter} from '#mark';
3
+ import {
4
+ printTrailingCommentBlock,
5
+ printTrailingCommentLine,
6
+ } from './while-statement-comments.js';
3
7
 
4
8
  export const WhileStatement = {
9
+ printTrailingCommentBlock,
10
+ printTrailingCommentLine,
5
11
  print(path, {print, indent}) {
6
12
  indent();
7
13
  print('while');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "17.10.1",
3
+ "version": "17.12.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",
@@ -65,7 +65,7 @@
65
65
  },
66
66
  "devDependencies": {
67
67
  "@babel/parser": "^7.28.5",
68
- "@putout/eslint": "^5.0.2",
68
+ "@putout/eslint": "^6.0.0",
69
69
  "@putout/eslint-flat": "^4.0.0",
70
70
  "@putout/plugin-minify": "^11.2.1",
71
71
  "@putout/plugin-printer": "^7.0.0",
@@ -73,7 +73,6 @@
73
73
  "@putout/plugin-react-hook-form": "^6.0.0",
74
74
  "@putout/plugin-react-hooks": "^9.0.0",
75
75
  "acorn": "^8.8.2",
76
- "c8": "^10.1.2",
77
76
  "check-dts": "^0.9.0",
78
77
  "escover": "^6.0.0",
79
78
  "eslint": "^10.0.0",
@@ -87,6 +86,7 @@
87
86
  "putout": "^42.0.1",
88
87
  "redlint": "^6.0.0",
89
88
  "samadhi": "^4.0.2",
89
+ "superc8": "^12.2.4",
90
90
  "supertape": "^12.0.9",
91
91
  "try-catch": "^4.0.6",
92
92
  "typescript": "^5.3.3"