@putout/printer 18.4.5 → 18.4.7

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.12, v18.4.7
2
+
3
+ feature:
4
+ - de587ba @putout/printer: private imports: comments
5
+
6
+ 2026.03.12, v18.4.6
7
+
8
+ feature:
9
+ - 7c290de @putout/printer: BlockStatement: simplify
10
+ - 0dc390f @putout/printer: BlockStatement: indent
11
+
1
12
  2026.03.12, v18.4.5
2
13
 
3
14
  feature:
@@ -7,7 +7,7 @@ import {
7
7
  isInsideExportDeclaration,
8
8
  isNext,
9
9
  } from '#is';
10
- import {parseComments} from '../../comment/comment.js';
10
+ import {parseComments} from '#comments';
11
11
  import {maybeDecorators} from '../../maybe/maybe-decorators.js';
12
12
 
13
13
  const isFunctionLike = (path) => isFunction(path.parentPath.parentPath);
@@ -1,4 +1,4 @@
1
- import {parseComments} from '../../comment/comment.js';
1
+ import {parseComments} from '#comments';
2
2
 
3
3
  const noop = () => {};
4
4
  const parseParams = (path) => path.get('params');
@@ -1,5 +1,6 @@
1
1
  import {types} from '@putout/babel';
2
2
  import {createTypeChecker} from '#type-checker';
3
+ import {parseComments} from '#comments';
3
4
  import {
4
5
  isCoupleLines,
5
6
  isForOf,
@@ -10,7 +11,6 @@ import {
10
11
  isInsideExpression,
11
12
  hasTrailingComment,
12
13
  } from '#is';
13
- import {parseComments} from '../../comment/comment.js';
14
14
  import {isInsideTuple} from './is-inside-tuple.js';
15
15
  import {isLooksLikeChain} from '../member-expression/is-looks-like-chain.js';
16
16
  import {isCommaAfterSpread} from './comma.js';
@@ -1,5 +1,5 @@
1
1
  import {isCoupleLines} from '#is';
2
- import {parseComments} from '../comment/comment.js';
2
+ import {parseComments} from '#comments';
3
3
 
4
4
  export {JSXElement} from './jsx-element.js';
5
5
  export {JSXAttribute} from './jsx-attribute.js';
@@ -1,13 +1,13 @@
1
1
  import {fullstore} from 'fullstore';
2
2
  import {TYPES} from '#types';
3
3
  import {maybeMarkAfter} from '#mark';
4
- import {createDebug, createLog} from './debug.js';
5
- import * as baseVisitors from '../visitors.js';
6
- import {maybeVisitor, maybeThrow} from '../maybe/index.js';
7
4
  import {
8
5
  parseLeadingComments,
9
6
  parseTrailingComments,
10
- } from '../comment/comment.js';
7
+ } from '#comments';
8
+ import {createDebug, createLog} from './debug.js';
9
+ import * as baseVisitors from '../visitors.js';
10
+ import {maybeVisitor, maybeThrow} from '../maybe/index.js';
11
11
  import {parseOverrides} from '../overrides/overrides.js';
12
12
  import {createIndent} from './indent.js';
13
13
 
@@ -1,27 +1,35 @@
1
- import {types} from '@putout/babel';
2
1
  import {markAfter} from '#mark';
3
- import {parseComments} from '../../comment/comment.js';
2
+ import {createTypeChecker} from '#type-checker';
3
+ import {isInsideBlock} from '#is';
4
+ import {parseComments} from '#comments';
4
5
  import {getDirectives} from './get-directives.js';
5
6
  import {isCallInsideChain} from './is-call-inside-chain.js';
6
7
  import {shouldAddNewlineAfter} from './block-statement-newline.js';
7
8
 
8
- const {isArrayExpression} = types;
9
+ const isThree = (a) => a === 3;
9
10
 
10
- const isFirstStatement = (path) => path.node.body[0];
11
- const isFirstDirective = (path) => path.node.directives?.[0];
11
+ const isInsideArrayTupleOfThree = createTypeChecker([
12
+ ['-: parentPath.parentPath -> !ArrayExpression'],
13
+ ['+: parentPath.parentPath.node.elements.length', isThree],
14
+ ]);
12
15
 
