@putout/printer 2.48.0 → 2.49.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.07.05, v2.49.0
2
+
3
+ feature:
4
+ - 1120884 @putout/printer: ImportDeclaration: newline
5
+
1
6
  2023.07.05, v2.48.0
2
7
 
3
8
  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,16 @@
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
+ };
16
+
@@ -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
 
@@ -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.49.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",