@putout/printer 2.30.0 → 2.32.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
+ 2023.06.19, v2.32.0
2
+
3
+ feature:
4
+ - 1e478d1 @putout/printer: VariableDeclarator: useless newline
5
+
6
+ 2023.06.19, v2.31.0
7
+
8
+ feature:
9
+ - bfb0901 @putout/printer: ArrayExpression: newlines
10
+
1
11
  2023.06.19, v2.30.0
2
12
 
3
13
  feature:
@@ -5,6 +5,7 @@ const {
5
5
  isStringAndIdentifier,
6
6
  isIdentifierAndIdentifier,
7
7
  isStringAndArray,
8
+ isIndented,
8
9
  } = require('../../is');
9
10
 
10
11
  const {
@@ -13,7 +14,10 @@ const {
13
14
  isCurrentNewLine,
14
15
  } = require('./new-line');
15
16
 
16
- const {isObjectExpression} = require('@babel/types');
17
+ const {
18
+ isObjectExpression,
19
+ isStringLiteral,
20
+ } = require('@babel/types');
17
21
 
18
22
  const isNextObject = (a) => a.getNextSibling().isObjectExpression();
19
23
 
@@ -23,7 +27,7 @@ const isInsideArray = (path) => path.parentPath.isArrayExpression();
23
27
  const isTwoLongStrings = ([a, b]) => {
24
28
  const LONG_STRING = 20;
25
29
 
26
- if (!a?.isStringLiteral() || !b?.isStringLiteral())
30
+ if (!isStringLiteral(a) || !isStringLiteral(b))
27
31
  return false;
28
32
 
29
33
  return a.node.value.length > LONG_STRING;
@@ -55,8 +59,11 @@ module.exports.ArrayExpression = {
55
59
 
56
60
  print('[');
57
61
 
58
- if (!isTwoLongStrings(elements))
62
+ const indented = !isTwoLongStrings(elements) || !isInsideArray(path) && isIndented(elements[0]);
63
+
64
+ if (indented) {
59
65
  maybe.indent.inc(shouldIncreaseIndent);
66
+ }
60
67
 
61
68
  const isNewLine = isNewlineBetweenElements(path, {
62
69
  elements,
@@ -81,9 +88,8 @@ module.exports.ArrayExpression = {
81
88
  }
82
89
  }
83
90
 
84
- if (!isTwoLongStrings(elements)) {
91
+ if (indented)
85
92
  maybe.indent.dec(shouldIncreaseIndent);
86
- }
87
93
 
88
94
  const parentElements = path.parentPath.get('elements');
89
95
 
@@ -34,6 +34,11 @@ module.exports.isParentProgram = isParentProgram;
34
34
  module.exports.isParentBlock = isParentBlock;
35
35
  module.exports.isLast = isLast;
36
36
  module.exports.isParentLast = (path) => isLast(path.parentPath);
37
+
38
+ module.exports.isIndented = (path = {}) => {
39
+ const {parentPath, node} = path;
40
+ return node.loc.start.column !== parentPath.node.loc.start.column;
41
+ };
37
42
  module.exports.isCoupleLines = isCoupleLines;
38
43
 
39
44
  function isCoupleLines(path) {
@@ -123,6 +123,12 @@ function notLastPrevVarNotNextVar(path) {
123
123
  const prev = path.getPrevSibling();
124
124
  const next = path.getNextSibling();
125
125
 
126
+ if (!exists(prev.getPrevSibling()))
127
+ return false;
128
+
129
+ if (path.node.loc?.start.line === prev.node?.loc?.start.line + 2)
130
+ return false;
131
+
126
132
  return !isLast(path) && prev.isVariableDeclaration() && !next.isVariableDeclaration();
127
133
  }
128
134
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "2.30.0",
3
+ "version": "2.32.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",