13
- const isInsideArrayTupleOfThree = (path) => {
14
- const {parentPath} = path.parentPath;
15
-
16
- if (!isArrayExpression(parentPath))
17
- return false;
18
-
19
- const {length} = parentPath.node.elements;
20
-
21
- return length === 3;
22
- };
16
+ const hasDirectives = (a) => getDirectives(a).length;
17
+
18
+ const isNewLineAfterOpenCurlyBrace = createTypeChecker([
19
+ ['+', hasDirectives],
20
+ ['+: node.body.length', Boolean],
21
+ ]);
22
+
23
+ const isLinebreakAfterDirectives = createTypeChecker([
24
+ ['-: node.body.length -> !', Boolean],
25
+ ['+', hasDirectives],
26
+ ]);
23
27
 
24
28
  export const BlockStatement = {
29
+ beforeIf: isInsideBlock,
30
+ before: (path, {indent}) => {
31
+ indent();
32
+ },
25
33
  print(path, printer, semantics) {
26
34
  const {
27
35
  indent,
@@ -32,22 +40,21 @@ export const BlockStatement = {
32
40
 
33
41
  const body = path.get('body');
34
42
  const directives = getDirectives(path);
35
-
36
- if (path.parentPath.isBlockStatement())
37
- indent();
38
-
39
43
  const insideArray = isInsideArrayTupleOfThree(path);
44
+
40
45
  maybe.indent.inc(!insideArray);
41
46
  write('{');
42
47
 
43
- if (isFirstStatement(path) || isFirstDirective(path))
48
+ if (isNewLineAfterOpenCurlyBrace(path))
44
49
  write.newline();
45
50
 
46
51
  for (const directive of directives) {
47
52
  traverse(directive);
48
53
  }
49
54
 
50
- maybe.write.linebreak(directives.length && body.length);
55
+ if (isLinebreakAfterDirectives(path))
56
+ write.linebreak();
57
+
51
58
  const callInsideChain = isCallInsideChain(path);
52
59
 
53
60
  maybe.indent.inc(callInsideChain);
@@ -1,5 +1,5 @@
1
1
  import {hasCoupleTrailingComments} from '#is';
2
- import {parseComments} from '../../comment/comment.js';
2
+ import {parseComments} from '#comments';
3
3
  import {getDirectives} from '../block-statement/get-directives.js';
4
4
 
5
5
  export const Program = (path, printer, semantics) => {
@@ -3,7 +3,7 @@ import {
3
3
  exists,
4
4
  isLast,
5
5
  } from '#is';
6
- import {parseLeadingComments} from '../../comment/comment.js';
6
+ import {parseLeadingComments} from '#comments';
7
7
  import {maybeSpaceAfterKeyword} from '../return-statement/maybe-space-after-keyword.js';
8
8
 
9
9
  export const SwitchStatement = {
@@ -3,6 +3,7 @@ import {hasPrevNewline} from '#mark';
3
3
  import {createTypeChecker} from '#type-checker';
4
4
  import {isConcatenation} from '#is-concatenation';
5
5
  import {maybeDeclare} from '#maybe-declare';
6
+ import {parseLeadingComments} from '#comments';
6
7
  import {
7
8
  isNext,
8
9
  isCoupleLines,
@@ -19,7 +20,6 @@ import {
19
20
  callWithParent,
20
21
  } from '#is';
21
22
  import {maybeSpaceAfterKeyword} from './maybe-space-after-keyword.js';
22
- import {parseLeadingComments} from '../../comment/comment.js';
23
23
 
24
24
  const {isExportDeclaration} = types;
25
25
 
@@ -1,4 +1,4 @@
1
- import {parseComments} from '../../comment/comment.js';
1
+ import {parseComments} from '#comments';
2
2
 
3
3
  export const TSInterfaceBody = (path, printer, semantics) => {
4
4
  const body = path.get('body');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.4.5",
3
+ "version": "18.4.7",
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",
@@ -70,7 +70,8 @@
70
70
  "#type-checker": "./lib/tokenize/type-checker/type-checker.js",
71
71
  "#type-checker/instrument": "./lib/tokenize/type-checker/instrument.js",
72
72
  "#type-checker/report": "./lib/tokenize/type-checker/report.js",
73
- "#is-concatenation": "./lib/tokenize/expressions/binary-expression/is-concatenation.js"
73
+ "#is-concatenation": "./lib/tokenize/expressions/binary-expression/is-concatenation.js",
74
+ "#comments": "./lib/tokenize/comments/comments.js"
74
75
  },
75
76
  "devDependencies": {
76
77
  "@babel/parser": "^7.28.5",