@putout/printer 18.1.0 → 18.1.2
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 +13 -0
- package/lib/tokenize/expressions/array-expression/array-expression.js +19 -31
- package/lib/tokenize/expressions/array-expression/before-if.js +24 -0
- package/lib/tokenize/expressions/array-expression/indent.js +1 -3
- package/lib/tokenize/expressions/array-expression/is-object-after-simple.js +0 -6
- package/lib/tokenize/expressions/array-expression/newline.js +1 -1
- package/lib/tokenize/expressions/member-expression/is-looks-like-chain.js +5 -1
- package/lib/tokenize/expressions/object-expression/object-expression.js +6 -1
- package/lib/tokenize/is.js +1 -0
- package/lib/tokenize/statements/expression-statement/expression-statement.js +15 -15
- package/lib/tokenize/type-checker/parsers.js +1 -1
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
2026.03.06, v18.1.2
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 5996fbf @putout/printer: TypeChecker: ->
|
|
5
|
+
- 7001376 @putout/printer: ArrayExpression: beforeIf: move out
|
|
6
|
+
- 2f22d1d @putout/printer: ArrayExpression: isSimpleBetweenObjects
|
|
7
|
+
- 50166f4 @putout/printer: ArrayExpression: isSpaceAfterComma
|
|
8
|
+
|
|
9
|
+
2026.03.06, v18.1.1
|
|
10
|
+
|
|
11
|
+
feature:
|
|
12
|
+
- ba26d34 @putout/printer: ExpressionStatement: isBreakline
|
|
13
|
+
|
|
1
14
|
2026.03.06, v18.1.0
|
|
2
15
|
|
|
3
16
|
feature:
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {types} from '@putout/babel';
|
|
2
|
+
import {createTypeChecker} from '#type-checker';
|
|
2
3
|
import {
|
|
3
4
|
isCoupleLines,
|
|
4
5
|
isStringAndIdentifier,
|
|
@@ -6,6 +7,8 @@ import {
|
|
|
6
7
|
isStringAndArray,
|
|
7
8
|
isSimpleAndNotEmptyObject,
|
|
8
9
|
isNextObject,
|
|
10
|
+
getNext,
|
|
11
|
+
isInsideArray,
|
|
9
12
|
} from '#is';
|
|
10
13
|
import {
|
|
11
14
|
isIncreaseIndent,
|
|
@@ -13,14 +16,14 @@ import {
|
|
|
13
16
|
isMultiLine,
|
|
14
17
|
} from './newline.js';
|
|
15
18
|
import {
|
|
16
|
-
isInsideArray,
|
|
17
19
|
isArrayInsideArray,
|
|
18
20
|
isArrayIndented,
|
|
19
21
|
} from './indent.js';
|
|
22
|
+
import {isObjectAfterSimple} from './is-object-after-simple.js';
|
|
20
23
|
import {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
} from './
|
|
24
|
+
beforeIf,
|
|
25
|
+
isInsideOneElementArray,
|
|
26
|
+
} from './before-if.js';
|
|
24
27
|
|
|
25
28
|
const {
|
|
26
29
|
isObjectExpression,
|
|
@@ -60,35 +63,20 @@ const isSpreadBeforeObject = (a) => {
|
|
|
60
63
|
return prev.get('argument').isCallExpression();
|
|
61
64
|
};
|
|
62
65
|
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return next
|
|
71
|
-
.getNextSibling()
|
|
72
|
-
.isObjectExpression();
|
|
73
|
-
};
|
|
66
|
+
const isSimpleBetweenObjects = createTypeChecker([
|
|
67
|
+
['+', getNext(isObjectExpression)],
|
|
68
|
+
['-', isSpreadElement],
|
|
69
|
+
['-', isIdentifier],
|
|
70
|
+
['+: -> !', isCallExpression],
|
|
71
|
+
]);
|
|
74
72
|
|
|
75
|
-
const
|
|
73
|
+
const isSpaceAfterComa = createTypeChecker([
|
|
74
|
+
getNext(isSimpleBetweenObjects),
|
|
75
|
+
'+: -> !ObjectExpression',
|
|
76
|
+
]);
|
|
76
77
|
|
|
77
78
|
export const ArrayExpression = {
|
|
78
|
-
beforeIf
|
|
79
|
-
const {parentPath} = path;
|
|
80
|
-
|
|
81
|
-
if (!parentPath.isArrayExpression())
|
|
82
|
-
return false;
|
|
83
|
-
|
|
84
|
-
if (isCoupleLines(parentPath))
|
|
85
|
-
return false;
|
|
86
|
-
|
|
87
|
-
if (isStringAndIdentifier(path) && isInsideOneElementArray(path))
|
|
88
|
-
return true;
|
|
89
|
-
|
|
90
|
-
return isIdentifierAndIdentifier(path);
|
|
91
|
-
},
|
|
79
|
+
beforeIf,
|
|
92
80
|
before(path, {print}) {
|
|
93
81
|
print.breakline();
|
|
94
82
|
},
|
|
@@ -137,7 +125,7 @@ export const ArrayExpression = {
|
|
|
137
125
|
if (!is && index < n) {
|
|
138
126
|
print(',');
|
|
139
127
|
|
|
140
|
-
if (
|
|
128
|
+
if (isSpaceAfterComa(element))
|
|
141
129
|
print.space();
|
|
142
130
|
}
|
|
143
131
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {createTypeChecker} from '#type-checker';
|
|
2
|
+
import {
|
|
3
|
+
isCoupleLines,
|
|
4
|
+
isIdentifierAndIdentifier,
|
|
5
|
+
isInsideArray,
|
|
6
|
+
isStringAndIdentifier,
|
|
7
|
+
} from '#is';
|
|
8
|
+
|
|
9
|
+
export const isInsideOneElementArray = ({parentPath}) => {
|
|
10
|
+
const {elements} = parentPath.node;
|
|
11
|
+
return elements.length === 1;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const isStringAndIdentifierInsideOneElementArray = createTypeChecker([
|
|
15
|
+
['-: -> !', isStringAndIdentifier],
|
|
16
|
+
['+', isInsideOneElementArray],
|
|
17
|
+
]);
|
|
18
|
+
|
|
19
|
+
export const beforeIf = createTypeChecker([
|
|
20
|
+
['-: -> !', isInsideArray],
|
|
21
|
+
['-: parentPath ->', isCoupleLines],
|
|
22
|
+
isIdentifierAndIdentifier,
|
|
23
|
+
isStringAndIdentifierInsideOneElementArray,
|
|
24
|
+
]);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {types} from '@putout/babel';
|
|
2
|
-
import {isIndented} from '#is';
|
|
2
|
+
import {isIndented, isInsideArray} from '#is';
|
|
3
3
|
|
|
4
4
|
const {
|
|
5
5
|
isStringLiteral,
|
|
@@ -8,8 +8,6 @@ const {
|
|
|
8
8
|
isTemplateLiteral,
|
|
9
9
|
} = types;
|
|
10
10
|
|
|
11
|
-
export const isInsideArray = (path) => path.parentPath.isArrayExpression();
|
|
12
|
-
|
|
13
11
|
const isObjectAfterString = ([first, second]) => {
|
|
14
12
|
if (!first || !second)
|
|
15
13
|
return false;
|
|
@@ -10,8 +10,8 @@ import {
|
|
|
10
10
|
isIdentifierAndIdentifier,
|
|
11
11
|
isSimpleAndNotEmptyObject,
|
|
12
12
|
isInsideCall,
|
|
13
|
+
isInsideArray,
|
|
13
14
|
} from '#is';
|
|
14
|
-
import {isInsideArray} from './indent.js';
|
|
15
15
|
import {isInsideForOf} from '../object-pattern/is.js';
|
|
16
16
|
|
|
17
17
|
const isLastArg = ({parentPath}) => !parentPath.isCallExpression();
|
|
@@ -12,7 +12,11 @@ const {
|
|
|
12
12
|
const isArgOfCall = (path) => path.parentPath?.isCallExpression() && path.parentPath.get('arguments.0') === path;
|
|
13
13
|
const isCall = (a) => a.type === 'CallExpression';
|
|
14
14
|
|
|
15
|
-
const isExcludedFromChain = satisfy([
|
|
15
|
+
const isExcludedFromChain = satisfy([
|
|
16
|
+
isUnaryExpression,
|
|
17
|
+
isIfStatement,
|
|
18
|
+
]);
|
|
19
|
+
|
|
16
20
|
const hasComment = ({type}) => type === 'CommentLine';
|
|
17
21
|
|
|
18
22
|
const isInsideMemberCall = (path) => {
|
|
@@ -38,7 +38,12 @@ const {
|
|
|
38
38
|
} = types;
|
|
39
39
|
|
|
40
40
|
const isLogicalArgument = (path) => isLogicalExpression(path.node.argument);
|
|
41
|
-
|
|
41
|
+
|
|
42
|
+
const isParens = createTypeChecker([
|
|
43
|
+
isInsideBody,
|
|
44
|
+
isInsideExpression,
|
|
45
|
+
]);
|
|
46
|
+
|
|
42
47
|
const getCallee = (fn) => (a) => fn(a.get('callee'));
|
|
43
48
|
|
|
44
49
|
const isMemberExpressionCallee = createTypeChecker([
|
package/lib/tokenize/is.js
CHANGED
|
@@ -24,6 +24,7 @@ export const isInsideBlock = (path) => isBlockStatement(path.parentPath);
|
|
|
24
24
|
export const isInsideSwitchCase = (path) => isSwitchCase(path.parentPath);
|
|
25
25
|
export const isInsideBody = ({node, parentPath}) => node === parentPath.node.body;
|
|
26
26
|
export const isInsideExpression = ({parentPath}) => isExpressionStatement(parentPath);
|
|
27
|
+
export const isInsideArray = (path) => isArrayExpression(path.parentPath);
|
|
27
28
|
|
|
28
29
|
export const isInsideTSModuleBlock = ({parentPath}) => isTSModuleBlock(parentPath);
|
|
29
30
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {types} from '@putout/babel';
|
|
1
2
|
import {createTypeChecker} from '#type-checker';
|
|
2
3
|
import {
|
|
3
4
|
isNext,
|
|
@@ -17,6 +18,8 @@ import {
|
|
|
17
18
|
import {afterIf} from './after-if.js';
|
|
18
19
|
import {beforeIf} from './before-if.js';
|
|
19
20
|
|
|
21
|
+
const {isIfStatement} = types;
|
|
22
|
+
|
|
20
23
|
const isCallInsideExpression = createTypeChecker([
|
|
21
24
|
'-: -> !ExpressionStatement',
|
|
22
25
|
'+: node.expression -> CallExpression',
|
|
@@ -27,23 +30,22 @@ const isNextToAssignmentCall = createTypeChecker([
|
|
|
27
30
|
['+', getNext(isCallInsideExpression)],
|
|
28
31
|
]);
|
|
29
32
|
|
|
30
|
-
const isNextStatementWithBlockComment = createTypeChecker([
|
|
31
|
-
'-: node.expression -> !CallExpression',
|
|
32
|
-
'-: node.expression.arguments.0 -> !CallExpression',
|
|
33
|
-
'+: node.trailingComments.0 -> CommentBlock',
|
|
34
|
-
]);
|
|
35
|
-
|
|
36
33
|
const isBreaklineAfter = createTypeChecker([
|
|
37
34
|
['-: -> !', hasTrailingComment],
|
|
38
35
|
['-: -> !', isLast],
|
|
39
36
|
['+', isCoupleLines],
|
|
40
37
|
]);
|
|
41
38
|
|
|
42
|
-
const
|
|
43
|
-
.
|
|
44
|
-
.
|
|
39
|
+
const isNextStatementWithBlockComment = createTypeChecker([
|
|
40
|
+
'-: node.expression -> !CallExpression',
|
|
41
|
+
'-: node.expression.arguments.0 -> !CallExpression',
|
|
42
|
+
'+: node.trailingComments.0 -> CommentBlock',
|
|
43
|
+
]);
|
|
45
44
|
|
|
46
|
-
const isBreakline = createTypeChecker([
|
|
45
|
+
const isBreakline = createTypeChecker([
|
|
46
|
+
isNewlineBetweenSiblings,
|
|
47
|
+
getNext(isIfStatement),
|
|
48
|
+
]);
|
|
47
49
|
|
|
48
50
|
const isIndent = createTypeChecker([
|
|
49
51
|
noTrailingComment,
|
|
@@ -57,15 +59,15 @@ export const isIndentAfter = createTypeChecker([
|
|
|
57
59
|
]);
|
|
58
60
|
|
|
59
61
|
export const ExpressionStatement = {
|
|
62
|
+
printLeadingCommentLine,
|
|
63
|
+
printLeadingCommentBlock,
|
|
60
64
|
beforeIf,
|
|
61
65
|
before(path, {indent}) {
|
|
62
66
|
indent();
|
|
63
67
|
},
|
|
64
68
|
print(path, {print, maybe, store}) {
|
|
65
|
-
const insideReturn = isInsideReturn(path);
|
|
66
|
-
|
|
67
69
|
print('__expression');
|
|
68
|
-
maybe.print(!
|
|
70
|
+
maybe.print(!isInsideReturn(path), ';');
|
|
69
71
|
|
|
70
72
|
if (!isNext(path))
|
|
71
73
|
return;
|
|
@@ -88,5 +90,3 @@ export const ExpressionStatement = {
|
|
|
88
90
|
maybe.markAfter(store(), path);
|
|
89
91
|
},
|
|
90
92
|
};
|
|
91
|
-
ExpressionStatement.printLeadingCommentLine = printLeadingCommentLine;
|
|
92
|
-
ExpressionStatement.printLeadingCommentBlock = printLeadingCommentBlock;
|
package/package.json
CHANGED