@putout/printer 18.0.9 → 18.0.11

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,17 @@
1
+ 2026.03.05, v18.0.11
2
+
3
+ feature:
4
+ - 6315e3c @putout/printer: BlockStatement: simplify
5
+
6
+ 2026.03.05, v18.0.10
7
+
8
+ feature:
9
+ - d29c6de @putout/printer: ObjectExpression: isInsideTupleLike: simplify
10
+ - e4ee1c0 @putout/printer: ObjectExpression: isMemberExpressionCallee: simplify
11
+ - e1df5a9 @putout/printer: isThirdObjectInsideArray: rm
12
+ - c90efb6 ObjectExpression: isInsideExpression: reuse from NewExpression
13
+ - 84b86bb @putout/printer: VariableDeclaration: isInsideBody: reuse in ObjectExpression
14
+
1
15
  2026.03.05, v18.0.9
2
16
 
3
17
  feature:
@@ -1,13 +1,12 @@
1
1
  import {types} from '@putout/babel';
2
- import {exists} from '#is';
2
+ import {
3
+ exists,
4
+ isInsideExpression,
5
+ } from '#is';
3
6
  import {isMarkedAfter} from '#mark';
4
7
 
5
- const {
6
- isExpressionStatement,
7
- isMemberExpression,
8
- } = types;
8
+ const {isMemberExpression} = types;
9
9
 
10
- const isInsideExpressionStatement = ({parentPath}) => isExpressionStatement(parentPath);
11
10
  const notFirst = ({parentPath}) => exists(parentPath.getPrevSibling());
12
11
  const isInsideMember = ({parentPath}) => isMemberExpression(parentPath);
13
12
 
