@putout/printer 18.7.6 → 18.7.8

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.03.18, v18.7.8
2
+
3
+ feature:
4
+ - 382ab893 @putout/printer: MemberExpression: isLooksLikeChain: simplify
5
+
6
+ 2026.03.17, v18.7.7
7
+
8
+ feature:
9
+ - a257dabc @putout/printer: MemberExpression: isLooksLikeChain: simplify
10
+
1
11
  2026.03.17, v18.7.6
2
12
 
3
13
  feature:
@@ -4,7 +4,7 @@ import {
4
4
  isCoupleLines,
5
5
  isNext,
6
6
  } from '#is';
7
- import {isLooksLikeChain} from '../expressions/member-expression/is-looks-like-chain.js';
7
+ import {isLooksLikeChain} from '../expressions/member-expression/is-looks-like-chain/index.js';
8
8
  import {
9
9
  printTrailingComments,
10
10
  hasTrailingCommentsPrinter,
@@ -0,0 +1,19 @@
1
+ import {types} from '@putout/babel';
2
+ import {createTypeChecker} from '#type-checker';
3
+
4
+ const {isCallExpression} = types;
5
+
6
+ export const checkCallsCount = (path, {properties}) => {
7
+ const calls = properties.filter(isCallExpression);
8
+ return checkFilteredCalls(calls);
9
+ };
10
+
11
+ const isTwoCallsWithoutName = createTypeChecker([
12
+ ['-: length -> !', '=', 2],
13
+ ['+: 0.name -> -'],
14
+ ]);
15
+
16
+ const checkFilteredCalls = createTypeChecker([
17
+ ['-', isTwoCallsWithoutName],
18
+ ['+: length', '>', 1],
19
+ ]);
@@ -1,6 +1,7 @@
1
1
  import {types} from '@putout/babel';
2
2
  import {createTypeChecker} from '#type-checker';
3
- import {chain} from './chain.js';
3
+ import {chain} from '../chain.js';
4
+ import {checkCallsCount} from './check-calls-count.js';
4
5
 
5
6
  const hasPropertyWithComment = (properties) => {
6
7
  return properties.find(hasComment);
@@ -15,7 +16,6 @@ const isPathGet = ([property]) => {
15
16
  const {
16
17
  isIfStatement,
17
18
  isCallExpression,
18
- isIdentifier,
19
19
  } = types;
20
20
 
21
21
  const isPathFirstArg = ({node, parentPath}) => {
@@ -38,8 +38,6 @@ const isLastArgInCall = createTypeChecker([
38
38
  ['+', isPathLastArg],
39
39
  ]);
40
40
 
41
- const isCall = (a) => a.type === 'CallExpression';
42
-
43
41
  const callWithRoot = (fn) => (a, {root}) => fn(root);
44
42
  const isExcludedFromChain = createTypeChecker([
45
43
  '+: -> UnaryExpression',
@@ -48,32 +46,16 @@ const isExcludedFromChain = createTypeChecker([
48
46
 
49
47
  const hasComment = ({type}) => type === 'CommentLine';
50
48
 
51
- const isInsideMemberCall = (path) => {
52
- if (!isIdentifier(path.node.object))
53
- return false;
54
-
55
- if (!isIdentifier(path.node.property))
56
- return false;
57
-
58
- if (isLastArgInCall(path))
59
- return true;
60
-
61
- return isCallExpression(path.parentPath.parentPath);
62
- };
49
+ const isInsideMemberCall = createTypeChecker([
50
+ ['-: node.object -> !Identifier'],
51
+ ['-: node.property -> !Identifier'],
52
+ ['+', isLastArgInCall],
53
+ ['+: parentPath.parentPath -> CallExpression'],
54
+ ]);
63
55
 
64
56
  const callWithProperties = (fn) => (a, {properties}) => fn(properties);
65
57
  const isFindUpIf = (path) => path.find(isIfUp);
66
58
 
67
- const checkCallsCount = (path, {properties}) => {
68
- const calls = properties.filter(isCall);
69
- const [firstCall] = calls;
70
-
71
- if (calls.length === 2 && !firstCall.name)
72
- return false;
73
-
74
- return calls.length > 1;
75
- };
76
-
77
59
  export const isLooksLikeChain = (path) => {
78
60
  const [root, properties] = chain(path);
79
61
 
@@ -111,3 +93,4 @@ const isIfUp = (path) => {
111
93
 
112
94
  return is;
113
95
  };
96
+
@@ -1,7 +1,7 @@
1
1
  import {maybeParens} from '#maybe-parens';
2
2
  import {createTypeChecker} from '#type-checker';
3
3
  import {maybePrintComputed} from '../object-expression/maybe-print-computed.js';
4
- import {isLooksLikeChain} from './is-looks-like-chain.js';
4
+ import {isLooksLikeChain} from './is-looks-like-chain/index.js';
5
5
 
6
6
  const isObjectInsideArrow = createTypeChecker([
7
7
  '-: node.object -> !ObjectExpression',
@@ -12,7 +12,7 @@ import {
12
12
  hasTrailingComment,
13
13
  } from '#is';
14
14
  import {isInsideTuple} from './is-inside-tuple.js';
15
- import {isLooksLikeChain} from '../member-expression/is-looks-like-chain.js';
15
+ import {isLooksLikeChain} from '../member-expression/is-looks-like-chain/index.js';
16
16
  import {isCommaAfterSpread} from './comma.js';
17
17
  import {isMultilineOption} from '../array-expression/is.js';
18
18
  import {isLinebreakAfterProperty} from './linebreak.js';
@@ -1,6 +1,6 @@
1
1
  import {types} from '@putout/babel';
2
2
  import {createTypeChecker} from '#type-checker';
3
- import {isLooksLikeChain} from '../../expressions/member-expression/is-looks-like-chain.js';
3
+ import {isLooksLikeChain} from '../../expressions/member-expression/is-looks-like-chain/index.js';
4
4
 
5
5
  const {isCallExpression} = types;
6
6
 
@@ -33,4 +33,3 @@ const isTopCall = createTypeChecker([
33
33
  '+: parentPath -> ReturnStatement',
34
34
  '+: parentPath -> ExpressionStatement',
35
35
  ]);
36
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.7.6",
3
+ "version": "18.7.8",
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",