@putout/printer 15.18.2 → 15.20.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
+ 2025.08.12, v15.20.0
2
+
3
+ feature:
4
+ - 0eb1ddd @putout/printer: JSXText: no extra
5
+
6
+ 2025.08.05, v15.19.0
7
+
8
+ feature:
9
+ - f518cd6 @putout/printer: SequenceExpression: leadingComments inside AssignmentExpressions: improve
10
+
1
11
  2025.08.05, v15.18.2
2
12
 
3
13
  feature:
@@ -4,7 +4,19 @@ const {types} = require('@putout/babel');
4
4
  const {hasLeadingComment} = require('#is');
5
5
  const {isReturnStatement} = types;
6
6
 
7
- module.exports.printLeadingCommentLine = (path, printer, semantics, {printComment}) => {
7
+ module.exports.printLeadingCommentLine = (path, printer, semantics, {printComment, isLast}) => {
8
+ const {parentPath} = path;
9
+ const {print, maybe} = printer;
10
+
11
+ if (isReturnStatement(parentPath))
12
+ return;
13
+
14
+ maybe.print.breakline(!isLast);
15
+ printComment();
16
+ print.breakline();
17
+ };
18
+
19
+ module.exports.printLeadingCommentBlock = (path, printer, semantics, {printComment}) => {
8
20
  const {parentPath} = path;
9
21
  const {print} = printer;
10
22
 
@@ -12,7 +24,7 @@ module.exports.printLeadingCommentLine = (path, printer, semantics, {printCommen
12
24
  return;
13
25
 
14
26
  printComment();
15
- print.newline();
27
+ print.indent();
16
28
  };
17
29
 
18
30
  module.exports.maybeInsideReturnWithCommentStart = (path, {print, indent}) => {
@@ -6,6 +6,7 @@ const {
6
6
  printLeadingCommentLine,
7
7
  maybeInsideReturnWithCommentEnd,
8
8
  maybeInsideReturnWithCommentStart,
9
+ printLeadingCommentBlock,
9
10
  } = require('./assignment-expression-comments');
10
11
 
11
12
  const {maybeParens} = require('../../maybe/maybe-parens');
@@ -38,3 +39,4 @@ module.exports.AssignmentExpression = maybeParens({
38
39
  });
39
40
 
40
41
  module.exports.AssignmentExpression.printLeadingCommentLine = printLeadingCommentLine;
42
+ module.exports.AssignmentExpression.printLeadingCommentBlock = printLeadingCommentBlock;
@@ -1,40 +1,18 @@
1
1
  'use strict';
2
2
 
3
- module.exports.maybeWriteLeftBrace = (path, printer, semantics) => {
4
- maybeWriteBrace(path, printer, semantics, {
5
- brace: '(',
6
- });
7
- };
8
-
9
- module.exports.maybeWriteRightBrace = (path, printer, semantics) => {
10
- maybeWriteBrace(path, printer, semantics, {
11
- brace: ')',
12
- });
13
- };
14
-
15
- function maybeWriteBrace(path, printer, semantics, {brace}) {
3
+ module.exports.condition = (path, printer, semantics) => {
16
4
  const {parentPath} = path;
17
5
  const {type} = parentPath;
18
6
  const {roundBraces} = semantics;
19
- const {write} = printer;
20
-
21
- if (type === 'ArrowFunctionExpression') {
22
- write(brace);
23
- return;
24
- }
25
7
 
26
- if (type === 'ConditionalExpression' && path !== parentPath.get('test')) {
27
- write(brace);
28
- return;
29
- }
8
+ if (type === 'ArrowFunctionExpression')
9
+ return true;
30
10
 
31
- if (type === 'LogicalExpression') {
32
- write(brace);
33
- return;
34
- }
11
+ if (type === 'ConditionalExpression' && path !== parentPath.get('test'))
12
+ return true;
35
13
 
36
- if (!roundBraces.sequence)
37
- return;
14
+ if (type === 'LogicalExpression')
15
+ return true;
38
16
 
39
- write(brace);
40
- }
17
+ return roundBraces.sequence;
18
+ };
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ const {hasLeadingComment} = require('#is');
4
+ const noop = () => {};
5
+
6
+ module.exports.printLeadingCommentLine = noop;
7
+ module.exports.printLeadingCommentBlock = noop;
8
+
9
+ module.exports.maybePrintComments = (path, {print}) => {
10
+ if (hasLeadingComment(path)) {
11
+ const {leadingComments} = path.node;
12
+
13
+ for (const {type, value} of leadingComments) {
14
+ if (type === 'CommentLine')
15
+ print(`//${value}`);
16
+ else
17
+ print(`/*${value}*/`);
18
+
19
+ print.breakline();
20
+ }
21
+ }
22
+ };
@@ -1,23 +1,53 @@
1
1
  'use strict';
2
2
 
3
+ const {hasLeadingComment} = require('#is');
4
+ const {maybeParens} = require('../../maybe/maybe-parens');
5
+ const {condition} = require('./maybe-write-brace');
6
+
3
7
  const {
4
- maybeWriteLeftBrace,
5
- maybeWriteRightBrace,
6
- } = require('./maybe-write-brace');
8
+ maybePrintComments,
9
+ printLeadingCommentLine,
10
+ printLeadingCommentBlock,
11
+ } = require('./sequence-expression-comments');
12
+
13
+ module.exports.SequenceExpression = maybeParens({
14
+ checkParens: false,
15
+ condition,
16
+ print(path, printer) {
17
+ const {
18
+ write,
19
+ traverse,
20
+ indent,
21
+ maybe,
22
+ } = printer;
23
+
24
+ const expressions = path.get('expressions');
25
+ const n = expressions.length - 1;
26
+
27
+ const withComment = hasLeadingComment(path);
28
+
29
+ if (withComment) {
30
+ indent.inc();
31
+ write.breakline();
32
+ maybePrintComments(path, printer);
33
+ }
34
+
35
+ for (const [index, expression] of expressions.entries()) {
36
+ traverse(expression);
37
+
38
+ if (index < n) {
39
+ write(',');
40
+ maybe.write.space(!withComment);
41
+ maybe.print.breakline(withComment);
42
+ }
43
+ }
44
+
45
+ if (withComment) {
46
+ indent.dec();
47
+ write.breakline();
48
+ }
49
+ },
50
+ });
7
51
 
8
- module.exports.SequenceExpression = (path, printer, semantics) => {
9
- const {maybe, traverse} = printer;
10
-
11
- const expressions = path.get('expressions');
12
- const n = expressions.length - 1;
13
-
14
- maybeWriteLeftBrace(path, printer, semantics);
15
-
16
- for (const [index, expression] of expressions.entries()) {
17
- traverse(expression);
18
- maybe.write(index < n, ',');
19
- maybe.write.space(index < n);
20
- }
21
-
22
- maybeWriteRightBrace(path, printer, semantics);
23
- };
52
+ module.exports.SequenceExpression.printLeadingCommentLine = printLeadingCommentLine;
53
+ module.exports.SequenceExpression.printLeadingCommentBlock = printLeadingCommentBlock;
@@ -5,7 +5,7 @@ const {JSXAttribute} = require('./jsx-attribute');
5
5
  const {isCoupleLines} = require('../is');
6
6
  const {JSXOpeningElement} = require('./jsx-opening-element');
7
7
  const fragments = require('./jsx-fragment');
8
- const {JSXText} = require('./jsx-text');
8
+ const {JSXText} = require('./jsx-text/jsx-text');
9
9
  const {parseComments} = require('../comment/comment');
10
10
 
11
11
  module.exports = {
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const {isNext} = require('../is');
3
+ const {isNext} = require('#is');
4
4
 
5
5
  module.exports.JSXText = (path, {write, indent}) => {
6
6
  const {node} = path;
@@ -8,7 +8,7 @@ module.exports.JSXText = (path, {write, indent}) => {
8
8
  const isSpacesOnly = /^\s+$/.test(value);
9
9
  const hasNext = isNext(path);
10
10
 
11
- if (extra.raw.includes('&'))
11
+ if (extra?.raw.includes('&'))
12
12
  return write(extra.raw);
13
13
 
14
14
  if (isSpacesOnly && hasNext) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "15.18.2",
3
+ "version": "15.20.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",