@putout/printer 15.26.2 → 15.27.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,8 @@
1
+ 2025.11.12, v15.27.0
2
+
3
+ feature:
4
+ - cd2a315 @putout/printer: MemberExpression: object is ObjectExpression: inside ArrowFunctionExpression
5
+
1
6
  2025.11.07, v15.26.2
2
7
 
3
8
  feature:
@@ -12,6 +12,9 @@ module.exports.condition = (path, printer, semantics) => {
12
12
  if (path.node.left.type === 'ObjectPattern')
13
13
  return true;
14
14
 
15
+ if (parentPath.type === 'MemberExpression')
16
+ return true;
17
+
15
18
  if (type === 'LogicalExpression')
16
19
  return true;
17
20
 
@@ -1,37 +1,45 @@
1
1
  'use strict';
2
2
 
3
+ const {types} = require('@putout/babel');
3
4
  const {maybePrintComputed} = require('../object-expression/maybe-print-computed');
4
5
  const {maybeParens} = require('../../maybe/maybe-parens');
5
6
  const {isLooksLikeChain} = require('./is-looks-like-chain');
6
7
 
7
- module.exports.MemberExpression = (path, printer) => {
8
- const {
9
- print,
10
- maybe,
11
- traverse,
12
- } = printer;
13
-
14
- const object = path.get('object');
15
- const property = path.get('property');
16
- const isParens = object.isAssignmentExpression();
17
- const {computed} = path.node;
18
-
19
- const isChain = isLooksLikeChain(path);
20
-
21
- maybe.print(isParens, '(');
22
- traverse(object);
23
- maybe.print(isParens, ')');
24
-
25
- if (computed)
26
- return maybePrintComputed(path, property, printer);
27
-
28
- maybe.indent.inc(isChain);
29
- maybe.print.breakline(isChain);
30
-
31
- print('.');
32
- print('__property');
33
- maybe.indent.dec(isChain);
34
- };
8
+ const {
9
+ isObjectExpression,
10
+ isArrowFunctionExpression,
11
+ } = types;
12
+
13
+ module.exports.MemberExpression = maybeParens({
14
+ checkParens: false,
15
+ condition: (path) => isObjectInsideArrow(path),
16
+ print: (path, printer) => {
17
+ const {
18
+ print,
19
+ maybe,
20
+ traverse,
21
+ } = printer;
22
+
23
+ const object = path.get('object');
24
+ const property = path.get('property');
25
+
26
+ const {computed} = path.node;
27
+
28
+ const isChain = isLooksLikeChain(path);
29
+
30
+ traverse(object);
31
+
32
+ if (computed)
33
+ return maybePrintComputed(path, property, printer);
34
+
35
+ maybe.indent.inc(isChain);
36
+ maybe.print.breakline(isChain);
37
+
38
+ print('.');
39
+ print('__property');
40
+ maybe.indent.dec(isChain);
41
+ },
42
+ });
35
43
 
36
44
  module.exports.OptionalMemberExpression = maybeParens((path, {print, maybe}) => {
37
45
  const {computed, optional} = path.node;
@@ -51,3 +59,10 @@ module.exports.OptionalMemberExpression = maybeParens((path, {print, maybe}) =>
51
59
 
52
60
  print('__property');
53
61
  });
62
+
63
+ const isObjectInsideArrow = ({node, parentPath}) => {
64
+ if (!isObjectExpression(node.object))
65
+ return false;
66
+
67
+ return isArrowFunctionExpression(parentPath);
68
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "15.26.2",
3
+ "version": "15.27.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "Simplest possible opinionated Babel AST printer for 🐊Putout",