@putout/printer 18.0.1 → 18.0.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 +10 -0
- package/lib/tokenize/expressions/class/class.js +2 -2
- package/lib/tokenize/is.js +2 -1
- package/lib/tokenize/statements/block-statement/block-statement-newline.js +4 -1
- package/lib/tokenize/statements/variable-declaration/variable-declaration.js +12 -22
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import {types} from '@putout/babel';
|
|
2
|
+
import {markAfter} from '#mark';
|
|
2
3
|
import {
|
|
3
4
|
hasBody,
|
|
5
|
+
isInsideExport,
|
|
4
6
|
isInsideTSModuleBlock,
|
|
5
7
|
isNext,
|
|
6
8
|
} from '#is';
|
|
7
|
-
import {markAfter} from '#mark';
|
|
8
9
|
import {maybeDeclare} from '../../maybe/maybe-declare.js';
|
|
9
10
|
import {parseComments} from '../../comment/comment.js';
|
|
10
11
|
import {maybeDecorators} from '../../maybe/maybe-decorators.js';
|
|
11
12
|
|
|
12
13
|
const {isFunction} = types;
|
|
13
14
|
|
|
14
|
-
const isInsideExport = ({parentPath}) => parentPath.isExportDeclaration();
|
|
15
15
|
const isFunctionLike = (path) => isFunction(path.parentPath.parentPath);
|
|
16
16
|
|
|
17
17
|
const classVisitor = maybeDecorators((path, printer, semantics) => {
|
package/lib/tokenize/is.js
CHANGED
|
@@ -21,7 +21,7 @@ const {
|
|
|
21
21
|
export const isInsideProgram = (path) => isProgram(path.parentPath);
|
|
22
22
|
export const isInsideBlock = (path) => isBlockStatement(path.parentPath);
|
|
23
23
|
|
|
24
|
-
export const
|
|
24
|
+
export const isInsideBlockLike = createTypeChecker('path.parentPath', [
|
|
25
25
|
'Program',
|
|
26
26
|
'BlockStatement',
|
|
27
27
|
'TSModuleBlock',
|
|
@@ -161,6 +161,7 @@ export const isForOf = (path) => {
|
|
|
161
161
|
};
|
|
162
162
|
|
|
163
163
|
export const isInsideIf = (path) => path.parentPath?.isIfStatement();
|
|
164
|
+
export const isInsideExport = ({parentPath}) => parentPath.isExportDeclaration();
|
|
164
165
|
|
|
165
166
|
export const isNewlineBetweenSiblings = (path) => {
|
|
166
167
|
const endCurrent = path.node?.loc?.end?.line;
|
|
@@ -31,7 +31,10 @@ const isTopLevelWithNoNext = (path) => {
|
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
const isInsideDoWhile = ({parentPath}) => isDoWhileStatement(parentPath);
|
|
34
|
-
const isMethodOrArrow = createTypeChecker([
|
|
34
|
+
const isMethodOrArrow = createTypeChecker([
|
|
35
|
+
'ArrowFunctionExpression',
|
|
36
|
+
'ObjectMethod',
|
|
37
|
+
]);
|
|
35
38
|
const isInsideFn = (path) => path.find(isMethodOrArrow);
|
|
36
39
|
|
|
37
40
|
const isInsideIfWithoutElseInsideFn = createTypeChecker([
|
|
@@ -7,9 +7,10 @@ import {
|
|
|
7
7
|
isNewlineBetweenSiblings,
|
|
8
8
|
exists,
|
|
9
9
|
noTrailingComment,
|
|
10
|
-
|
|
10
|
+
isInsideBlockLike,
|
|
11
11
|
isInsideIf,
|
|
12
12
|
isInsideBlock,
|
|
13
|
+
isInsideExport,
|
|
13
14
|
} from '#is';
|
|
14
15
|
import {maybeSpaceAfterKeyword} from './maybe-space-after-keyword.js';
|
|
15
16
|
import {isConcatenation} from '../../expressions/binary-expression/concatenate.js';
|
|
@@ -53,7 +54,7 @@ export const VariableDeclaration = {
|
|
|
53
54
|
print: maybeDeclare((path, {maybe, store, write, traverse, print, indent}, semantics) => {
|
|
54
55
|
const {maxVariablesInOneLine} = semantics;
|
|
55
56
|
|
|
56
|
-
maybe.indent(
|
|
57
|
+
maybe.indent(isInsideBlockLike(path));
|
|
57
58
|
|
|
58
59
|
write(path.node.kind);
|
|
59
60
|
maybeSpaceAfterKeyword(path, {
|
|
@@ -122,7 +123,7 @@ export const VariableDeclaration = {
|
|
|
122
123
|
isNextCoupleLines,
|
|
123
124
|
notLastPrevVarNotNextVar,
|
|
124
125
|
isNewlineBetweenSiblings,
|
|
125
|
-
|
|
126
|
+
isInsideExport,
|
|
126
127
|
isParentTSModuleBlock,
|
|
127
128
|
],
|
|
128
129
|
after(path, {maybe, store, print}) {
|
|
@@ -142,26 +143,15 @@ const skipAfter = createTypeChecker([
|
|
|
142
143
|
['+: -> !', isInsideBlock],
|
|
143
144
|
]);
|
|
144
145
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
return path.parentPath.isBlockStatement();
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function notLastParentExport(path) {
|
|
153
|
-
if (isLast(path.parentPath))
|
|
154
|
-
return false;
|
|
155
|
-
|
|
156
|
-
return path.parentPath.isExportDeclaration();
|
|
157
|
-
}
|
|
146
|
+
const noNextParentBlock = createTypeChecker([
|
|
147
|
+
['-', isNext],
|
|
148
|
+
['+', isInsideBlock],
|
|
149
|
+
]);
|
|
158
150
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
return isCoupleLines(path);
|
|
164
|
-
}
|
|
151
|
+
const notLastCoupleLines = createTypeChecker([
|
|
152
|
+
['-', isLast],
|
|
153
|
+
['+', isCoupleLines],
|
|
154
|
+
]);
|
|
165
155
|
|
|
166
156
|
function notLastPrevVarNotNextVar(path) {
|
|
167
157
|
const prev = path.getPrevSibling();
|
package/package.json
CHANGED