@putout/printer 1.14.0 → 1.14.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,16 @@
1
+ 2023.03.30, v1.14.2
2
+
3
+ feature:
4
+ - 6bf7725 @putout/printer: add support of EmptyStatement
5
+
6
+ 2023.03.30, v1.14.1
7
+
8
+ fix:
9
+ - 1a117af @putout/printer: duplicate comment
10
+
11
+ feature:
12
+ - 260d680 @putout/printer: add support of getters
13
+
1
14
  2023.03.30, v1.14.0
2
15
 
3
16
  feature:
package/README.md CHANGED
@@ -24,7 +24,6 @@ const ast = parse('const a = (b, c) => {const d = 5; return a;}');
24
24
 
25
25
  print(ast);
26
26
 
27
- // returns
28
27
  // returns
29
28
  `
30
29
  const a = (b, c) => {
@@ -32,7 +31,6 @@ const a = (b, c) => {
32
31
  return a;
33
32
  };
34
33
  `;
35
-
36
34
  ```
37
35
 
38
36
  ## Overrides
@@ -62,10 +60,8 @@ print(ast, {
62
60
  },
63
61
  });
64
62
 
65
- // returns
66
63
  // returns
67
64
  'const {a /* [hello world] */= 5} = b;\n';
68
-
69
65
  ```
70
66
 
71
67
  ## License
@@ -1,7 +1,13 @@
1
1
  'use strict';
2
2
 
3
- const {isFirst} = require('./is');
4
- const {markBefore} = require('./mark');
3
+ const {
4
+ isFirst,
5
+ isNext,
6
+ } = require('./is');
7
+ const {
8
+ markBefore,
9
+ hasPrevNewline,
10
+ } = require('./mark');
5
11
 
6
12
  module.exports.parseLeadingComments = (path, {print, indent}) => {
7
13
  const {leadingComments} = path.node;
@@ -41,6 +47,9 @@ module.exports.parseTrailingComments = (path, {print}) => {
41
47
  if (!trailingComments || !trailingComments.length)
42
48
  return;
43
49
 
50
+ if (isNext(path))
51
+ return;
52
+
44
53
  for (const {type, value} of trailingComments) {
45
54
  if (type === 'CommentLine') {
46
55
  print.space();
@@ -52,5 +61,5 @@ module.exports.parseTrailingComments = (path, {print}) => {
52
61
  };
53
62
 
54
63
  function shouldAddNewlineBefore(path) {
55
- return path.isStatement() && !isFirst(path);
64
+ return path.isStatement() && !isFirst(path) && !hasPrevNewline(path);
56
65
  }
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- module.exports.ClassDeclaration = (path, {maybe, print, indent}) => {
3
+ module.exports.ClassDeclaration = (path, {print, indent}) => {
4
4
  indent();
5
5
  print('class ');
6
6
  print('__id');
@@ -17,12 +17,10 @@ module.exports.ClassDeclaration = (path, {maybe, print, indent}) => {
17
17
  indent.inc();
18
18
 
19
19
  const body = path.get('body.body');
20
- const n = body.length - 1;
21
20
 
22
- for (const [i, item] of body.entries()) {
21
+ for (const item of body) {
23
22
  indent();
24
23
  print(item);
25
- maybe.print(i < n, '\n');
26
24
  }
27
25
 
28
26
  indent.dec();
@@ -51,6 +51,11 @@ function ArrowFunctionExpression(path, {print, maybe}) {
51
51
  print('__body');
52
52
  }
53
53
  module.exports.ObjectMethod = (path, {print}) => {
54
+ const {kind} = path.node;
55
+
56
+ if (kind !== 'method')
57
+ print(`${kind} `);
58
+
54
59
  print('__key');
55
60
  print('(');
56
61
 
@@ -94,6 +99,11 @@ module.exports.FunctionDeclaration = (path, {print, maybe}) => {
94
99
  };
95
100
 
96
101
  module.exports.ClassMethod = (path, {print}) => {
102
+ const {kind} = path.node;
103
+
104
+ if (kind !== 'method')
105
+ print(`${kind} `);
106
+
97
107
  print('__key');
98
108
  print('(');
99
109
 
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  const {isCoupleLines} = require('../is');
4
-
5
4
  const isBodyOfArrow = (path) => path.parentPath.node.body === path.node;
6
5
  const isLogical = (path) => path.get('argument').isLogicalExpression();
7
6
 
@@ -90,4 +89,3 @@ function isOneLine(path) {
90
89
 
91
90
  return isForOf(path);
92
91
  }
93
-
@@ -44,6 +44,7 @@ function unaryExpression(path, {print, maybe}) {
44
44
  maybe.print(isWord(
45
45
  operator,
46
46
  ), ' ');
47
+
47
48
  print('__argument');
48
49
 
49
50
  if (!prefix)
@@ -2,8 +2,17 @@
2
2
 
3
3
  const isParentProgram = (path) => path.parentPath?.isProgram();
4
4
  const isParentBlock = (path) => path.parentPath.isBlockStatement();
5
- const isNext = (path) => path.getNextSibling().node;
6
- const isNextParent = (path) => path.parentPath.getNextSibling().node;
5
+
6
+ const isNext = (path) => {
7
+ const next = path.getNextSibling();
8
+
9
+ if (!next.node)
10
+ return false;
11
+
12
+ return !next.isEmptyStatement();
13
+ };
14
+
15
+ const isNextParent = (path) => isNext(path.parentPath);
7
16
  const isLast = (path) => isParentProgram(path) && !isNext(path);
8
17
 
9
18
  module.exports.isFirst = (path) => path.node === path.parentPath.node.body[0];
@@ -35,6 +35,7 @@ module.exports = {
35
35
  path.get('body').forEach(print);
36
36
  print.newline();
37
37
  },
38
+ EmptyStatement({}) {},
38
39
  InterpreterDirective(path, {print}) {
39
40
  print(`#!${path.node.value}`);
40
41
  print.newline();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.14.0",
3
+ "version": "1.14.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",