@putout/printer 12.15.0 → 12.16.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
+ 2025.01.24, v12.16.0
2
+
3
+ feature:
4
+ - 974bf0e @putout/printer: ExpressionStatement: inside AssignemntExpression: after FunctionDeclaration
5
+
1
6
  2025.01.24, v12.15.0
2
7
 
3
8
  feature:
@@ -15,9 +15,11 @@ const {
15
15
  } = require('../../is');
16
16
 
17
17
  const {
18
- isFunctionDeclaration,
18
+ isExpressionStatement,
19
19
  isAssignmentExpression,
20
+ isFunction,
20
21
  } = types;
22
+
21
23
  const not = (fn) => (...a) => !fn(...a);
22
24
 
23
25
  const isBeforeElse = (path) => {
@@ -80,7 +82,7 @@ module.exports.ExpressionStatement = {
80
82
 
81
83
  return isBeforeElse(path);
82
84
  },
83
- after(path, {print, maybe, store}) {
85
+ after(path, {print, maybe, store, indent}) {
84
86
  if (hasTrailingComment(path) && isLast(path) && isCoupleLines(path))
85
87
  print.breakline();
86
88
 
@@ -91,14 +93,16 @@ module.exports.ExpressionStatement = {
91
93
  return;
92
94
 
93
95
  if (notInsideReturn(path)) {
94
- maybe.indent(isInsideAssignNextFunction(path));
96
+ if (isInsideAssignNextAssignFunction(path))
97
+ indent();
98
+
95
99
  print.newline();
96
100
  maybe.markAfter(store(), path);
97
101
  }
98
102
  },
99
103
  };
100
104
 
101
- const isInsideAssignNextFunction = (path) => {
105
+ const isInsideAssignNextAssignFunction = (path) => {
102
106
  const {expression} = path.node;
103
107
 
104
108
  if (!isAssignmentExpression(expression))
@@ -106,7 +110,18 @@ const isInsideAssignNextFunction = (path) => {
106
110
 
107
111
  const next = path.getNextSibling();
108
112
 
109
- return isFunctionDeclaration(next);
113
+ if (!isExpressionStatement(next))
114
+ return false;
115
+
116
+ const {leadingComments} = next.node;
117
+
118
+ if (!leadingComments)
119
+ return false;
120
+
121
+ if (!isAssignmentExpression(next.node.expression))
122
+ return false;
123
+
124
+ return isFunction(next.node.expression.right);
110
125
  };
111
126
 
112
127
  function isTopParentLast({parentPath}) {
@@ -148,4 +163,3 @@ function isStrictMode(path) {
148
163
 
149
164
  return value === 'use strict';
150
165
  }
151
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "12.15.0",
3
+ "version": "12.16.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",