@putout/printer 18.42.0 → 18.42.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
CHANGED
package/lib/printer.d.ts
CHANGED
|
@@ -18,12 +18,9 @@ export interface Semantics {
|
|
|
18
18
|
trailingComma: boolean;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export type
|
|
22
|
-
|
|
21
|
+
export type PrinterPrint = (input: string | Node) => void;
|
|
23
22
|
export type Indent = () => void;
|
|
24
|
-
|
|
25
23
|
export type Traverse = (input: Node) => void;
|
|
26
|
-
|
|
27
24
|
export type MaybeCondition = (condition: boolean) => void;
|
|
28
25
|
|
|
29
26
|
export type MaybeIndent = {
|
|
@@ -43,7 +40,7 @@ export interface Maybe {
|
|
|
43
40
|
}
|
|
44
41
|
|
|
45
42
|
export interface Printer {
|
|
46
|
-
print:
|
|
43
|
+
print: PrinterPrint;
|
|
47
44
|
maybe: Maybe;
|
|
48
45
|
indent: Indent;
|
|
49
46
|
traverse: Traverse;
|
|
@@ -61,7 +58,8 @@ export interface Options {
|
|
|
61
58
|
visitors?: Visitors;
|
|
62
59
|
}
|
|
63
60
|
|
|
64
|
-
|
|
61
|
+
type Print = (ast: Node, options?: Options) => string;
|
|
62
|
+
export const print: Print;
|
|
65
63
|
|
|
66
|
-
export declare function maybeVisitor(plugin: Visitor, path: Node, printer:
|
|
64
|
+
export declare function maybeVisitor(plugin: Visitor, path: Node, printer: Printer, semantics: Semantics): void;
|
|
67
65
|
export const visitors: Visitors;
|
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import {createTypeChecker} from '#type-checker';
|
|
2
|
+
import {isCoupleLines} from '#is';
|
|
3
|
+
|
|
4
|
+
export const isConditionalExpressionMultiline = createTypeChecker([
|
|
5
|
+
['-: node.alternate -> ObjectExpression'],
|
|
6
|
+
['-: node.consequent -> ObjectExpression'],
|
|
7
|
+
['+', isCoupleLines],
|
|
8
|
+
]);
|
|
9
|
+
|
|
10
|
+
export const printConditionalExpressionMultiline = (path, {print, indent}) => {
|
|
2
11
|
print('__test');
|
|
3
12
|
print.space();
|
|
4
13
|
print('?');
|
|
@@ -11,3 +20,4 @@ export const ConditionalExpressionMultiline = (path, {print, indent}) => {
|
|
|
11
20
|
indent.dec();
|
|
12
21
|
print('__alternate');
|
|
13
22
|
};
|
|
23
|
+
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import {types} from '@putout/babel';
|
|
2
1
|
import {maybeParens} from '#maybe-parens';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
import {
|
|
3
|
+
isConditionalExpressionMultiline,
|
|
4
|
+
printConditionalExpressionMultiline,
|
|
5
|
+
} from './conditional-expression-multiline.js';
|
|
7
6
|
|
|
8
7
|
export const ConditionalExpression = maybeParens((path, printer) => {
|
|
9
8
|
const {print} = printer;
|
|
10
|
-
const {alternate} = path.node;
|
|
11
9
|
|
|
12
|
-
if (
|
|
13
|
-
|
|
10
|
+
if (isConditionalExpressionMultiline(path)) {
|
|
11
|
+
printConditionalExpressionMultiline(path, printer);
|
|
14
12
|
return;
|
|
15
13
|
}
|
|
16
14
|
|
|
@@ -24,4 +22,3 @@ export const ConditionalExpression = maybeParens((path, printer) => {
|
|
|
24
22
|
print.space();
|
|
25
23
|
print('__alternate');
|
|
26
24
|
});
|
|
27
|
-
|
package/package.json
CHANGED