@putout/printer 17.11.0 → 17.12.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 +6 -0
- package/lib/tokenize/expressions/assignment-expression/assignment-expression.js +6 -3
- package/lib/tokenize/expressions/function/function-declaration.js +2 -2
- package/lib/tokenize/is.js +2 -0
- package/lib/tokenize/statements/block-statement/block-statement.js +2 -3
- package/lib/tokenize/statements/debugger-statement.js +6 -4
- package/lib/tokenize/statements/if-statement/if-statement-comments.js +9 -4
- package/lib/tokenize/statements/try-statement/try-statements.js +7 -6
- package/lib/tokenize/statements/variable-declaration/variable-declaration.js +2 -2
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import {maybeParens} from '#maybe-parens';
|
|
2
|
+
import {
|
|
3
|
+
isParentBlock,
|
|
4
|
+
isParentProgram,
|
|
5
|
+
} from '#is';
|
|
2
6
|
import {condition} from './maybe-parens-condition.js';
|
|
3
7
|
import {printSeparator} from './print-separator.js';
|
|
4
8
|
import {
|
|
@@ -8,8 +12,6 @@ import {
|
|
|
8
12
|
printLeadingCommentBlock,
|
|
9
13
|
} from './assignment-expression-comments.js';
|
|
10
14
|
|
|
11
|
-
const isInsideBlock = ({parentPath}) => /BlockStatement|Program/.test(parentPath.type);
|
|
12
|
-
|
|
13
15
|
export const AssignmentExpression = maybeParens({
|
|
14
16
|
checkParens: false,
|
|
15
17
|
condition,
|
|
@@ -25,7 +27,7 @@ export const AssignmentExpression = maybeParens({
|
|
|
25
27
|
printSeparator(path, printer);
|
|
26
28
|
print('__right');
|
|
27
29
|
|
|
28
|
-
if (
|
|
30
|
+
if (isParentBlock(path) || isParentProgram(path)) {
|
|
29
31
|
print(';');
|
|
30
32
|
print.breakline();
|
|
31
33
|
}
|
|
@@ -36,3 +38,4 @@ export const AssignmentExpression = maybeParens({
|
|
|
36
38
|
|
|
37
39
|
AssignmentExpression.printLeadingCommentLine = printLeadingCommentLine;
|
|
38
40
|
AssignmentExpression.printLeadingCommentBlock = printLeadingCommentBlock;
|
|
41
|
+
|
|
@@ -51,7 +51,7 @@ export const FunctionDeclaration = {
|
|
|
51
51
|
print.space();
|
|
52
52
|
print('__body');
|
|
53
53
|
},
|
|
54
|
-
afterSatisfy: () => [isNext, isNextParent,
|
|
54
|
+
afterSatisfy: () => [isNext, isNextParent, isInsideBlockLike],
|
|
55
55
|
after(path, {indent, maybe}) {
|
|
56
56
|
if (isNextAssign(path) || isNextFunction(path) || isNext(path))
|
|
57
57
|
indent();
|
|
@@ -75,7 +75,7 @@ const isNextAssign = (path) => {
|
|
|
75
75
|
return isAssignmentExpression(next.node.expression);
|
|
76
76
|
};
|
|
77
77
|
|
|
78
|
-
function
|
|
78
|
+
function isInsideBlockLike(path) {
|
|
79
79
|
const {parentPath} = path;
|
|
80
80
|
|
|
81
81
|
if (isTSModuleBlock(parentPath.parentPath))
|
package/lib/tokenize/is.js
CHANGED
|
@@ -16,6 +16,7 @@ const {
|
|
|
16
16
|
|
|
17
17
|
export const isParentProgram = (path) => path.parentPath?.isProgram();
|
|
18
18
|
export const isParentBlock = (path) => path.parentPath.isBlockStatement();
|
|
19
|
+
export const isInsideBlockLike = (path) => /^(Program|BlockStatement|TSModuleBlock|SwitchCase)$/.test(path.parentPath.type);
|
|
19
20
|
|
|
20
21
|
export const isNext = (path) => {
|
|
21
22
|
const next = path.getNextSibling();
|
|
@@ -177,3 +178,4 @@ export const hasLeadingComment = (path) => path.node?.leadingComments?.length;
|
|
|
177
178
|
|
|
178
179
|
export const noTrailingComment = (path) => !path.node.trailingComments?.length;
|
|
179
180
|
export const noLeadingComment = (path) => !path.node.leadingComments?.length;
|
|
181
|
+
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
isLast,
|
|
7
7
|
exists,
|
|
8
8
|
satisfy,
|
|
9
|
+
isParentBlock,
|
|
9
10
|
} from '#is';
|
|
10
11
|
import {parseComments} from '../../comment/comment.js';
|
|
11
12
|
import {insideIfWithNoBody} from './inside-if-with-no-body.js';
|
|
@@ -18,7 +19,6 @@ const {
|
|
|
18
19
|
isFunctionDeclaration,
|
|
19
20
|
isExportDeclaration,
|
|
20
21
|
isDoWhileStatement,
|
|
21
|
-
isBlockStatement,
|
|
22
22
|
isArrayExpression,
|
|
23
23
|
} = types;
|
|
24
24
|
|
|
@@ -127,7 +127,6 @@ const NEWLINE = true;
|
|
|
127
127
|
const NO_NEWLINE = false;
|
|
128
128
|
|
|
129
129
|
const isInsideDoWhile = ({parentPath}) => isDoWhileStatement(parentPath);
|
|
130
|
-
const isInsideBlock = ({parentPath}) => isBlockStatement(parentPath);
|
|
131
130
|
|
|
132
131
|
const isNoNewline = satisfy([
|
|
133
132
|
isInsideDoWhile,
|
|
@@ -136,7 +135,7 @@ const isNoNewline = satisfy([
|
|
|
136
135
|
]);
|
|
137
136
|
|
|
138
137
|
function shouldAddNewlineAfter(path) {
|
|
139
|
-
if (
|
|
138
|
+
if (isParentBlock(path))
|
|
140
139
|
return NEWLINE;
|
|
141
140
|
|
|
142
141
|
if (isNoNewline(path))
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
isNext,
|
|
3
|
+
isInsideIf,
|
|
4
|
+
isParentBlock,
|
|
5
|
+
} from '#is';
|
|
4
6
|
|
|
5
7
|
export const DebuggerStatement = {
|
|
6
8
|
print(path, {print, indent}) {
|
|
@@ -9,7 +11,7 @@ export const DebuggerStatement = {
|
|
|
9
11
|
},
|
|
10
12
|
afterSatisfy: () => [
|
|
11
13
|
isNext,
|
|
12
|
-
|
|
14
|
+
isParentBlock,
|
|
13
15
|
isInsideIf,
|
|
14
16
|
],
|
|
15
17
|
after(path, {print}) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {types} from '@putout/babel';
|
|
2
|
-
import {isNext} from '#is';
|
|
2
|
+
import {isNext, isParentBlock} from '#is';
|
|
3
3
|
|
|
4
4
|
const {isBlockStatement} = types;
|
|
5
5
|
|
|
@@ -12,13 +12,18 @@ export const printTrailingCommentBlock = (path, printer, semantics, {printCommen
|
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
export const printTrailingCommentLine = (path, printer, semantics, {printComment}) => {
|
|
15
|
+
const hasNext = isNext(path);
|
|
15
16
|
const {consequent} = path.node;
|
|
16
17
|
const consequentIsBlock = isBlockStatement(consequent);
|
|
17
|
-
const {print
|
|
18
|
+
const {print} = printer;
|
|
18
19
|
|
|
19
20
|
print.indent();
|
|
20
|
-
|
|
21
|
+
|
|
22
|
+
if (!hasNext && !consequentIsBlock)
|
|
23
|
+
print.space();
|
|
21
24
|
|
|
22
25
|
printComment();
|
|
23
|
-
|
|
26
|
+
|
|
27
|
+
if (hasNext || isParentBlock(path))
|
|
28
|
+
print.newline();
|
|
24
29
|
};
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import {types} from '@putout/babel';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
isNext,
|
|
4
|
+
isNextTry,
|
|
5
|
+
isParentBlock,
|
|
6
|
+
} from '#is';
|
|
3
7
|
|
|
4
8
|
const {isExpressionStatement} = types;
|
|
5
9
|
|
|
@@ -34,6 +38,7 @@ const isNextExpression = (path) => {
|
|
|
34
38
|
};
|
|
35
39
|
|
|
36
40
|
export const CatchClause = (path, {print, maybe}) => {
|
|
41
|
+
const {parentPath} = path;
|
|
37
42
|
const param = path.get('param');
|
|
38
43
|
const body = path.get('body');
|
|
39
44
|
|
|
@@ -50,9 +55,5 @@ export const CatchClause = (path, {print, maybe}) => {
|
|
|
50
55
|
}
|
|
51
56
|
|
|
52
57
|
print(body);
|
|
53
|
-
maybe.print.newline(
|
|
58
|
+
maybe.print.newline(isParentBlock(parentPath));
|
|
54
59
|
};
|
|
55
|
-
|
|
56
|
-
function isInsideBlock(path) {
|
|
57
|
-
return path.parentPath.parentPath.isBlockStatement();
|
|
58
|
-
}
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
isNewlineBetweenSiblings,
|
|
7
7
|
exists,
|
|
8
8
|
noTrailingComment,
|
|
9
|
+
isInsideBlockLike,
|
|
9
10
|
} from '#is';
|
|
10
11
|
import {maybeSpaceAfterKeyword} from './maybe-space-after-keyword.js';
|
|
11
12
|
import {isConcatenation} from '../../expressions/binary-expression/concatenate.js';
|
|
@@ -16,7 +17,6 @@ const {isExportDeclaration} = types;
|
|
|
16
17
|
|
|
17
18
|
const isParentTSModuleBlock = (path) => path.parentPath.isTSModuleBlock();
|
|
18
19
|
const isParentBlock = (path) => /Program|BlockStatement|Export|LabeledStatement/.test(path.parentPath.type);
|
|
19
|
-
const isInsideBlock = (path) => /^(Program|BlockStatement|TSModuleBlock|SwitchCase)$/.test(path.parentPath.type);
|
|
20
20
|
const isParentSwitchCase = (path) => path.parentPath.isSwitchCase();
|
|
21
21
|
const isFirstInSwitch = (path) => path.parentPath.get('consequent.0') === path;
|
|
22
22
|
const isParentIf = (path) => path.parentPath.isIfStatement();
|
|
@@ -29,7 +29,7 @@ export const VariableDeclaration = {
|
|
|
29
29
|
print: maybeDeclare((path, {maybe, store, write, traverse, print, indent}, semantics) => {
|
|
30
30
|
const {maxVariablesInOneLine} = semantics;
|
|
31
31
|
|
|
32
|
-
maybe.indent(
|
|
32
|
+
maybe.indent(isInsideBlockLike(path));
|
|
33
33
|
|
|
34
34
|
write(path.node.kind);
|
|
35
35
|
maybeSpaceAfterKeyword(path, {
|
package/package.json
CHANGED