@putout/printer 11.7.0 → 11.9.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.9.0
2
+
3
+ fix:
4
+ - d30419e @putout/printer: LabeledStatement
5
+
6
+ feature:
7
+ - 20c554a @putout/printer: TSDeclareMethod: comment: indent
8
+ - 7702bf3 @putout/printer: LogicalExpressions: maxLogicalsInOneLine
9
+
10
+ 2024.12.17, v11.8.0
11
+
12
+ feature:
13
+ - 0ed288d @putout/printer: LabeledStatement: nexted
14
+
1
15
  2024.12.17, v11.7.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,7 +86,7 @@ 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
92
  const isIndent = isFirst(path) || !looksLikeSwitchCase && !path.isClassMethod() && !insideFn && !propIs;
@@ -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;
@@ -12,6 +12,7 @@ const {
12
12
  isMemberExpression,
13
13
  isArrayExpression,
14
14
  isObjectExpression,
15
+ isLabeledStatement,
15
16
  } = types;
16
17
 
17
18
  const isParentProgram = (path) => path.parentPath?.isProgram();
@@ -124,6 +125,8 @@ module.exports.isNewlineBetweenSiblings = (path) => {
124
125
  return startNext - endCurrent > 1;
125
126
  };
126
127
 
128
+ module.exports.isInsideLabel = ({parentPath}) => isLabeledStatement(parentPath);
129
+
127
130
  module.exports.satisfy = (conditions) => (path) => {
128
131
  for (const condition of conditions)
129
132
  if (condition(path))
@@ -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,
@@ -1,6 +1,5 @@
1
1
  'use strict';
2
2
 
3
- const {isLabeledStatement} = require('@putout/babel').types;
4
3
  const {
5
4
  isNext,
6
5
  isLast,
@@ -11,6 +10,7 @@ const {
11
10
  noTrailingComment,
12
11
  hasTrailingComment,
13
12
  isCoupleLines,
13
+ isInsideLabel,
14
14
  } = require('../is');
15
15
 
16
16
  const isBeforeElse = (path) => {
@@ -36,8 +36,6 @@ const shouldBreakline = satisfy([
36
36
  isStrictMode,
37
37
  ]);
38
38
 
39
- const isInsideLabel = ({parentPath}) => isLabeledStatement(parentPath);
40
-
41
39
  module.exports.ExpressionStatement = {
42
40
  print(path, {print, maybe, store}) {
43
41
  maybe.indent(!isInsideLabel(path));
@@ -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,
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ const {isInsideLabel} = require('../../is');
4
+
5
+ module.exports.LabeledStatement = (path, {print, maybe}) => {
6
+ maybe.indent(!isInsideLabel(path));
7
+ print('__label');
8
+ print(':');
9
+ print.space();
10
+ print('__body');
11
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "11.7.0",
3
+ "version": "11.9.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",
@@ -1,9 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports.LabeledStatement = (path, {print, indent}) => {
4
- indent();
5
- print('__label');
6
- print(':');
7
- print.space();
8
- print('__body');
9
- };