@putout/printer 12.3.0 → 12.4.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.01.15, v12.4.0
2
+
3
+ feature:
4
+ - 96a5778 ObjectExpression: inside tuple
5
+
1
6
  2025.01.14, v12.3.0
2
7
 
3
8
  feature:
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ const {types} = require('@putout/babel');
4
+ const {
5
+ isNumericLiteral,
6
+ isNullLiteral,
7
+ isArrayExpression,
8
+ } = types;
9
+
10
+ module.exports.isInsideTuple = (path) => {
11
+ const {parentPath} = path;
12
+
13
+ if (!isArrayExpression(parentPath))
14
+ return false;
15
+
16
+ const [first, second] = parentPath.node.elements;
17
+
18
+ if (second !== path.node)
19
+ return false;
20
+
21
+ return isNullLiteral(first) || isNumericLiteral(first);
22
+ };
@@ -14,8 +14,12 @@ const {
14
14
 
15
15
  const {parseComments} = require('../../comment/comment');
16
16
  const {likeChain} = require('../member-expression/member-expressions');
17
+ const {isInsideTuple} = require('./is-inside-tuple');
17
18
 
18
- const {isStringLiteral} = types;
19
+ const {
20
+ isStringLiteral,
21
+ isArrayExpression,
22
+ } = types;
19
23
 
20
24
  const isBodyOfArrow = (path) => path.parentPath.node.body === path.node;
21
25
  const isLogical = (path) => path.get('argument').isLogicalExpression();
@@ -37,16 +41,19 @@ const isMemberExpressionCallee = ({parentPath}) => {
37
41
  const isInsideCall = ({parentPath}) => parentPath.isCallExpression();
38
42
 
39
43
  function isInsideNestedArrayCall({parentPath}) {
40
- if (!parentPath.isArrayExpression())
44
+ if (!isArrayExpression(parentPath))
41
45
  return false;
42
46
 
43
- if (!parentPath.parentPath.isArrayExpression())
47
+ if (!isArrayExpression(parentPath.parentPath))
44
48
  return false;
45
49
 
46
50
  return isInsideCall(parentPath.parentPath);
47
51
  }
48
52
 
49
53
  function isInsideNestedTuple({parentPath}) {
54
+ if (!isArrayExpression(parentPath.parentPath))
55
+ return false;
56
+
50
57
  const {elements} = parentPath.parentPath.node;
51
58
  const [first] = elements;
52
59
 
@@ -61,7 +68,7 @@ module.exports.ObjectExpression = (path, printer, semantics) => {
61
68
  indent,
62
69
  } = printer;
63
70
 
64
- const insideNestedArrayCall = isInsideNestedArrayCall(path);
71
+ const insideNestedArrayCall = isInsideTuple(path) || isInsideNestedArrayCall(path);
65
72
 
66
73
  maybe.indent.inc(!insideNestedArrayCall);
67
74
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "12.3.0",
3
+ "version": "12.4.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",