@putout/printer 1.40.1 → 1.40.2

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.04.13, v1.40.2
2
+
3
+ feature:
4
+ - 6d8d812 @putout/printer: comments: newline after CommentLine
5
+
1
6
  2023.04.13, v1.40.1
2
7
 
3
8
  fix:
@@ -45,7 +45,7 @@ module.exports.parseLeadingComments = (path, {print, maybe}) => {
45
45
  }
46
46
  };
47
47
 
48
- module.exports.parseTrailingComments = (path, {print}) => {
48
+ module.exports.parseTrailingComments = (path, {write, maybe}) => {
49
49
  const {trailingComments} = path.node;
50
50
 
51
51
  if (!trailingComments || !trailingComments.length)
@@ -54,10 +54,13 @@ module.exports.parseTrailingComments = (path, {print}) => {
54
54
  if (isNext(path))
55
55
  return;
56
56
 
57
- for (const {type, value} of trailingComments) {
57
+ for (const {type, value, loc} of trailingComments) {
58
58
  if (type === 'CommentLine') {
59
- print.space();
60
- print(`//${value}`);
59
+ const sameLine = isSameLine(path, loc);
60
+ maybe.write.space(sameLine);
61
+ maybe.indent(!sameLine);
62
+ write(`//${value}`);
63
+ maybe.write.newline(!sameLine);
61
64
 
62
65
  continue;
63
66
  }
@@ -67,3 +70,7 @@ module.exports.parseTrailingComments = (path, {print}) => {
67
70
  function shouldAddNewlineBefore(path) {
68
71
  return path.isStatement() && !isFirst(path) && !hasPrevNewline(path);
69
72
  }
73
+
74
+ function isSameLine(path, loc) {
75
+ return path.node.loc.start.line === loc.start.line;
76
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.40.1",
3
+ "version": "1.40.2",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "Easiest possible opinionated Babel AST printer made with ❤️ to use in 🐊Putout",