@putout/printer 17.10.0 → 17.10.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.
Files changed (25) hide show
  1. package/ChangeLog +6 -0
  2. package/lib/tokenize/comment/parse-leading-comments.js +1 -1
  3. package/lib/tokenize/expressions/assignment-expression/print-separator.js +5 -3
  4. package/lib/tokenize/expressions/class/class.js +1 -1
  5. package/lib/tokenize/expressions/function/function-declaration.js +1 -1
  6. package/lib/tokenize/expressions/function/kind.js +5 -2
  7. package/lib/tokenize/expressions/new-expression/new-expression.js +1 -1
  8. package/lib/tokenize/expressions/object-expression/object-property.js +5 -2
  9. package/lib/tokenize/printer/printer.js +1 -1
  10. package/lib/tokenize/statements/block-statement/block-statement.js +1 -1
  11. package/lib/tokenize/statements/export-declaration/export-declaration.js +1 -1
  12. package/lib/tokenize/statements/for-of-statement/for-of-statement.js +1 -1
  13. package/lib/tokenize/statements/for-statement.js +9 -7
  14. package/lib/tokenize/statements/if-statement/if-statement-comments.js +6 -2
  15. package/lib/tokenize/statements/if-statement/if-statement.js +1 -1
  16. package/lib/tokenize/statements/import-declaration/import-declaration.js +1 -1
  17. package/lib/tokenize/statements/return-statement/return-statement.js +1 -1
  18. package/lib/tokenize/statements/variable-declaration/variable-declaration.js +1 -1
  19. package/lib/tokenize/statements/while-statement/while-statement.js +8 -6
  20. package/lib/tokenize/statements/with-statement/with-statement.js +8 -6
  21. package/lib/tokenize/typescript/enum/ts-enum-declaration.js +1 -1
  22. package/lib/tokenize/typescript/interface/ts-interface-declaration.js +1 -1
  23. package/lib/tokenize/typescript/ts-union-type/ts-union-type.js +5 -3
  24. package/lib/tokenize/typescript/type/ts-type-alias-declaration.js +1 -1
  25. package/package.json +2 -1
package/ChangeLog CHANGED
@@ -1,3 +1,9 @@
1
+ 2026.03.03, v17.10.1
2
+
3
+ feature:
4
+ - 250f066 @putout/printer: #mark: add
5
+ - 6f44535 @putout/printer: IfStatement: comments with next sibling
6
+
1
7
  2026.03.03, v17.10.0
2
8
 
3
9
  feature:
@@ -3,7 +3,7 @@ import {
3
3
  hasTrailingComment,
4
4
  satisfy,
5
5
  } from '#is';
6
- import {markBefore} from '../mark.js';
6
+ import {markBefore} from '#mark';
7
7
  import {maybeInsideFn} from './maybe-inside-fn.js';
