@putout/printer 8.28.0 → 8.30.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,13 @@
1
+ 2024.05.02, v8.30.0
2
+
3
+ feature:
4
+ - 9a3ea75 @putout/printer: ArrayExpression: tuple: call
5
+
6
+ 2024.05.02, v8.29.0
7
+
8
+ feature:
9
+ - 3286498 @putout/printer: ObjectExpression inside ArrayExpression tuple
10
+
1
11
  2024.05.02, v8.28.0
2
12
 
3
13
  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,
@@ -27,6 +27,7 @@ const {
27
27
  isStringLiteral,
28
28
  isIdentifier,
29
29
  isArrayExpression,
30
+ isCallExpression,
30
31
  } = types;
31
32
 
32
33
  const isNextString = (path) => isStringLiteral(path.getNextSibling());
@@ -44,10 +45,20 @@ const isObjectAfterArray = (a) => {
44
45
  return isNextObject(a);
45
46
  };
46
47
 
48
+ const isObjectAfterCall = (a) => {
49
+ if (!isCallExpression(a))
50
+ return false;
51
+
52
+ return isNextObject(a);
53
+ };
54
+
47
55
  const isObjectAfterSimple = (a) => {
48
56
  if (isObjectAfterArray(a))
49
57
  return true;
50
58
 
59
+ if (isObjectAfterCall(a))
60
+ return true;
61
+
51
62
  return isObjectAfterSpread(a) || isObjectAfterIdentifier(a);
52
63
  };
53
64
 
@@ -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.30.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",