@putout/printer 6.8.2 → 6.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,8 @@
1
+ 2023.11.30, v6.9.0
2
+
3
+ feature:
4
+ - 672f353 @putout/printer: improve support of trailing comments on next line
5
+
1
6
  2023.11.30, v6.8.2
2
7
 
3
8
  feature:
@@ -13,6 +13,23 @@ function isSameLine(path, loc) {
13
13
  return path.node.loc?.start.line === loc.start.line || path.node.loc?.end.line === loc.end.line;
14
14
  }
15
15
 
16
+ const isTrailingIsLeading = (path) => path.node.trailingComments === path.getNextSibling().node?.leadingComments;
17
+
18
+ function isCommentOnNextLine(path) {
19
+ const {
20
+ loc,
21
+ trailingComments,
22
+ } = path.node;
23
+
24
+ if (isTrailingIsLeading(path))
25
+ return false;
26
+
27
+ const [comment] = trailingComments;
28
+ const {line} = comment.loc.start;
29
+
30
+ return line === loc.start.line + 1;
31
+ }
32
+
16
33
  module.exports.parseTrailingComments = (path, {write, maybe}, semantics) => {
17
34
  if (!semantics.comments)
18
35
  return;
@@ -29,10 +46,12 @@ module.exports.parseTrailingComments = (path, {write, maybe}, semantics) => {
29
46
 
30
47
  for (const {type, value, loc} of trailingComments) {
31
48
  const sameLine = isSameLine(path, loc);
49
+ const commentOnNextLine = isCommentOnNextLine(path);
32
50
 
33
51
  if (type === 'CommentLine') {
52
+ maybe.write.breakline(commentOnNextLine);
34
53
  maybe.write.space(sameLine);
35
- maybe.indent(!sameLine);
54
+ maybe.indent(!sameLine && !commentOnNextLine);
36
55
 
37
56
  if (hasBody(path)) {
38
57
  maybe.write.breakline(!isNext(path));
@@ -53,3 +72,4 @@ module.exports.parseTrailingComments = (path, {write, maybe}, semantics) => {
53
72
  }
54
73
  }
55
74
  };
75
+
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const {hasTrailingComment} = require('../is');
4
+
4
5
  module.exports.SpreadElement = (path, printer) => {
5
6
  const {print} = printer;
6
7
  print('...');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "6.8.2",
3
+ "version": "6.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",