8
8
  import {
9
9
  printLeadingComments,
@@ -6,10 +6,12 @@ const {
6
6
  } = types;
7
7
 
8
8
  export const printSeparator = (path, {print}) => {
9
- if (isMultiline(path))
9
+ if (isMultiline(path)) {
10
10
  print.breakline();
11
- else
12
- print.space();
11
+ return;
12
+ }
13
+
14
+ print.space();
13
15
  };
14
16
 
15
17
  function isMultiline(path) {
@@ -1,6 +1,6 @@
1
1
  import {types} from '@putout/babel';
2
2
  import {isNext} from '#is';
3
- import {markAfter} from '../../mark.js';
3
+ import {markAfter} from '#mark';
4
4
  import {maybeDeclare} from '../../maybe/maybe-declare.js';
5
5
  import {parseComments} from '../../comment/comment.js';
6
6
  import {maybeDecorators} from '../../maybe/maybe-decorators.js';
@@ -1,7 +1,7 @@
1
1
  import {types} from '@putout/babel';
2
2
  import {isNext, isNextParent} from '#is';
3
3
  import {printParams} from '#print-params';
4
- import {markAfter} from '../../mark.js';
4
+ import {markAfter} from '#mark';
5
5
 
6
6
  const not = (fn) => (...a) => !fn(...a);
7
7
  const notInsideExportDefaultWithBody = not(isInsideExportDefaultWithBody);
@@ -3,8 +3,11 @@ export const printKind = (path, {write}) => {
3
3
 
4
4
  const isGetter = kind === 'get' || kind === 'set';
5
5
 
6
- if (isGetter)
6
+ if (isGetter) {
7
7
  write(`${kind} `);
8
- else if (generator)
8
+ return;
9
+ }
10
+
11
+ if (generator)
9
12
  write('*');
10
13
  };
@@ -1,6 +1,6 @@
1
1
  import {types} from '@putout/babel';
2
2
  import {exists} from '#is';
3
- import {isMarkedAfter} from '../../mark.js';
3
+ import {isMarkedAfter} from '#mark';
4
4
 
5
5
  const {
6
6
  isExpressionStatement,
@@ -24,8 +24,11 @@ export const ObjectProperty = (path, printer, semantics) => {
24
24
  traverse(value);
25
25
  }
26
26
 
27
- if (manyLines)
27
+ if (manyLines) {
28
28
  maybe.write(!isLast || trailingComma, ',');
29
- else if (!isLast && properties.length)
29
+ return;
30
+ }
31
+
32
+ if (!isLast && properties.length)
30
33
  write(', ');
31
34
  };
@@ -1,7 +1,7 @@
1
1
  import {fullstore} from 'fullstore';
2
2
  import {TYPES} from '#types';
3
+ import {maybeMarkAfter} from '#mark';
3
4
  import {createDebug, createLog} from './debug.js';
4
- import {maybeMarkAfter} from '../mark.js';
5
5
  import * as baseVisitors from '../visitors.js';
6
6
  import {maybeVisitor, maybeThrow} from '../maybe/index.js';
7
7
  import {
@@ -1,4 +1,5 @@
1
1
  import {types} from '@putout/babel';
2
+ import {markAfter} from '#mark';
2
3
  import {
3
4
  isNext,
4
5
  isParentProgram,
@@ -6,7 +7,6 @@ import {
6
7
  exists,
7
8
  satisfy,
8
9
  } from '#is';
9
- import {markAfter} from '../../mark.js';
10
10
  import {parseComments} from '../../comment/comment.js';
11
11
  import {insideIfWithNoBody} from './inside-if-with-no-body.js';
12
12
  import {getDirectives} from './get-directives.js';
@@ -11,7 +11,7 @@ import {
11
11
  markAfter,
12
12
  isMarkedAfter,
13
13
  hasPrevNewline,
14
- } from '../../mark.js';
14
+ } from '#mark';
15
15
 
16
16
  const {
17
17
  isExportNamespaceSpecifier,
@@ -8,7 +8,7 @@ import {
8
8
  markAfter,
9
9
  markBefore,
10
10
  isMarkedAfter,
11
- } from '../../mark.js';
11
+ } from '#mark';
12
12
 
13
13
  export const ForOfStatement = {
14
14
  beforeIf(path) {
@@ -1,5 +1,5 @@
1
1
  import {isInsideLabel, exists} from '#is';
2
- import {markAfter} from '../mark.js';
2
+ import {markAfter} from '#mark';
3
3
 
4
4
  export const ForStatement = {
5
5
  print(path, {print, maybe}) {
@@ -26,13 +26,15 @@ export const ForStatement = {
26
26
  if (body.body) {
27
27
  print.space();
28
28
  print('__body');
29
- } else {
30
- const is = !path.get('body').isEmptyStatement();
31
- maybe.print.newline(is);
32
- maybe.indent.inc(is);
33
- print('__body');
34
- maybe.indent.dec(is);
29
+
30
+ return;
35
31
  }
32
+
33
+ const is = !path.get('body').isEmptyStatement();
34
+ maybe.print.newline(is);
35
+ maybe.indent.inc(is);
36
+ print('__body');
37
+ maybe.indent.dec(is);
36
38
  },
37
39
  afterIf(path) {
38
40
  return exists(path.getNextSibling());
@@ -1,11 +1,15 @@
1
1
  import {types} from '@putout/babel';
2
+ import {isNext} from '#is';
2
3
 
3
4
  const {isBlockStatement} = types;
4
5
 
5
6
  export const printTrailingCommentBlock = (path, printer, semantics, {printComment}) => {
6
- const {print} = printer;
7
- print.breakline();
7
+ const {maybe} = printer;
8
+ const hasNext = isNext(path);
9
+
10
+ maybe.print.breakline(!hasNext);
8
11
  printComment();
12
+ //maybe.print.breakline(hasNext);
9
13
  };
10
14
 
11
15
  export const printTrailingCommentLine = (path, printer, semantics, {printComment}) => {
@@ -4,7 +4,7 @@ import {
4
4
  isNext,
5
5
  isInsideIf,
6
6
  } from '#is';
7
- import {markAfter} from '../../mark.js';
7
+ import {markAfter} from '#mark';
8
8
  import {
9
9
  printTrailingCommentBlock,
10
10
  printTrailingCommentLine,
@@ -1,7 +1,7 @@
1
1
  import {parseImportSpecifiers} from 'parse-import-specifiers';
2
2
  import {isLast, isNext} from '#is';
3
3
  import {printAttributes} from '#import-attributes';
4
- import {markAfter} from '../../mark.js';
4
+ import {markAfter} from '#mark';
5
5
  import {
6
6
  printTrailingCommentBlock,
7
7
  printTrailingCommentLine,
@@ -1,4 +1,5 @@
1
1
  import {types} from '@putout/babel';
2
+ import {hasPrevNewline} from '#mark';
2
3
  import {
3
4
  isInsideLabel,
4
5
  isPrevBody,
@@ -6,7 +7,6 @@ import {
6
7
  isLast,
7
8
  isPrevTry,
8
9
  } from '#is';
9
- import {hasPrevNewline} from '../../mark.js';
10
10
  import {maybeSpaceAfterKeyword} from './maybe-space-after-keyword.js';
11
11
 
12
12
  const {isJSXElement} = types;
@@ -1,4 +1,5 @@
1
1
  import {types} from '@putout/babel';
2
+ import {hasPrevNewline} from '#mark';
2
3
  import {
3
4
  isNext,
4
5
  isCoupleLines,
@@ -6,7 +7,6 @@ import {
6
7
  exists,
7
8
  noTrailingComment,
8
9
  } from '#is';
9
- import {hasPrevNewline} from '../../mark.js';
10
10
  import {maybeSpaceAfterKeyword} from './maybe-space-after-keyword.js';
11
11
  import {isConcatenation} from '../../expressions/binary-expression/concatenate.js';
12
12
  import {parseLeadingComments} from '../../comment/comment.js';
@@ -1,5 +1,5 @@
1
1
  import {isNext} from '#is';
2
- import {markAfter} from '../../mark.js';
2
+ import {markAfter} from '#mark';
3
3
 
4
4
  export const WhileStatement = {
5
5
  print(path, {print, indent}) {
@@ -13,12 +13,14 @@ export const WhileStatement = {
13
13
  if (path.node.body.body) {
14
14
  print.space();
15
15
  print('__body');
16
- } else {
17
- indent.inc();
18
- print.newline();
19
- print('__body');
20
- indent.dec();
16
+
17
+ return;
21
18
  }
19
+
20
+ indent.inc();
21
+ print.newline();
22
+ print('__body');
23
+ indent.dec();
22
24
  },
23
25
  afterIf(path) {
24
26
  return isNext(path);
@@ -1,5 +1,5 @@
1
1
  import {isNext} from '#is';
2
- import {markAfter} from '../../mark.js';
2
+ import {markAfter} from '#mark';
3
3
 
4
4
  export const WithStatement = {
5
5
  print(path, {print, indent}) {
@@ -13,12 +13,14 @@ export const WithStatement = {
13
13
  if (path.node.body.body) {
14
14
  print.space();
15
15
  print('__body');
16
- } else {
17
- indent.inc();
18
- print.newline();
19
- print('__body');
20
- indent.dec();
16
+
17
+ return;
21
18
  }
19
+
20
+ indent.inc();
21
+ print.newline();
22
+ print('__body');
23
+ indent.dec();
22
24
  },
23
25
  afterIf(path) {
24
26
  return isNext(path);
@@ -3,7 +3,7 @@ import {
3
3
  isNextParent,
4
4
  isLast,
5
5
  } from '#is';
6
- import {markAfter} from '../../mark.js';
6
+ import {markAfter} from '#mark';
7
7
 
8
8
  export const TSEnumDeclaration = {
9
9
  beforeIf(path) {
@@ -1,7 +1,7 @@
1
1
  import {types} from '@putout/babel';
2
2
  import {isNext, isNextParent} from '#is';
3
+ import {markAfter} from '#mark';
3
4
  import {maybeDeclare} from '../../maybe/maybe-declare.js';
4
- import {markAfter} from '../../mark.js';
5
5
 
6
6
  const {
7
7
  isTSTypeAliasDeclaration,
@@ -10,10 +10,12 @@ export const TSUnionType = maybeParens({
10
10
  const types = path.get('types');
11
11
  const {length} = types;
12
12
 
13
- if (!insideTypeDeclaration(path) || length <= maxTypesInOneLine)
13
+ if (!insideTypeDeclaration(path) || length <= maxTypesInOneLine) {
14
14
  printInOneLine(types, printer);
15
- else
16
- printInCoupleLines(types, printer);
15
+ return;
16
+ }
17
+
18
+ printInCoupleLines(types, printer);
17
19
  },
18
20
  });
19
21
 
@@ -3,7 +3,7 @@ import {
3
3
  isNext,
4
4
  isNextParent,
5
5
  } from '#is';
6
- import {markAfter} from '../../mark.js';
6
+ import {markAfter} from '#mark';
7
7
  import {maybeDeclare} from '../../maybe/maybe-declare.js';
8
8
 
9
9
  const isNextType = (a) => a
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "17.10.0",
3
+ "version": "17.10.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",
@@ -57,6 +57,7 @@
57
57
  "#printer": "./lib/printer.js",
58
58
  "#test": "./test/create-test.js",
59
59
  "#is": "./lib/tokenize/is.js",
60
+ "#mark": "./lib/tokenize/mark.js",
60
61
  "#maybe-parens": "./lib/tokenize/maybe/maybe-parens.js",
61
62
  "#print-params": "./lib/tokenize/expressions/function/params.js",
62
63
  "#import-attributes": "./lib/tokenize/statements/import-declaration/import-attribute.js",