@putout/printer 1.21.0 → 1.23.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.04.05, v1.23.0
2
+
3
+ feature:
4
+ - 316c0f6 @putout/printer: add support of ExpressionStatement parent of ObjectExpression
5
+
6
+ 2023.04.04, v1.22.0
7
+
8
+ feature:
9
+ - c8fc7b7 @putout/printer: improve support of tuples
10
+ - 599bd93 @putout/printer: set @putout/printer as putout printer
11
+
1
12
  2023.04.04, v1.21.0
2
13
 
3
14
  feature:
@@ -8,6 +8,7 @@ const isForOf = ({parentPath}) => parentPath.isForOfStatement();
8
8
  const SECOND = 1;
9
9
 
10
10
  const isStringAndArray = ([a, b]) => a?.isStringLiteral() && b?.isArrayExpression();
11
+ const isStringAndIdentifier = ([a, b]) => a?.isStringLiteral() && b?.isIdentifier();
11
12
  const isArrayParent = (path) => path.parentPath.isArrayExpression();
12
13
  const isTwoLongStrings = ([a, b]) => {
13
14
  const LONG_STRING = 20;
@@ -27,9 +28,8 @@ module.exports.ArrayExpression = (path, {print, maybe, indent}) => {
27
28
 
28
29
  print('[');
29
30
 
30
- if (!isTwoLongStrings(elements) && !shouldIncreaseIndent) {
31
- indent.inc();
32
- }
31
+ if (!isTwoLongStrings(elements))
32
+ maybe.indent.inc(!shouldIncreaseIndent);
33
33
 
34
34
  const isNewLine = isNewlineBetweenElements(path, {elements});
35
35
  const n = elements.length - 1;
@@ -133,13 +133,21 @@ function isNewlineBetweenElements(path, {elements}) {
133
133
  if (isStringAndArray(elements))
134
134
  return false;
135
135
 
136
+ if (isStringAndIdentifier(elements))
137
+ return false;
138
+
136
139
  if (tooLong(path) || isCoupleLines(path) || !isNumbers(elements) && !isForOf(path) && isLastArg(path) && !isParentProperty(path))
137
140
  return true;
138
141
 
139
142
  return false;
140
143
  }
141
144
 
142
- function isTwoStringsDifferentLength([a, b]) {
145
+ function isTwoStringsDifferentLength(strings) {
146
+ const [a, b] = strings;
147
+
148
+ if (strings.length > 2)
149
+ return false;
150
+
143
151
  if (!a?.isStringLiteral() || !b?.isStringLiteral())
144
152
  return false;
145
153
 
@@ -6,7 +6,6 @@ module.exports.ArrayPattern = (path, {indent, maybe, print}) => {
6
6
  print('[');
7
7
 
8
8
  const elements = path.get('elements');
9
-
10
9
  indent.inc();
11
10
 
12
11
  const isNewLine = !isForOf(path) && elements.length > 2;
@@ -5,6 +5,7 @@ module.exports.ClassDeclaration = classVisitor;
5
5
 
6
6
  module.exports.ClassDeclaration = (path, {print, indent}) => {
7
7
  indent();
8
+
8
9
  classVisitor(path, {
9
10
  print,
10
11
  indent,
@@ -16,7 +16,6 @@ module.exports.FunctionExpression = (path, {print, maybe, write, traverse}) => {
16
16
  maybe.print(generator, '*');
17
17
 
18
18
  const id = path.get('id');
19
-
20
19
  write.space();
21
20
 
22
21
  if (id.node) {
@@ -6,7 +6,6 @@ module.exports.NewExpression = (path, {indent, print, maybe}) => {
6
6
  print('__callee');
7
7
 
8
8
  const args = path.get('arguments');
9
-
10
9
  print('(');
11
10
 
12
11
  const n = args.length - 1;
@@ -5,6 +5,7 @@ const isBodyOfArrow = (path) => path.parentPath.node.body === path.node;
5
5
  const isLogical = (path) => path.get('argument').isLogicalExpression();
6
6
  const isValue = (path) => path.get('properties.0.value').node;
7
7
  const isIf = (path) => path.parentPath.parentPath.isIfStatement();
8
+ const isParentExpression = (path) => path.parentPath.isExpressionStatement();
8
9
 
9
10
  const isForOf = (path) => {
10
11
  if (path.parentPath.isForOfStatement())
@@ -18,7 +19,7 @@ module.exports.ObjectExpression = (path, {print, maybe, indent}) => {
18
19
 
19
20
  const properties = path.get('properties');
20
21
  const {length} = properties;
21
- const parens = isBodyOfArrow(path);
22
+ const parens = isParens(path);
22
23
  const manyLines = !isOneLine(path);
23
24
 
24
25
  maybe.print(parens, '(');
@@ -62,7 +63,6 @@ function shouldAddNewline(path) {
62
63
 
63
64
  return path.parentPath.parentPath.isSpreadElement();
64
65
  }
65
-
66
66
  module.exports.ObjectProperty = (path, {print, maybe}) => {
67
67
  const {
68
68
  shorthand,
@@ -103,3 +103,13 @@ function isOneLine(path) {
103
103
 
104
104
  return !isValue(path);
105
105
  }
106
+
107
+ function isParens(path) {
108
+ if (isBodyOfArrow(path))
109
+ return true;
110
+
111
+ if (isParentExpression(path))
112
+ return true;
113
+
114
+ return false;
115
+ }
@@ -85,4 +85,3 @@ function isStrictMode(path) {
85
85
 
86
86
  return value === 'use strict';
87
87
  }
88
-
@@ -52,4 +52,3 @@ module.exports.ForOfStatement = {
52
52
  markAfter(path);
53
53
  },
54
54
  };
55
-
@@ -48,9 +48,6 @@ module.exports.IfStatement = {
48
48
  traverse(alternate);
49
49
  indent.dec();
50
50
  }
51
-
52
- //if (shouldAddNewline(path))
53
- //print.newline();
54
51
  },
55
52
  afterIf: (path) => {
56
53
  const next = path.getNextSibling();
@@ -18,7 +18,6 @@ module.exports.SwitchStatement = (path, {print, maybe}) => {
18
18
  print(':');
19
19
 
20
20
  const isBlock = switchCase.get('consequent.0').isBlockStatement();
21
-
22
21
  maybe.indent.inc(!isBlock);
23
22
  maybe.print.newline(!isBlock);
24
23
 
@@ -17,7 +17,6 @@ module.exports.TryStatement = (path, {print, maybe}) => {
17
17
  }
18
18
 
19
19
  print.newline();
20
-
21
20
  maybe.print.breakline(isNext(path));
22
21
  };
23
22
 
@@ -23,7 +23,6 @@ module.exports.VariableDeclaration = {
23
23
  print('__declarations.0.id');
24
24
 
25
25
  const initPath = path.get('declarations.0.init');
26
-
27
26
  maybe.print(initPath.node, ' = ');
28
27
  print('__declarations.0.init');
29
28
  maybe.print(isParentBlock(path), ';');
@@ -243,4 +243,3 @@ const computePath = (path, maybeLine) => {
243
243
 
244
244
  return maybeLine;
245
245
  };
246
-
@@ -59,6 +59,7 @@ module.exports = {
59
59
  write('{');
60
60
  write.newline();
61
61
  indent.inc();
62
+
62
63
  for (const member of path.get('members')) {
63
64
  indent();
64
65
  traverse(member);
@@ -78,4 +79,3 @@ module.exports = {
78
79
  print('__typeAnnotation');
79
80
  },
80
81
  };
81
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.21.0",
3
+ "version": "1.23.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "Easiest possible opinionated Babel AST printer made with ❤️ to use in 🐊Putout",