@putout/printer 8.28.0 → 8.29.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
+ 2024.05.02, v8.29.0
2
+
3
+ feature:
4
+ - 3286498 @putout/printer: ObjectExpression inside ArrayExpression tuple
5
+
1
6
  2024.05.02, v8.28.0
2
7
 
3
8
  fix:
package/lib/printer.d.ts CHANGED
@@ -24,8 +24,8 @@ type Traverse = (input: types.Node) => void;
24
24
 
25
25
  declare function MaybeIndent(condition: boolean): void;
26
26
  declare namespace MaybeIndent {
27
- type inc = (condition: boolean) => void;
28
- type dec = (condition: boolean) => void;
27
+ type inc = (condition: boolean) => void;
28
+ type dec = (condition: boolean) => void;
29
29
 
30
30
  export {
31
31
  inc,
@@ -13,6 +13,7 @@ const {
13
13
 
14
14
  const {parseComments} = require('../../comment/comment');
15
15
  const {likeChain} = require('../member-expression/member-expressions');
16
+ const {isStringLiteral} = require('@putout/babel').types;
16
17
 
17
18
  const isBodyOfArrow = (path) => path.parentPath.node.body === path.node;
18
19
  const isLogical = (path) => path.get('argument').isLogicalExpression();
@@ -43,9 +44,20 @@ function isInsideNestedArrayCall({parentPath}) {
43
44
  return isInsideCall(parentPath.parentPath);
44
45
  }
45
46
 
47
+ function isInsideNestedTuple({parentPath}) {
48
+ const {elements} = parentPath.parentPath.node;
49
+ const [first] = elements;
50
+
51
+ return isStringLiteral(first);
52
+ }
53
+
46
54
  module.exports.ObjectExpression = (path, printer, semantics) => {
47
55
  const {trailingComma} = semantics;
48
- const {print, maybe} = printer;
56
+ const {
57
+ print,
58
+ maybe,
59
+ indent,
60
+ } = printer;
49
61
 
50
62
  const insideNestedArrayCall = isInsideNestedArrayCall(path);
51
63
 
@@ -95,8 +107,14 @@ module.exports.ObjectExpression = (path, printer, semantics) => {
95
107
  }
96
108
  }
97
109
 
98
- maybe.indent.dec(!insideNestedArrayCall);
99
- maybe.indent(manyLines && !insideNestedArrayCall);
110
+ if (!insideNestedArrayCall) {
111
+ indent.dec();
112
+ maybe.indent(manyLines);
113
+ } else if (isInsideNestedTuple(path)) {
114
+ indent.dec();
115
+ indent();
116
+ indent.inc();
117
+ }
100
118
 
101
119
  print('}');
102
120
  maybe.print(parens, ')');
@@ -51,4 +51,3 @@ module.exports.TSTypeAliasDeclaration = {
51
51
  markAfter(path);
52
52
  },
53
53
  };
54
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "8.28.0",
3
+ "version": "8.29.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",