@putout/printer 12.13.0 → 12.15.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
+ 2025.01.24, v12.15.0
2
+
3
+ feature:
4
+ - 138144f @putout/printer: ExpressionStatement: indent: inside AssignmentExpression: after FunctionDeclaration
5
+
6
+ 2025.01.24, v12.14.0
7
+
8
+ feature:
9
+ - c8360c5 @putout/printer: FunctionDeclaration: indent before FunctionDeclaration
10
+
1
11
  2025.01.24, v12.13.0
2
12
 
3
13
  feature:
@@ -11,6 +11,7 @@ const {
11
11
  isBlockStatement,
12
12
  isExportNamedDeclaration,
13
13
  isExpressionStatement,
14
+ isFunctionDeclaration,
14
15
  } = types;
15
16
 
16
17
  const isInsideNamedExport = ({parentPath}) => isExportNamedDeclaration(parentPath);
@@ -49,13 +50,20 @@ module.exports.FunctionDeclaration = {
49
50
  print('__body');
50
51
  },
51
52
  afterSatisfy: () => [isNext, isNextParent, isInsideBlockStatement],
52
- after(path, {write, maybe}) {
53
- maybe.indent(isNextAssign(path));
53
+ after(path, {write, indent}) {
54
+ if (isNextAssign(path) || isNextFunction(path))
55
+ indent();
56
+
54
57
  write.newline();
55
58
  markAfter(path);
56
59
  },
57
60
  };
58
61
 
62
+ const isNextFunction = (path) => {
63
+ const next = path.getNextSibling();
64
+ return isFunctionDeclaration(next);
65
+ };
66
+
59
67
  const isNextAssign = (path) => {
60
68
  const next = path.getNextSibling();
61
69
 
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ const {types} = require('@putout/babel');
3
4
  const {
4
5
  isNext,
5
6
  isLast,
@@ -13,6 +14,10 @@ const {
13
14
  isInsideLabel,
14
15
  } = require('../../is');
15
16
 
17
+ const {
18
+ isFunctionDeclaration,
19
+ isAssignmentExpression,
20
+ } = types;
16
21
  const not = (fn) => (...a) => !fn(...a);
17
22
 
18
23
  const isBeforeElse = (path) => {
@@ -86,12 +91,24 @@ module.exports.ExpressionStatement = {
86
91
  return;
87
92
 
88
93
  if (notInsideReturn(path)) {
94
+ maybe.indent(isInsideAssignNextFunction(path));
89
95
  print.newline();
90
96
  maybe.markAfter(store(), path);
91
97
  }
92
98
  },
93
99
  };
94
100
 
101
+ const isInsideAssignNextFunction = (path) => {
102
+ const {expression} = path.node;
103
+
104
+ if (!isAssignmentExpression(expression))
105
+ return false;
106
+
107
+ const next = path.getNextSibling();
108
+
109
+ return isFunctionDeclaration(next);
110
+ };
111
+
95
112
  function isTopParentLast({parentPath}) {
96
113
  if (!parentPath.isIfStatement())
97
114
  return false;
@@ -131,3 +148,4 @@ function isStrictMode(path) {
131
148
 
132
149
  return value === 'use strict';
133
150
  }
151
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "12.13.0",
3
+ "version": "12.15.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",