@putout/printer 6.15.0 → 6.17.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.12.08, v6.17.0
2
+
3
+ feature:
4
+ - ff5b2bf @putout/printer: @putout/plugin-minify v6.2.0
5
+ - a5c7341 @putout/printer: Multiline Comments after function params
6
+
7
+ 2023.12.03, v6.16.0
8
+
9
+ feature:
10
+ - 27a2185 @putout/printer: ReturnStatement inside IfStatement: newline
11
+
1
12
  2023.12.03, v6.15.0
2
13
 
3
14
  feature:
@@ -13,6 +13,17 @@ const {
13
13
 
14
14
  const hasBody = (path) => path.node.body;
15
15
 
16
+ const isFnParam = (path) => {
17
+ const {parentPath} = path;
18
+
19
+ if (!parentPath.isFunction())
20
+ return false;
21
+
22
+ return parentPath
23
+ .get('params')
24
+ .includes(path);
25
+ };
26
+
16
27
  function isSameLine(path, loc) {
17
28
  return path.node.loc?.start.line === loc.start.line || path.node.loc?.end.line === loc.end.line;
18
29
  }
@@ -95,7 +106,7 @@ module.exports.parseTrailingComments = (path, {write, maybe}, semantics) => {
95
106
  maybe.write.space(sameLine);
96
107
  maybe.indent(!sameLine);
97
108
  write(`/*${value}*/`);
98
- maybe.write.newline(!sameLine || isCoupleLines(path.parentPath));
109
+ maybe.write.newline(!sameLine || !isFnParam(path) && isCoupleLines(path.parentPath));
99
110
  }
100
111
  }
101
112
  };
@@ -67,6 +67,27 @@ const isExcludedFromChain = satisfy([
67
67
  isIfStatement,
68
68
  ]);
69
69
 
70
+ const isIfUp = (path) => {
71
+ const ifPath = path.find(isIfStatement);
72
+ let is = false;
73
+
74
+ if (!ifPath)
75
+ return is;
76
+
77
+ ifPath
78
+ .get('test')
79
+ .traverse({
80
+ MemberExpression(currentPath) {
81
+ if (path === currentPath) {
82
+ is = true;
83
+ path.stop();
84
+ }
85
+ },
86
+ });
87
+
88
+ return is;
89
+ };
90
+
70
91
  module.exports.likeChain = likeChain;
71
92
  function likeChain(path) {
72
93
  const [root, properties] = chain(path);
@@ -74,7 +95,7 @@ function likeChain(path) {
74
95
  if (isExcludedFromChain(root))
75
96
  return false;
76
97
 
77
- if (path.find(isIfStatement))
98
+ if (path.find(isIfUp))
78
99
  return false;
79
100
 
80
101
  const calls = properties.filter(isCall);
@@ -4,7 +4,6 @@ const {markAfter} = require('../../mark');
4
4
  const {exists, isNext} = require('../../is');
5
5
 
6
6
  const isInside = ({parentPath}) => !parentPath.parentPath.isProgram();
7
-
8
7
  const isEmptyConsequent = (path) => path.get('consequent').isEmptyStatement();
9
8
 
10
9
  const isInsideNestedBody = ({parentPath}) => {
@@ -43,6 +43,9 @@ module.exports.ReturnStatement = {
43
43
  if (isLast(path))
44
44
  return false;
45
45
 
46
+ if (isLast(path.parentPath))
47
+ return false;
48
+
46
49
  return noTrailingComment(path);
47
50
  },
48
51
  after(path, {print}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "6.15.0",
3
+ "version": "6.17.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",
@@ -47,7 +47,7 @@
47
47
  ],
48
48
  "devDependencies": {
49
49
  "@babel/plugin-codemod-object-assign-to-object-spread": "^7.10.4",
50
- "@putout/plugin-minify": "^5.0.0",
50
+ "@putout/plugin-minify": "^6.2.0",
51
51
  "@putout/plugin-printer": "^3.0.0",
52
52
  "@putout/plugin-promises": "^13.0.0",
53
53
  "@putout/plugin-react-hook-form": "^4.0.0",