@putout/printer 1.52.1 → 1.52.3

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,14 @@
1
+ 2023.04.17, v1.52.3
2
+
3
+ fix:
4
+ - f316738 @putout/printer: no newline after VariableDeclaration inside ExportDeclaration
5
+
6
+ 2023.04.17, v1.52.2
7
+
8
+ feature:
9
+ - ef0ef15 @putout/printer: maybe
10
+ - beb210c @putout/printer: ExpressionStatement: apply satisfy
11
+
1
12
  2023.04.17, v1.52.1
2
13
 
3
14
  feature:
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const rendy = require('rendy');
4
- const maybeSatisfy = require('./maybe/satisfy');
4
+ const maybeSatisfy = require('./satisfy');
5
5
 
6
6
  const {
7
7
  isProgram,
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const {satisfy} = require('../is');
4
+
4
5
  module.exports = (plugin) => {
5
6
  if (!plugin.afterSatisfy && !plugin.beforeSatisfy)
6
7
  return plugin;
@@ -6,8 +6,15 @@ const {
6
6
  isParentBlock,
7
7
  isParentLast,
8
8
  isNewlineBetweenStatements,
9
+ satisfy,
9
10
  } = require('../is');
10
11
 
12
+ const shouldBreakline = satisfy([
13
+ isNewlineBetweenStatements,
14
+ isNotLastBody,
15
+ isStrictMode,
16
+ ]);
17
+
11
18
  module.exports.ExpressionStatement = {
12
19
  print(path, {indent, print, maybe, store}) {
13
20
  indent();
@@ -32,23 +39,14 @@ module.exports.ExpressionStatement = {
32
39
  },
33
40
  };
34
41
 
35
- function shouldBreakline(path) {
36
- if (isNewlineBetweenStatements(path))
37
- return true;
38
-
39
- if (isLast(path) || isParentLast(path))
40
- return false;
41
-
42
+ function isNotLastBody(path) {
42
43
  if (!isNext(path) && isParentBlock(path))
43
44
  return false;
44
45
 
45
- if (path.parentPath.get('body') === path)
46
- return true;
47
-
48
- if (isStrictMode(path))
49
- return true;
46
+ if (isLast(path) || isParentLast(path))
47
+ return false;
50
48
 
51
- return false;
49
+ return path.parentPath.get('body') === path;
52
50
  }
53
51
 
54
52
  function isParentOrNotLastORParentLast(path) {
@@ -46,8 +46,19 @@ module.exports.VariableDeclaration = {
46
46
  },
47
47
  };
48
48
 
49
+ function noNextParentBlock(path) {
50
+ return !isNext(path) && path.parentPath.isBlockStatement();
51
+ }
52
+
53
+ function notLastParentExport(path) {
54
+ if (isLast(path.parentPath))
55
+ return false;
56
+
57
+ return path.parentPath.isExportDeclaration();
58
+ }
59
+
49
60
  function shouldAddNewlineAfter(path) {
50
- if (!isNext(path) && path.parentPath.isBlockStatement())
61
+ if (noNextParentBlock(path))
51
62
  return true;
52
63
 
53
64
  if (isLast(path))
@@ -71,9 +82,12 @@ function shouldAddNewlineAfter(path) {
71
82
  if (isNewlineBetweenStatements(path))
72
83
  return true;
73
84
 
85
+ if (notLastParentExport(path))
86
+ return true;
87
+
74
88
  return false;
75
89
  }
76
- const isLast = (path) => path.parentPath.isProgram() && !isNext(path);
90
+ const isLast = (path) => path.parentPath?.isProgram() && !isNext(path);
77
91
 
78
92
  function shouldAddNewlineBefore(path) {
79
93
  if (isFirst(path))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.52.1",
3
+ "version": "1.52.3",
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",