@putout/printer 8.15.0 → 8.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,13 @@
1
+ 2024.04.16, v8.17.0
2
+
3
+ feature:
4
+ - 60c64ba @putout/printer: IfStatement: nested no body: improve
5
+
6
+ 2024.04.16, v8.16.0
7
+
8
+ feature:
9
+ - 95b0c77 @putout/printer: ImprotDeclaration: maxSpecifiersInOneLine: align to eslint-plugin-putout
10
+
1
11
  2024.04.16, v8.15.0
2
12
 
3
13
  feature:
@@ -67,11 +67,31 @@ module.exports.ExpressionStatement = {
67
67
  if (hasTrailingComment(path) && !isCoupleLines(path))
68
68
  return;
69
69
 
70
+ if (isTopParentLast(path))
71
+ return;
72
+
70
73
  print.newline();
71
74
  maybe.markAfter(store(), path);
72
75
  },
73
76
  };
74
77
 
78
+ function isTopParentLast({parentPath}) {
79
+ if (!parentPath.isIfStatement())
80
+ return false;
81
+
82
+ const nextParent = parentPath.parentPath;
83
+
84
+ if (!nextParent.isIfStatement())
85
+ return false;
86
+
87
+ const nextNext = nextParent.parentPath;
88
+
89
+ if (!nextNext.isIfStatement())
90
+ return false;
91
+
92
+ return isLast(nextNext);
93
+ }
94
+
75
95
  function isNotLastBody(path) {
76
96
  return path.parentPath.get('body') === path;
77
97
  }
@@ -56,7 +56,12 @@ module.exports.IfStatement = {
56
56
  write.space();
57
57
  traverse(alternate);
58
58
  } else if (alternate.isIfStatement()) {
59
- write(' else ');
59
+ if (alternate.get('consequent').isBlockStatement())
60
+ write.space();
61
+ else
62
+ indent();
63
+
64
+ write('else ');
60
65
  traverse(alternate);
61
66
  } else if (exists(alternate)) {
62
67
  maybe.write.newline(isVar);
@@ -69,6 +74,9 @@ module.exports.IfStatement = {
69
74
  indent.dec();
70
75
  }
71
76
 
77
+ if (!isNext(path) && !consequent.isBlockStatement())
78
+ return;
79
+
72
80
  if (path === partOfAlternate && isInside(path))
73
81
  print.newline();
74
82
  },
@@ -56,7 +56,7 @@ module.exports.ImportDeclaration = {
56
56
  indent.inc();
57
57
 
58
58
  maybe.write(!wasSpecifier, '{');
59
- maybe.write.breakline(importsCount > maxSpecifiersInOneLine);
59
+ maybe.write.breakline(importsCount >= maxSpecifiersInOneLine);
60
60
 
61
61
  wasSpecifier = true;
62
62
  write(imported.name);
@@ -66,12 +66,12 @@ module.exports.ImportDeclaration = {
66
66
  write(spec.node.local.name);
67
67
  }
68
68
 
69
- if (importsCount <= maxSpecifiersInOneLine && notLast) {
69
+ if (importsCount < maxSpecifiersInOneLine && notLast) {
70
70
  maybe.write(n, ',');
71
71
  maybe.write.space(n);
72
72
  }
73
73
 
74
- if (importsCount > maxSpecifiersInOneLine) {
74
+ if (importsCount >= maxSpecifiersInOneLine) {
75
75
  maybe.write(n, ',');
76
76
 
77
77
  const last = index === n;
@@ -115,7 +115,7 @@ function parseMaxSpecifiers(imports, options) {
115
115
 
116
116
  for (const {node} of imports) {
117
117
  if (node.imported.name !== node.local.name)
118
- return 0;
118
+ return 1;
119
119
  }
120
120
 
121
121
  return maxSpecifiersInOneLine;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "8.15.0",
3
+ "version": "8.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",