@putout/printer 2.48.0 → 2.50.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,16 @@
1
+ 2023.07.05, v2.50.0
2
+
3
+ feature:
4
+ - f77a990 @putout/printer: BlockStatement: newlines
5
+ - 483494a package: c8 v8.0.0
6
+ - dabddf7 package: @putout/plugin-promises v11.0.0
7
+ - bf8f478 package: putout v30.0.0
8
+
9
+ 2023.07.05, v2.49.0
10
+
11
+ feature:
12
+ - 1120884 @putout/printer: ImportDeclaration: newline
13
+
1
14
  2023.07.05, v2.48.0
2
15
 
3
16
  feature:
@@ -4,37 +4,35 @@ const {isNext} = require('../../is');
4
4
  const {markAfter} = require('../../mark');
5
5
  const {maybeDecorators} = require('../../maybe-get');
6
6
 
7
- module.exports.ClassExpression = classVisitor;
7
+ const isInsideExport = ({parentPath}) => parentPath.isExportDeclaration();
8
8
 
9
- module.exports.StaticBlock = (path, {print, traverse}) => {
10
- print('static ');
11
- print('{');
12
- print.breakline();
13
-
14
- for (const child of path.get('body')) {
15
- traverse(child);
16
- }
17
-
18
- print.indent();
19
- print('}');
20
- print.newline();
21
- };
9
+ module.exports.ClassExpression = classVisitor;
22
10
 
23
- module.exports.ClassDeclaration = (path, {print, indent, maybe, write, traverse}) => {
24
- indent();
25
-
26
- classVisitor(path, {
27
- print,
28
- indent,
29
- maybe,
30
- traverse,
31
- });
32
-
33
- if (!path.parentPath.isExportDeclaration() && isNext(path)) {
11
+ module.exports.ClassDeclaration = {
12
+ print(path, {print, indent, maybe, traverse}) {
13
+ indent();
14
+
15
+ classVisitor(path, {
16
+ print,
17
+ indent,
18
+ maybe,
19
+ traverse,
20
+ });
21
+ },
22
+ afterIf(path) {
23
+ if (!isNext(path))
24
+ return false;
25
+
26
+ return !isInsideExport(path);
27
+ },
28
+ after(path, {write}) {
34
29
  write.newline();
35
- maybe.write.newline(path.node.body.body.length);
36
- markAfter(path);
37
- }
30
+
31
+ if (path.node.body.body.length) {
32
+ write.newline();
33
+ markAfter(path);
34
+ }
35
+ },
38
36
  };
39
37
 
40
38
  function classVisitor(path, {print, indent, maybe, traverse}) {
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ module.exports.StaticBlock = (path, {print, traverse}) => {
4
+ print('static ');
5
+ print('{');
6
+ print.breakline();
7
+
8
+ for (const child of path.get('body')) {
9
+ traverse(child);
10
+ }
11
+
12
+ print.indent();
13
+ print('}');
14
+ print.newline();
15
+ };
@@ -7,7 +7,6 @@ const memberExpressions = require('./member-expressions/member-expressions');
7
7
  const {
8
8
  ClassExpression,
9
9
  ClassDeclaration,
10
- StaticBlock,
11
10
  } = require('./class/class');
12
11
 
13
12
  const {
@@ -42,6 +41,7 @@ const {
42
41
  } = require('./binary-expression/binary-expression');
43
42
 
44
43
  const {ConditionalExpression} = require('./conditional-expression');
44
+ const {StaticBlock} = require('./class/static-block');
45
45
 
46
46
  module.exports = {
47
47
  ...functions,
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const {exists} = require('../is');
4
+ const {isMarkedAfter} = require('../mark');
4
5
  const isInsideExpressionStatement = ({parentPath}) => parentPath.isExpressionStatement();
5
6
  const notFirst = ({parentPath}) => exists(parentPath.getPrevSibling());
6
7
 
@@ -23,6 +24,9 @@ module.exports.NewExpression = {
23
24
  if (!exists)
24
25
  return false;
25
26
 
27
+ if (isMarkedAfter(prev))
28
+ return false;
29
+
26
30
  if (prev.isExpressionStatement())
27
31
  return false;
28
32
 
@@ -4,6 +4,12 @@ const {markAfter} = require('../../mark');
4
4
  const {exists} = require('../../is');
5
5
 
6
6
  const isEmptyConsequent = (path) => path.get('consequent').isEmptyStatement();
7
+ const isInsideNestedBody = ({parentPath}) => {
8
+ if (parentPath.type !== 'BlockStatement')
9
+ return false;
10
+
11
+ return parentPath.parentPath.type === 'BlockStatement';
12
+ };
7
13
 
8
14
  const isInsideIf = (path) => path.parentPath.parentPath?.isIfStatement();
9
15
  const isEmptyBody = (path) => !path.node.body.length;
@@ -24,7 +30,10 @@ module.exports.IfStatement = {
24
30
  if (isConsequentBlock) {
25
31
  print.space();
26
32
  print(consequent);
27
- maybe.print.newline(isEmptyBody(consequent) && isInsideIf(path));
33
+
34
+ if (isInsideIf(path) || isInsideNestedBody(path)) {
35
+ maybe.print.newline(isEmptyBody(consequent));
36
+ }
28
37
  } else {
29
38
  const is = !isEmptyConsequent(path);
30
39
  maybe.print.newline(is);
@@ -64,3 +73,4 @@ module.exports.IfStatement = {
64
73
  markAfter(path);
65
74
  },
66
75
  };
76
+
@@ -14,4 +14,3 @@ module.exports.TSInterfaceDeclaration = {
14
14
  print.breakline();
15
15
  },
16
16
  };
17
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "2.48.0",
3
+ "version": "2.50.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",
@@ -50,12 +50,12 @@
50
50
  "@babel/plugin-codemod-object-assign-to-object-spread": "^7.10.4",
51
51
  "@putout/plugin-minify": "^1.8.0",
52
52
  "@putout/plugin-printer": "^1.0.0",
53
- "@putout/plugin-promises": "^10.0.0",
53
+ "@putout/plugin-promises": "^11.0.0",
54
54
  "@putout/plugin-react-hook-form": "^3.4.1",
55
55
  "@putout/plugin-react-hooks": "^5.0.0",
56
56
  "@putout/test": "^6.0.1",
57
57
  "acorn": "^8.8.2",
58
- "c8": "^7.5.0",
58
+ "c8": "^8.0.0",
59
59
  "escover": "^3.0.0",
60
60
  "eslint": "^8.0.1",
61
61
  "eslint-plugin-n": "^16.0.0",
@@ -66,7 +66,7 @@
66
66
  "mock-require": "^3.0.3",
67
67
  "montag": "^1.0.0",
68
68
  "nodemon": "^2.0.1",
69
- "putout": "29",
69
+ "putout": "^30.0.0",
70
70
  "supertape": "^8.0.0",
71
71
  "try-catch": "^3.0.0"
72
72
  },