@putout/printer 11.8.0 → 11.10.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,17 @@
1
+ 2024.12.18, v11.10.0
2
+
3
+ feature:
4
+ - 6c06c0c @putout/printer: ExportDeclaration: no specifiers
5
+
6
+ 2024.12.18, v11.9.0
7
+
8
+ fix:
9
+ - d30419e @putout/printer: LabeledStatement
10
+
11
+ feature:
12
+ - 20c554a @putout/printer: TSDeclareMethod: comment: indent
13
+ - 7702bf3 @putout/printer: LogicalExpressions: maxLogicalsInOneLine
14
+
1
15
  2024.12.17, v11.8.0
2
16
 
3
17
  feature:
package/README.md CHANGED
@@ -96,6 +96,7 @@ print(ast, {
96
96
  comments: true,
97
97
  maxSpecifiersInOneLine: 2,
98
98
  maxElementsInOneLine: 3,
99
+ maxLogicalsInOneLine: 3,
99
100
  maxVariablesInOneLine: 4,
100
101
  maxTypesInOneLine: 3,
101
102
  maxPropertiesInOneLine: 2,
@@ -177,6 +178,7 @@ if(a>3)console.log('ok');else console.log('not ok');
177
178
  Options used to configure logic of output, similar to ESLint rules:
178
179
 
179
180
  - ✅ `maxElementsInOneLine` - count of `ArrayExpression` and `ArrayPattern` elements placed in one line.
181
+ - ✅ `maxLogicalsInOneLine` - count of `LogicalExpression` elements placed in one line.
180
182
  - ✅ `maxVariablesInOneLine` - count of `VariableDeclarators` in one line.
181
183
  - ✅ `maxPropertiesInOneLine` - count of `ObjectProperties` in one line.
182
184
  - ✅ `maxPropertiesLengthInOneLine` - maximum length of `Object Property`, when violated splits event if `maxPropertiesInOneLine` satisfies;
@@ -86,10 +86,14 @@ module.exports.parseLeadingComments = (path, {print, maybe, indent}, semantics)
86
86
  if (!looksLikeSwitchCase && hasTrailingComment(path.getPrevSibling()))
87
87
  return;
88
88
 
89
- const insideFn = path.parentPath.isFunction() && !path.isTSTypeParameterDeclaration();
89
+ const insideFn = (path.parentPath.isFunction() || path.parentPath.isTSDeclareMethod()) && !path.isTSTypeParameterDeclaration();
90
90
 
91
91
  const propIs = isProperty(path);
92
- const isIndent = isFirst(path) || !looksLikeSwitchCase && !path.isClassMethod() && !insideFn && !propIs;
92
+ const isIndent = isFirst(path)
93
+ || !looksLikeSwitchCase
94
+ && !path.isClassMethod()
95
+ && !insideFn
96
+ && !propIs;
93
97
 
94
98
  for (const {type, value} of leadingComments) {
95
99
  maybe.indent(isIndent);
@@ -3,8 +3,8 @@
3
3
  const {maybeTypeAnnotation} = require('../../maybe/maybe-type-annotation');
4
4
  const isForOf = ({parentPath}) => parentPath.parentPath.parentPath?.isForOfStatement();
5
5
 
6
- module.exports.ArrayPattern = maybeTypeAnnotation((path, {indent, maybe, print}, options) => {
7
- const {maxElementsInOneLine} = options;
6
+ module.exports.ArrayPattern = maybeTypeAnnotation((path, {indent, maybe, print}, semantics) => {
7
+ const {maxElementsInOneLine} = semantics;
8
8
 
9
9
  print('[');
10
10
 
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const {
4
+ isLogicalExpression,
4
5
  isReturnStatement,
5
6
  isVariableDeclarator,
6
7
  } = require('@putout/babel').types;
@@ -26,7 +27,13 @@ function down(current) {
26
27
 
27
28
  do {
28
29
  ++count;
30
+ const right = current.get('right');
31
+
32
+ if (isLogicalExpression(right))
33
+ count += down(right)[0];
34
+
29
35
  current = current.get('left');
36
+
30
37
  const {operator} = current.node;
31
38
 
32
39
  if (operator !== '||' && operator !== '&&')
@@ -31,7 +31,7 @@ function isNewLine(path, semantics) {
31
31
  if (!isRootOk(root))
32
32
  return false;
33
33
 
34
- if (count <= semantics.maxElementsInOneLine)
34
+ if (count <= semantics.maxLogicalsInOneLine)
35
35
  return false;
36
36
 
37
37
  const {operator} = path.node;
@@ -35,6 +35,7 @@ function initSemantics(semantics = {}) {
35
35
  maxPropertiesLengthInOneLine: 15,
36
36
  maxSpecifiersInOneLine: 2,
37
37
  maxElementsInOneLine: 5,
38
+ maxLogicalsInOneLine: 3,
38
39
  maxVariablesInOneLine: 4,
39
40
  maxTypesInOneLine: 3,
40
41
  trailingComma: true,
@@ -35,14 +35,14 @@ module.exports.ExportNamespaceSpecifier = (path, {print}) => {
35
35
  };
36
36
 
37
37
  module.exports.ExportNamedDeclaration = {
38
- print(path, {print, traverse, write, indent, maybe}) {
38
+ print(path, {print, traverse, indent, maybe}) {
39
39
  const {exportKind} = path.node;
40
40
  const specifiers = path.get('specifiers');
41
41
  const {maxOneLineSpecifiers} = options.exports;
42
42
  const source = path.get('source');
43
43
 
44
44
  indent();
45
- write('export');
45
+ print('export');
46
46
 
47
47
  if (exportKind === 'type' && specifiers.length)
48
48
  print(' type');
@@ -61,39 +61,43 @@ module.exports.ExportNamedDeclaration = {
61
61
  const n = specifiers.length;
62
62
  const isNewline = !exists(source) || n > maxOneLineSpecifiers;
63
63
 
64
- if (specifiers.length) {
64
+ if (specifiers && !path.node.declaration) {
65
65
  print.space();
66
- write('{');
67
- indent.inc();
68
- maybe.write.newline(isNewline);
66
+ print('{');
69
67
 
70
- const lastIndex = n - 1;
71
-
72
- for (const [i, spec] of specifiers.entries()) {
73
- const isType = spec.node.exportKind === 'type';
74
- maybe.indent(isNewline);
75
- maybe.write(isType, 'type ');
76
- traverse(spec);
68
+ if (specifiers.length) {
69
+ indent.inc();
70
+ maybe.print.newline(isNewline);
71
+
72
+ const lastIndex = n - 1;
77
73
 
78
- if (i < lastIndex && !isNewline)
79
- write(', ');
74
+ for (const [i, spec] of specifiers.entries()) {
75
+ const isType = spec.node.exportKind === 'type';
76
+ maybe.indent(isNewline);
77
+ maybe.print(isType, 'type ');
78
+ traverse(spec);
79
+
80
+ if (i < lastIndex && !isNewline)
81
+ print(', ');
82
+
83
+ maybe.print(isNewline, ',');
84
+ maybe.print.newline(isNewline);
85
+ }
80
86
 
81
- maybe.write(isNewline, ',');
82
- maybe.write.newline(isNewline);
87
+ indent.dec();
88
+ indent();
83
89
  }
84
90
 
85
- indent.dec();
86
- indent();
87
- write('}');
91
+ print('}');
88
92
  const source = path.get('source');
89
93
 
90
94
  if (exists(source)) {
91
- write(' from ');
95
+ print(' from ');
92
96
  traverse(source);
93
97
  }
94
98
 
95
- write(';');
96
- maybe.write.newline(isNext(path) || isInsideNamespace(path));
99
+ print(';');
100
+ maybe.print.newline(isNext(path) || isInsideNamespace(path));
97
101
 
98
102
  return;
99
103
  }
@@ -115,3 +119,4 @@ module.exports.ExportNamedDeclaration = {
115
119
  markAfter(path);
116
120
  },
117
121
  };
122
+
@@ -21,7 +21,7 @@ const {BreakStatement} = require('./break-statement');
21
21
  const {DoWhileStatement} = require('./do-while-statement');
22
22
  const {Program} = require('./program/program');
23
23
  const {ContinueStatement} = require('./continue-statement');
24
- const {LabeledStatement} = require('./labeled-statement/labeled-satement');
24
+ const {LabeledStatement} = require('./labeled-statement/labeled-statement');
25
25
 
26
26
  const {
27
27
  ExportNamespaceSpecifier,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "11.8.0",
3
+ "version": "11.10.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",