@putout/printer 5.0.0 → 5.2.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,14 @@
1
+ 2023.09.19, v5.2.0
2
+
3
+ feature:
4
+ - 018f2c3 @putout/printer: ObjectPattern: typeAnnotation (coderaiser/putout#183)
5
+
6
+ 2023.09.19, v5.1.0
7
+
8
+ feature:
9
+ - 8cea880 package: eslint-plugin-putout v20.0.0
10
+ - 7ae8762 @putout/printer: ObjectExpression used as argument of CallExpression with MemberExpression chain used as callee
11
+
1
12
  2023.09.18, v5.0.0
2
13
 
3
14
  feature:
@@ -70,6 +70,7 @@ const isExcludedFromChain = satisfy([
70
70
  isIfStatement,
71
71
  ]);
72
72
 
73
+ module.exports.likeChain = likeChain;
73
74
  function likeChain(path) {
74
75
  const [root, properties] = chain(path);
75
76
 
@@ -82,9 +83,8 @@ function likeChain(path) {
82
83
  if (calls.length === 2 && !firstCall.name)
83
84
  return false;
84
85
 
85
- if (isArgOfCall(path)) {
86
+ if (isArgOfCall(path))
86
87
  return false;
87
- }
88
88
 
89
89
  return calls.length > 1;
90
90
  }
@@ -12,12 +12,25 @@ const {
12
12
  } = require('../../is');
13
13
 
14
14
  const {parseComments} = require('../../comment/comment');
15
+ const {likeChain} = require('../member-expression/member-expressions');
15
16
 
16
17
  const isBodyOfArrow = (path) => path.parentPath.node.body === path.node;
17
18
  const isLogical = (path) => path.get('argument').isLogicalExpression();
18
19
  const isValue = (path) => path.get('properties.0.value').node;
19
20
  const isParentExpression = (path) => path.parentPath.isExpressionStatement();
20
21
 
22
+ const isMemberExpressionCallee = ({parentPath}) => {
23
+ if (!parentPath.isCallExpression())
24
+ return false;
25
+
26
+ const callee = parentPath.get('callee');
27
+
28
+ if (!callee.isMemberExpression())
29
+ return false;
30
+
31
+ return likeChain(callee);
32
+ };
33
+
21
34
  module.exports.ObjectExpression = (path, {print, maybe, indent, write}, semantics) => {
22
35
  const {trailingComma} = semantics;
23
36
  indent.inc();
@@ -34,6 +47,8 @@ module.exports.ObjectExpression = (path, {print, maybe, indent, write}, semantic
34
47
 
35
48
  const n = properties.length - 1;
36
49
 
50
+ maybe.indent.inc(isMemberExpressionCallee(path));
51
+
37
52
  for (const [index, property] of properties.entries()) {
38
53
  if (property.isSpreadElement()) {
39
54
  const logical = isLogical(property);
@@ -68,6 +83,8 @@ module.exports.ObjectExpression = (path, {print, maybe, indent, write}, semantic
68
83
  maybe.indent(manyLines);
69
84
  print('}');
70
85
  maybe.print(parens, ')');
86
+
87
+ maybe.indent.dec(isMemberExpressionCallee(path));
71
88
  };
72
89
 
73
90
  const hasNextLeadingComment = (path) => {
@@ -89,6 +89,13 @@ module.exports.ObjectPattern = {
89
89
  indent.dec();
90
90
  maybe.indent(is);
91
91
  print('}');
92
+
93
+ const {typeAnnotation} = path.node;
94
+
95
+ if (typeAnnotation) {
96
+ print(': ');
97
+ print('__typeAnnotation');
98
+ }
92
99
  },
93
100
  afterIf(path) {
94
101
  if (!path.parentPath.isObjectProperty())
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "5.0.0",
3
+ "version": "5.2.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",
@@ -56,7 +56,7 @@
56
56
  "escover": "^3.0.0",
57
57
  "eslint": "^8.0.1",
58
58
  "eslint-plugin-n": "^16.0.0",
59
- "eslint-plugin-putout": "^19.0.2",
59
+ "eslint-plugin-putout": "^20.0.0",
60
60
  "estree-to-babel": "^7.0.0",
61
61
  "just-kebab-case": "^4.2.0",
62
62
  "madrun": "^9.0.0",