@putout/printer 14.8.0 → 15.1.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,21 @@
1
+ 2025.06.12, v15.1.0
2
+
3
+ fix:
4
+ - 7274b61 @putout/printer: ObjectPattern: AssignmentPattern: ObjectExpression: comma
5
+
6
+ feature:
7
+ - c41eda6 @putout/printer: Decorator: printLeadingCommentLine
8
+ - 88d8cd4 @putout/printer: @putout/plugin-react-hooks v9.0.0
9
+ - 57495a1 @putout/printer: @putout/operate v14.0.1
10
+
11
+ 2025.06.01, v15.0.0
12
+
13
+ feature:
14
+ - abb07ed @putout/printer: get rid of Record and Tuple (https://github.com/tc39/proposal-record-tuple/issues/394)
15
+ - 6a5ff0c @putout/printer: @putout/compare v18.0.0
16
+ - 9c147b2 @putout/printer: @putout/plugin-promises v18.0.0
17
+ - 0300161 @putout/printer: @putout/babel v4.0.1
18
+
1
19
  2025.05.26, v14.8.0
2
20
 
3
21
  feature:
@@ -48,12 +48,7 @@ const isInsideVar = (path) => {
48
48
  return isVariableDeclarator(parentPath.parentPath);
49
49
  };
50
50
 
51
- const hasDecoratorsWithComments = (path) => {
52
- if (isDecorator(path))
53
- return false;
54
-
55
- return path?.parentPath.node?.decorators;
56
- };
51
+ const hasDecoratorsWithComments = (path) => path?.parentPath.node?.decorators;
57
52
 
58
53
  function isCommentOfPrevious(path) {
59
54
  const [comment] = path.node.leadingComments;
@@ -13,3 +13,9 @@ module.exports.Decorator = (path, {print, maybe}) => {
13
13
  print('__expression');
14
14
  maybe.print(isMember, ')');
15
15
  };
16
+
17
+ module.exports.Decorator.printLeadingCommentLine = (path, printer, semantics, {printComment}) => {
18
+ const {print} = printer;
19
+ printComment();
20
+ print.breakline();
21
+ };
@@ -36,7 +36,7 @@ module.exports.printFunctionParams = (path, printer, semantics) => {
36
36
  printer,
37
37
  });
38
38
 
39
- const printAfterOpen = createPrintAfterOpen(path, {
39
+ const printAfterOpen = createPrintAfterOpen({
40
40
  type: 'inc',
41
41
  printer,
42
42
  isNewline,
@@ -57,7 +57,7 @@ module.exports.printFunctionParams = (path, printer, semantics) => {
57
57
  });
58
58
  };
59
59
 
60
- const createPrintAfterOpen = (path, {isNewline, isAllHasComments, printer, type}) => () => {
60
+ const createPrintAfterOpen = ({isNewline, isAllHasComments, printer, type}) => () => {
61
61
  if (!isNewline)
62
62
  return;
63
63
 
@@ -67,11 +67,6 @@ const createPrintAfterOpen = (path, {isNewline, isAllHasComments, printer, type}
67
67
  indent[type]();
68
68
 
69
69
  print.breakline();
70
-
71
- const [first] = path.get('params');
72
-
73
- if (!first.node.decorators)
74
- indent();
75
70
  };
76
71
 
77
72
  const createPrintBeforeClose = ({isNewline, printer, isAllHasComments, type}) => () => {
@@ -39,8 +39,6 @@ const {BinaryExpression} = require('./binary-expression/binary-expression');
39
39
  const {LogicalExpression} = require('./logical-expression/logical-expression');
40
40
  const {ConditionalExpression} = require('./conditional-expression');
41
41
  const {StaticBlock} = require('./class/static-block');
42
- const {RecordExpression} = require('./object-expression/record-expression');
43
- const {TupleExpression} = require('./array-expression/tuple-expression');
44
42
  const {ImportExpression} = require('./import-expression');
45
43
  const {ParenthesizedExpression} = require('./parenthesized-expression/parenthesized-expression');
46
44
 
@@ -77,6 +75,4 @@ module.exports = {
77
75
  ThisExpression(path, {write}) {
78
76
  write('this');
79
77
  },
80
- RecordExpression,
81
- TupleExpression,
82
78
  };
@@ -181,4 +181,3 @@ function isParens(path) {
181
181
 
182
182
  return isParentExpression(path);
183
183
  }
184
-
@@ -1,8 +1,11 @@
1
1
  'use strict';
2
2
 
3
+ const {types} = require('@putout/babel');
3
4
  const {isConcatenation} = require('../binary-expression/concatenate');
4
5
  const {isOneLine} = require('./object-expression');
5
6
  const {printKey} = require('./print-key');
7
+ const {isTSImportType} = types;
8
+ const isInsideTSImportType = ({parentPath}) => isTSImportType(parentPath.parentPath);
6
9
 
7
10
  module.exports.ObjectProperty = (path, printer, semantics) => {
8
11
  const {trailingComma} = semantics;
@@ -14,7 +17,6 @@ module.exports.ObjectProperty = (path, printer, semantics) => {
14
17
  } = printer;
15
18
 
16
19
  const value = path.get('value');
17
-
18
20
  const properties = path.parentPath.get('properties');
19
21
  const isLast = path === properties.at(-1);
20
22
  const manyLines = !isOneLine(path.parentPath);
@@ -27,7 +29,7 @@ module.exports.ObjectProperty = (path, printer, semantics) => {
27
29
  traverse(value);
28
30
  }
29
31
 
30
- if (manyLines)
32
+ if (manyLines && !isInsideTSImportType(path))
31
33
  maybe.write(!isLast || trailingComma, ',');
32
34
  else if (!isLast && properties.length)
33
35
  write(', ');
@@ -115,7 +115,7 @@ module.exports.ObjectPattern = {
115
115
  continue;
116
116
  }
117
117
 
118
- if (i < n) {
118
+ if (i < n && !(isAssign && couple)) {
119
119
  print(',');
120
120
  print.space();
121
121
  }
@@ -8,10 +8,10 @@ const maybeSatisfy = require('./satisfy');
8
8
  const {
9
9
  isProgram,
10
10
  isFile,
11
- File,
12
- ExpressionStatement,
13
- Program,
14
11
  isStatement,
12
+ expressionStatement,
13
+ program,
14
+ file,
15
15
  } = types;
16
16
 
17
17
  const isFn = (a) => typeof a === 'function';
@@ -26,13 +26,13 @@ module.exports.maybeThrow = (a, path, b) => {
26
26
  }));
27
27
  };
28
28
 
29
- const maybeStatement = (ast) => isStatement(ast) ? ast : ExpressionStatement(ast);
29
+ const maybeStatement = (ast) => isStatement(ast) ? ast : expressionStatement(ast);
30
30
 
31
- const maybeProgram = (ast) => isProgram(ast) ? ast : Program([
31
+ const maybeProgram = (ast) => isProgram(ast) ? ast : program([
32
32
  maybeStatement(ast),
33
33
  ]);
34
34
 
35
- module.exports.maybeFile = (ast) => isFile(ast) ? ast : File(maybeProgram(ast));
35
+ module.exports.maybeFile = (ast) => isFile(ast) ? ast : file(maybeProgram(ast));
36
36
 
37
37
  module.exports.maybeVisitor = (plugin, path, printer, options) => {
38
38
  if (isFn(plugin))
@@ -196,4 +196,3 @@ function isTry({parentPath}) {
196
196
 
197
197
  return parentPath.parentPath?.isTryStatement();
198
198
  }
199
-
@@ -10,7 +10,6 @@ module.exports.TSParameterProperty = (path, {print, maybe, indent}) => {
10
10
  } = path.node;
11
11
 
12
12
  const decoratorsLength = decorators?.length > 1;
13
- const isNewline = decoratorsLength || hasLeadingComment(path);
14
13
 
15
14
  maybe.print.breakline(decoratorsLength);
16
15
 
@@ -22,11 +21,10 @@ module.exports.TSParameterProperty = (path, {print, maybe, indent}) => {
22
21
 
23
22
  maybe.print.breakline(decoratorsLength);
24
23
 
25
- if (isNewline)
26
- indent();
27
-
28
24
  if (!hasLeadingComment(path))
29
- print.space();
25
+ indent();
26
+ else
27
+ print(' ');
30
28
  }
31
29
 
32
30
  if (accessibility) {
@@ -48,12 +46,21 @@ module.exports.TSParameterProperty = (path, {print, maybe, indent}) => {
48
46
  module.exports.TSParameterProperty.printLeadingCommentLine = (path, printer, semantics, {printComment}) => {
49
47
  const {indent, print} = printer;
50
48
 
51
- if (path.parentPath.isClassMethod() && !path.node.decorators) {
49
+ if (path.node.decorators) {
50
+ printComment();
51
+ print.breakline();
52
+
53
+ return;
54
+ }
55
+
56
+ if (path.parentPath.isClassMethod()) {
52
57
  indent.inc();
53
58
  print.breakline();
54
59
 
55
60
  printComment();
56
61
  print.breakline();
57
62
  indent.dec();
63
+
64
+ return;
58
65
  }
59
66
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "14.8.0",
3
+ "version": "15.1.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",
@@ -33,9 +33,9 @@
33
33
  "report": "madrun report"
34
34
  },
35
35
  "dependencies": {
36
- "@putout/babel": "^3.0.0",
37
- "@putout/compare": "^17.0.0",
38
- "@putout/operate": "^13.0.0",
36
+ "@putout/babel": "^4.0.1",
37
+ "@putout/compare": "^18.0.0",
38
+ "@putout/operate": "^14.0.1",
39
39
  "@putout/operator-json": "^2.0.0",
40
40
  "fullstore": "^3.0.0",
41
41
  "just-snake-case": "^3.2.0",
@@ -72,9 +72,9 @@
72
72
  "@putout/eslint": "^4.1.0",
73
73
  "@putout/plugin-minify": "^10.0.0",
74
74
  "@putout/plugin-printer": "^5.0.0",
75
- "@putout/plugin-promises": "^17.0.0",
75
+ "@putout/plugin-promises": "^18.0.0",
76
76
  "@putout/plugin-react-hook-form": "^6.0.0",
77
- "@putout/plugin-react-hooks": "^8.0.1",
77
+ "@putout/plugin-react-hooks": "^9.0.0",
78
78
  "acorn": "^8.8.2",
79
79
  "c8": "^10.1.2",
80
80
  "check-dts": "^0.9.0",
@@ -1,10 +0,0 @@
1
- 'use strict';
2
-
3
- const {ArrayExpression} = require('./array-expression');
4
- const {maybeVisitor} = require('../../maybe');
5
-
6
- module.exports.TupleExpression = (path, operations, semantics) => {
7
- const {write} = operations;
8
- write('#');
9
- maybeVisitor(ArrayExpression, path, operations, semantics);
10
- };
@@ -1,9 +0,0 @@
1
- 'use strict';
2
-
3
- const {ObjectExpression} = require('./object-expression');
4
-
5
- module.exports.RecordExpression = (path, operations, semantics) => {
6
- const {write} = operations;
7
- write('#');
8
- ObjectExpression(path, operations, semantics);
9
- };