@@ -22,7 +21,7 @@ const getPrev = ({parentPath}) => {
22
21
 
23
22
  export const NewExpression = {
24
23
  beforeIf(path) {
25
- if (!isInsideExpressionStatement(path))
24
+ if (!isInsideExpression(path))
26
25
  return false;
27
26
 
28
27
  const [exists, prev] = getPrev(path);
@@ -1,4 +1,5 @@
1
1
  import {types} from '@putout/babel';
2
+ import {createTypeChecker} from '#type-checker';
2
3
  import {
3
4
  isCoupleLines,
4
5
  isForOf,
@@ -9,51 +10,41 @@ import {
9
10
  hasLeadingComment,
10
11
  exists,
11
12
  isInsideCall,
13
+ isInsideBody,
14
+ isInsideExpression,
12
15
  } from '#is';
13
16
  import {parseComments} from '../../comment/comment.js';
14
17
  import {isInsideTuple} from './is-inside-tuple.js';
15
18
  import {isLooksLikeChain} from '../member-expression/is-looks-like-chain.js';
16
- import {isThirdObjectInsideArray} from './is-third-object-inside-array.js';
17
19
 
18
20
  const {
19
- isStringLiteral,
20
- isArrayExpression,
21
21
  isSpreadElement,
22
+ isMemberExpression,
22
23
  } = types;
23
24
 
24
- const isBodyOfArrow = (path) => path.parentPath.node.body === path.node;
25
25
  const isLogical = (path) => path.get('argument').isLogicalExpression();
26
26
  const isValue = (path) => path.get('properties.0.value').node;
27
- const isParentExpression = (path) => path.parentPath.isExpressionStatement();
28
27
 
29
- const isMemberExpressionCallee = ({parentPath}) => {
30
- if (!parentPath.isCallExpression())
31
- return false;
32
-
33
- const callee = parentPath.get('callee');
34
-
35
- if (!callee.isMemberExpression())
36
- return false;
37
-
38
- return isLooksLikeChain(callee);
39
- };
28
+ const isParens = createTypeChecker([isInsideBody, isInsideExpression]);
29
+ const getCallee = (fn) => (a) => fn(a.get('callee'));
40
30
 
41
- function isInsideNestedArrayCall({parentPath}) {
42
- if (!isArrayExpression(parentPath))
43
- return false;
44
-
45
- if (!isArrayExpression(parentPath.parentPath))
46
- return false;
47
-
48
- return isInsideCall(parentPath.parentPath);
49
- }
31
+ const isMemberExpressionCallee = createTypeChecker([
32
+ '-: parentPath -> !CallExpression',
33
+ ['-: parentPath -> !', getCallee(isMemberExpression)],
34
+ ['+: parentPath', getCallee(isLooksLikeChain)],
35
+ ]);
50
36
 
51
- function isInsideNestedTuple({parentPath}) {
52
- const {elements} = parentPath.parentPath.node;
53
- const [first] = elements;
54
-
55
- return isStringLiteral(first);
56
- }
37
+ const isInsideNestedArrayCall = createTypeChecker([
38
+ isInsideTuple,
39
+ '-: parentPath -> !ArrayExpression',
40
+ '-: parentPath.parentPath -> !ArrayExpression',
41
+ ['+: parentPath.parentPath', isInsideCall],
42
+ ]);
43
+
44
+ const isInsideTupleLike = createTypeChecker([
45
+ ['+', isInsideTuple],
46
+ '+: parentPath.parentPath.node.elements.0 -> StringLiteral',
47
+ ]);
57
48
 
58
49
  export const ObjectExpression = (path, printer, semantics) => {
59
50
  const {trailingComma} = semantics;
@@ -63,7 +54,7 @@ export const ObjectExpression = (path, printer, semantics) => {
63
54
  indent,
64
55
  } = printer;
65
56
 
66
- const insideNestedArrayCall = isInsideTuple(path) || isInsideNestedArrayCall(path) || isThirdObjectInsideArray(path);
57
+ const insideNestedArrayCall = isInsideNestedArrayCall(path);
67
58
 
68
59
  maybe.indent.inc(!insideNestedArrayCall);
69
60
 
@@ -114,7 +105,7 @@ export const ObjectExpression = (path, printer, semantics) => {
114
105
  if (!insideNestedArrayCall) {
115
106
  indent.dec();
116
107
  maybe.indent(manyLines);
117
- } else if (isInsideTuple(path) || isInsideNestedTuple(path)) {
108
+ } else if (isInsideTupleLike(path)) {
118
109
  indent.dec();
119
110
  indent();
120
111
  indent.inc();
@@ -182,10 +173,3 @@ export function isOneLine(path) {
182
173
 
183
174
  return !isValue(path);
184
175
  }
185
-
186
- function isParens(path) {
187
- if (isBodyOfArrow(path))
188
- return true;
189
-
190
- return isParentExpression(path);
191
- }
@@ -16,11 +16,14 @@ const {
16
16
  isBlockStatement,
17
17
  isTSModuleBlock,
18
18
  isSwitchCase,
19
+ isExpressionStatement,
19
20
  } = types;
20
21
 
21
22
  export const isInsideProgram = (path) => isProgram(path.parentPath);
22
23
  export const isInsideBlock = (path) => isBlockStatement(path.parentPath);
23
24
  export const isInsideSwitchCase = (path) => isSwitchCase(path.parentPath);
25
+ export const isInsideBody = ({node, parentPath}) => node === parentPath.node.body;
26
+ export const isInsideExpression = ({parentPath}) => isExpressionStatement(parentPath);
24
27
 
25
28
  export const isInsideTSModuleBlock = ({parentPath}) => isTSModuleBlock(parentPath);
26
29
 
@@ -63,9 +63,8 @@ export const BlockStatement = {
63
63
 
64
64
  parseComments(path, printer, semantics);
65
65
 
66
- maybe.indent.dec(!insideArray);
66
+ indent.dec();
67
67
 
68
- maybe.indent.dec(insideArray);
69
68
  maybe.indent(body.length);
70
69
  maybe.indent.inc(insideArray);
71
70
  write('}');
@@ -13,6 +13,7 @@ import {
13
13
  isInsideTSModuleBlock,
14
14
  isInsideProgram,
15
15
  isInsideSwitchCase,
16
+ isInsideBody,
16
17
  } from '#is';
17
18
  import {maybeSpaceAfterKeyword} from './maybe-space-after-keyword.js';
18
19
  import {isConcatenation} from '../../expressions/binary-expression/concatenate.js';
@@ -21,8 +22,6 @@ import {maybeDeclare} from '../../maybe/maybe-declare.js';
21
22
 
22
23
  const {isExportDeclaration} = types;
23
24
 
24
- const isInsideBody = ({node, parentPath}) => node === parentPath.node.body;
25
-
26
25
  const isInsideBlockLike = createTypeChecker([
27
26
  isInsideProgram,
28
27
  isInsideBlock,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.0.9",
3
+ "version": "18.0.11",
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",
@@ -1,16 +0,0 @@
1
- import {types} from '@putout/babel';
2
-
3
- const {
4
- isArrayExpression,
5
- isCallExpression,
6
- isIdentifier,
7
- } = types;
8
-
9
- export const isThirdObjectInsideArray = ({parentPath}) => {
10
- if (!isArrayExpression(parentPath))
11
- return false;
12
-
13
- const [, second] = parentPath.node.elements;
14
-
15
- return isCallExpression(second) && !!isIdentifier(second);
16
- };