@putout/printer 18.20.1 → 18.21.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,15 @@
|
|
|
1
|
+
2026.06.22, v18.21.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 9cf1ba3f @putout/printer: export TS types
|
|
5
|
+
- 7c045046 @putout/printer: export TS types
|
|
6
|
+
|
|
7
|
+
2026.06.20, v18.20.2
|
|
8
|
+
|
|
9
|
+
feature:
|
|
10
|
+
- 69369b4e @putout/printer: isNextSimpleWithLeadingComments: type checker
|
|
11
|
+
- b970af9c @putout/printer: binary-expression: newline
|
|
12
|
+
|
|
1
13
|
2026.06.20, v18.20.1
|
|
2
14
|
|
|
3
15
|
feature:
|
package/README.md
CHANGED
|
@@ -120,7 +120,6 @@ print(ast, {
|
|
|
120
120
|
},
|
|
121
121
|
},
|
|
122
122
|
});
|
|
123
|
-
|
|
124
123
|
// returns
|
|
125
124
|
'const {a/* [hello world] */= 5} = b;\n';
|
|
126
125
|
```
|
|
@@ -185,10 +184,6 @@ Options used to configure logic of output, similar to ESLint rules:
|
|
|
185
184
|
- ✅ `maxPropertiesInOneLine` - count of `ObjectProperties` in one line.
|
|
186
185
|
- ✅ `maxPropertiesLengthInOneLine` - maximum length of `Object Property`, when violated splits event if `maxPropertiesInOneLine` satisfies;
|
|
187
186
|
- ✅ `roundBraces` to output braces or not
|
|
188
|
-
- `arrow`: In a single argument arrow function expressions enabled: `(a) => {}`, disabled: `a => {}`;
|
|
189
|
-
- `sequence`: In sequence expressions: enabled: `for(let e of l) (a(), b())`, disabled: `for(let e of l) a(), b()`;
|
|
190
|
-
- `assign`: In assignment expressions: enabled: `(e.o=w(e.o)`, disabled: `e.o=w(e.o)`;
|
|
191
|
-
- `new`: In new expressions: enabled: `new Date()`, disabled: `new Date`;
|
|
192
187
|
|
|
193
188
|
## Visitors API
|
|
194
189
|
|
package/lib/printer.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {type Node} from '@putout/babel';
|
|
2
2
|
|
|
3
|
-
interface Format {
|
|
3
|
+
export interface Format {
|
|
4
4
|
indent: string;
|
|
5
5
|
newline: string;
|
|
6
6
|
space: string;
|
|
@@ -8,7 +8,7 @@ interface Format {
|
|
|
8
8
|
quote: string;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
interface Semantics {
|
|
11
|
+
export interface Semantics {
|
|
12
12
|
roundBraces: boolean;
|
|
13
13
|
comments: boolean;
|
|
14
14
|
maxPropertiesInOneLine: number;
|
|
@@ -18,46 +18,46 @@ interface Semantics {
|
|
|
18
18
|
trailingComma: boolean;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
type Print = (input: string |
|
|
22
|
-
type Indent = () => void;
|
|
23
|
-
type Traverse = (input:
|
|
24
|
-
type MaybeCondition = (condition: boolean) => void;
|
|
21
|
+
export type Print = (input: string | Node) => void;
|
|
22
|
+
export type Indent = () => void;
|
|
23
|
+
export type Traverse = (input: Node) => void;
|
|
24
|
+
export type MaybeCondition = (condition: boolean) => void;
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
export type MaybeIndent = {
|
|
27
|
+
(condition: boolean): void;
|
|
27
28
|
inc: MaybeCondition;
|
|
28
29
|
dec: MaybeCondition;
|
|
29
30
|
};
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
type
|
|
33
|
-
type MaybeTraverse = (condition: boolean, input: types.Node) => void;
|
|
32
|
+
export type MaybePrint = (condition: boolean, input: string | Node) => void;
|
|
33
|
+
export type MaybeTraverse = (condition: boolean, input: Node) => void;
|
|
34
34
|
|
|
35
|
-
interface Maybe {
|
|
35
|
+
export interface Maybe {
|
|
36
36
|
print: MaybePrint;
|
|
37
37
|
traverse: MaybeTraverse;
|
|
38
38
|
indent: typeof MaybeIndent;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
interface Printer {
|
|
41
|
+
export interface Printer {
|
|
42
42
|
print: Print;
|
|
43
43
|
maybe: Maybe;
|
|
44
44
|
indent: Indent;
|
|
45
45
|
traverse: Traverse;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
type Visitor = (path:
|
|
48
|
+
export type Visitor = (path: Node, printer: Printer, semantics?: Semantics) => void;
|
|
49
49
|
|
|
50
|
-
interface Visitors {
|
|
50
|
+
export interface Visitors {
|
|
51
51
|
[name: string]: Visitor;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
interface Options {
|
|
54
|
+
export interface Options {
|
|
55
55
|
format?: Format;
|
|
56
56
|
semantics?: Semantics;
|
|
57
57
|
visitors?: Visitors;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
export function print(ast:
|
|
60
|
+
export function print(ast: Node, options?: Options): string;
|
|
61
61
|
|
|
62
|
-
declare function maybeVisitor(plugin: Visitor, path:
|
|
63
|
-
export const visitors
|
|
62
|
+
export declare function maybeVisitor(plugin: Visitor, path: Node, printer: Print, semantics: Semantics): void;
|
|
63
|
+
export const visitors: Visitors;
|
|
@@ -15,12 +15,8 @@ import {
|
|
|
15
15
|
const {
|
|
16
16
|
isCallExpression,
|
|
17
17
|
isAssignmentExpression,
|
|
18
|
-
isArrayExpression,
|
|
19
|
-
isStringLiteral,
|
|
20
|
-
isTemplateLiteral,
|
|
21
18
|
isExpressionStatement,
|
|
22
19
|
isStatement,
|
|
23
|
-
isBooleanLiteral,
|
|
24
20
|
} = types;
|
|
25
21
|
|
|
26
22
|
function isNotLastOrParentLast(path) {
|
|
@@ -76,42 +72,6 @@ const isNextCallWithLeadingComments = (path) => {
|
|
|
76
72
|
return isCallExpression(nextExpression);
|
|
77
73
|
};
|
|
78
74
|
|
|
79
|
-
function isNextWithLeadingComments(path) {
|
|
80
|
-
const next = path.getNextSibling();
|
|
81
|
-
const {expression} = path.node;
|
|
82
|
-
|
|
83
|
-
if (!path.node.trailingComments)
|
|
84
|
-
return true;
|
|
85
|
-
|
|
86
|
-
if (isAssignmentExpression(expression))
|
|
87
|
-
return true;
|
|
88
|
-
|
|
89
|
-
return !exists(next);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export function isNextSimpleWithLeadingComments(path) {
|
|
93
|
-
const next = path.getNextSibling();
|
|
94
|
-
|
|
95
|
-
if (!hasTrailingComment(path))
|
|
96
|
-
return false;
|
|
97
|
-
|
|
98
|
-
if (!isExpressionStatement(next))
|
|
99
|
-
return false;
|
|
100
|
-
|
|
101
|
-
const {expression} = next.node;
|
|
102
|
-
|
|
103
|
-
if (isBooleanLiteral(expression))
|
|
104
|
-
return true;
|
|
105
|
-
|
|
106
|
-
if (isStringLiteral(expression))
|
|
107
|
-
return true;
|
|
108
|
-
|
|
109
|
-
if (isTemplateLiteral(expression))
|
|
110
|
-
return true;
|
|
111
|
-
|
|
112
|
-
return isArrayExpression(next.node.expression);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
75
|
function isAssignWithTrailingComments(path) {
|
|
116
76
|
const {expression} = path.node;
|
|
117
77
|
|
|
@@ -125,10 +85,8 @@ export const afterIf = createTypeChecker([
|
|
|
125
85
|
['-', isInsideReturn],
|
|
126
86
|
['-', isTopParentLast],
|
|
127
87
|
['+', isNextCallWithLeadingComments],
|
|
128
|
-
['-: -> !', isNextWithLeadingComments],
|
|
129
88
|
['+', isAssignWithTrailingComments],
|
|
130
89
|
['-: node.trailingComments.length -> +'],
|
|
131
90
|
['+', satisfyAfter],
|
|
132
91
|
['+', isBeforeElse],
|
|
133
92
|
]);
|
|
134
|
-
|
|
@@ -12,10 +12,7 @@ import {
|
|
|
12
12
|
printLeadingCommentLine,
|
|
13
13
|
printLeadingCommentBlock,
|
|
14
14
|
} from './comments.js';
|
|
15
|
-
import {
|
|
16
|
-
afterIf,
|
|
17
|
-
isNextSimpleWithLeadingComments,
|
|
18
|
-
} from './after-if.js';
|
|
15
|
+
import {afterIf} from './after-if.js';
|
|
19
16
|
import {beforeIf} from './before-if.js';
|
|
20
17
|
|
|
21
18
|
const {isIfStatement} = types;
|
|
@@ -82,3 +79,12 @@ export const ExpressionStatement = {
|
|
|
82
79
|
maybe.markAfter(store(), path);
|
|
83
80
|
},
|
|
84
81
|
};
|
|
82
|
+
|
|
83
|
+
export const isNextSimpleWithLeadingComments = callWithNext(createTypeChecker([
|
|
84
|
+
['-: -> !', hasLeadingComment],
|
|
85
|
+
['-: -> !ExpressionStatement'],
|
|
86
|
+
['+: node.expression -> TemplateLiteral'],
|
|
87
|
+
['+: node.expression -> ArrayExpression'],
|
|
88
|
+
['+: node.expression -> BooleanLiteral'],
|
|
89
|
+
['+: node.expression -> StringLiteral'],
|
|
90
|
+
]));
|
package/package.json
CHANGED