@putout/printer 5.33.0 → 5.35.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
+ 2023.10.24, v5.35.0
2
+
3
+ feature:
4
+ - 7664649 @putout/printer: CommentBlock: improve support
5
+
6
+ 2023.10.24, v5.34.0
7
+
8
+ feature:
9
+ - 66a867a @putout/printer: comments: improve
10
+
1
11
  2023.10.24, v5.33.0
2
12
 
3
13
  feature:
@@ -1,6 +1,8 @@
1
1
  'use strict';
2
2
 
3
- module.exports.parseComments = (path, {write}, semantics) => {
3
+ const {isNext} = require('../is');
4
+
5
+ module.exports.parseComments = (path, {write, maybe}, semantics) => {
4
6
  if (!semantics.comments)
5
7
  return;
6
8
 
@@ -9,11 +11,20 @@ module.exports.parseComments = (path, {write}, semantics) => {
9
11
  if (!comments)
10
12
  return;
11
13
 
12
- for (const {type, value} of comments) {
14
+ const n = comments.length - 1;
15
+ const program = path.isProgram();
16
+
17
+ for (const [i, {type, value}] of comments.entries()) {
13
18
  if (type === 'CommentLine') {
14
- write.breakline();
19
+ maybe.write.breakline(isNext(path) || !program);
15
20
  write('//');
16
21
  write(value);
22
+
23
+ if (program) {
24
+ maybe.write.newline(i < n);
25
+ continue;
26
+ }
27
+
17
28
  write.newline();
18
29
  continue;
19
30
  }
@@ -26,6 +26,11 @@ module.exports.parseTrailingComments = (path, {write, maybe}, semantics) => {
26
26
  maybe.write.space(sameLine);
27
27
  maybe.indent(!sameLine);
28
28
 
29
+ if (path.node.body) {
30
+ write.breakline();
31
+ write.breakline();
32
+ }
33
+
29
34
  write(`//${value}`);
30
35
  maybe.write.newline(!isLast(path) && !isDecorator(path));
31
36
  continue;
@@ -33,6 +38,7 @@ module.exports.parseTrailingComments = (path, {write, maybe}, semantics) => {
33
38
 
34
39
  if (type === 'CommentBlock') {
35
40
  maybe.write.space(sameLine);
41
+ maybe.indent(!sameLine);
36
42
  write(`/*${value}*/`);
37
43
  maybe.write.newline(!sameLine || isCoupleLines(path.parentPath));
38
44
  }
@@ -31,8 +31,14 @@ const isMemberExpressionCallee = ({parentPath}) => {
31
31
  return likeChain(callee);
32
32
  };
33
33
 
34
- module.exports.ObjectExpression = (path, {print, maybe, indent, write}, semantics) => {
34
+ module.exports.ObjectExpression = (path, printer, semantics) => {
35
35
  const {trailingComma} = semantics;
36
+ const {
37
+ print,
38
+ maybe,
39
+ indent,
40
+ } = printer;
41
+
36
42
  indent.inc();
37
43
 
38
44
  const properties = path.get('properties');
@@ -42,7 +48,7 @@ module.exports.ObjectExpression = (path, {print, maybe, indent, write}, semantic
42
48
 
43
49
  maybe.print(parens, '(');
44
50
  print('{');
45
- parseComments(path, {write}, semantics);
51
+ parseComments(path, printer, semantics);
46
52
  maybe.print.newline(manyLines);
47
53
 
48
54
  const n = properties.length - 1;
@@ -29,7 +29,14 @@ const parentIfWithoutElse = ({parentPath}) => {
29
29
  };
30
30
 
31
31
  module.exports.BlockStatement = {
32
- print(path, {indent, maybe, write, traverse}, semantics) {
32
+ print(path, printer, semantics) {
33
+ const {
34
+ indent,
35
+ maybe,
36
+ write,
37
+ traverse,
38
+ } = printer;
39
+
33
40
  const body = path.get('body');
34
41
  const directives = getDirectives(path);
35
42
 
@@ -50,7 +57,7 @@ module.exports.BlockStatement = {
50
57
  traverse(element);
51
58
  }
52
59
 
53
- parseComments(path, {write}, semantics);
60
+ parseComments(path, printer, semantics);
54
61
 
55
62
  indent.dec();
56
63
  maybe.indent(body.length);
@@ -3,10 +3,16 @@
3
3
  const {parseComments} = require('../../comment/comment');
4
4
  const {getDirectives} = require('../block-statement/get-directives');
5
5
 
6
- module.exports.Program = (path, {print, write, traverse, maybe}, semantics) => {
6
+ module.exports.Program = (path, printer, semantics) => {
7
7
  const {body} = path.node;
8
+ const {
9
+ print,
10
+ traverse,
11
+ maybe,
12
+ } = printer;
13
+
8
14
  print('__interpreter');
9
- parseComments(path, {write}, semantics);
15
+ parseComments(path, printer, semantics);
10
16
 
11
17
  const directives = getDirectives(path);
12
18
 
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const {isLast} = require('../../is');
3
+ const {isLast, isNext} = require('../../is');
4
4
  const {markAfter} = require('../../mark');
5
5
  const {maybeDeclare} = require('../../maybe/maybe-declare');
6
6
  const isNextType = (a) => a.getNextSibling().isTSTypeAliasDeclaration();
@@ -32,8 +32,8 @@ module.exports.TSTypeAliasDeclaration = {
32
32
 
33
33
  return !isNextType(path);
34
34
  },
35
- after(path, {print}) {
36
- print.newline();
35
+ after(path, {maybe}) {
36
+ maybe.print.newline(isNext(path) || isNext(path.parentPath));
37
37
  markAfter(path);
38
38
  },
39
39
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "5.33.0",
3
+ "version": "5.35.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",