1 | import { Doc } from './';
|
2 |
|
3 |
|
4 |
|
5 | export namespace builders {
|
6 | type Doc =
|
7 | | string
|
8 | | Align
|
9 | | BreakParent
|
10 | | Concat
|
11 | | Fill
|
12 | | Group
|
13 | | IfBreak
|
14 | | Indent
|
15 | | Line
|
16 | | LineSuffix
|
17 | | LineSuffixBoundary
|
18 | | Trim
|
19 | | Cursor;
|
20 |
|
21 | interface Align {
|
22 | type: 'align';
|
23 | contents: Doc;
|
24 | n: number | string | { type: 'root' };
|
25 | }
|
26 |
|
27 | interface BreakParent {
|
28 | type: 'break-parent';
|
29 | }
|
30 |
|
31 | interface Concat {
|
32 | type: 'concat';
|
33 | parts: Doc[];
|
34 | }
|
35 |
|
36 | interface Fill {
|
37 | type: 'fill';
|
38 | parts: Doc[];
|
39 | }
|
40 |
|
41 | interface Group {
|
42 | type: 'group';
|
43 | contents: Doc;
|
44 | break: boolean;
|
45 | expandedStates: Doc[];
|
46 | }
|
47 |
|
48 | interface IfBreak {
|
49 | type: 'if-break';
|
50 | breakContents: Doc;
|
51 | flatContents: Doc;
|
52 | }
|
53 |
|
54 | interface Indent {
|
55 | type: 'indent';
|
56 | contents: Doc;
|
57 | }
|
58 |
|
59 | interface Line {
|
60 | type: 'line';
|
61 | soft?: boolean;
|
62 | hard?: boolean;
|
63 | literal?: boolean;
|
64 | }
|
65 |
|
66 | interface LineSuffix {
|
67 | type: 'line-suffix';
|
68 | contents: Doc;
|
69 | }
|
70 |
|
71 | interface LineSuffixBoundary {
|
72 | type: 'line-suffix-boundary';
|
73 | }
|
74 |
|
75 | interface Trim {
|
76 | type: 'trim';
|
77 | }
|
78 |
|
79 | interface Cursor {
|
80 | type: 'cursor';
|
81 | placeholder: symbol;
|
82 | }
|
83 |
|
84 | function addAlignmentToDoc(doc: Doc, size: number, tabWidth: number): Doc;
|
85 | function align(n: Align['n'], contents: Doc): Align;
|
86 | const breakParent: BreakParent;
|
87 | function concat(contents: Doc[]): Concat;
|
88 | function conditionalGroup(states: Doc[], opts?: { shouldBreak: boolean }): Group;
|
89 | function dedent(contents: Doc): Align;
|
90 | function dedentToRoot(contents: Doc): Align;
|
91 | function fill(parts: Doc[]): Fill;
|
92 | function group(contents: Doc, opts?: { shouldBreak: boolean }): Group;
|
93 | const hardline: Concat;
|
94 | function ifBreak(breakContents: Doc, flatContents: Doc): IfBreak;
|
95 | function indent(contents: Doc): Indent;
|
96 | function join(separator: Doc, parts: Doc[]): Concat;
|
97 | const line: Line;
|
98 | function lineSuffix(contents: Doc): LineSuffix;
|
99 | const lineSuffixBoundary: LineSuffixBoundary;
|
100 | const literalline: Concat;
|
101 | function markAsRoot(contents: Doc): Align;
|
102 | const softline: Line;
|
103 | const trim: Trim;
|
104 | const cursor: Cursor;
|
105 | }
|
106 |
|
107 | export namespace debug {
|
108 | function printDocToDebug(doc: Doc): string;
|
109 | }
|
110 |
|
111 | export namespace printer {
|
112 | function printDocToString(
|
113 | doc: Doc,
|
114 | options: Options,
|
115 | ): {
|
116 | formatted: string;
|
117 | cursorNodeStart?: number;
|
118 | cursorNodeText?: string;
|
119 | };
|
120 | interface Options {
|
121 | |
122 |
|
123 |
|
124 |
|
125 | printWidth: number;
|
126 | |
127 |
|
128 |
|
129 |
|
130 | tabWidth: number;
|
131 | |
132 |
|
133 |
|
134 |
|
135 | useTabs: boolean;
|
136 | }
|
137 | }
|
138 |
|
139 | export namespace utils {
|
140 | function isEmpty(doc: Doc): boolean;
|
141 | function isLineNext(doc: Doc): boolean;
|
142 | function willBreak(doc: Doc): boolean;
|
143 | function traverseDoc(
|
144 | doc: Doc,
|
145 | onEnter?: (doc: Doc) => void | boolean,
|
146 | onExit?: (doc: Doc) => void,
|
147 | shouldTraverseConditionalGroups?: boolean,
|
148 | ): void;
|
149 | function mapDoc<T>(doc: Doc, callback: (doc: Doc) => T): T;
|
150 | function propagateBreaks(doc: Doc): void;
|
151 | function removeLines(doc: Doc): Doc;
|
152 | function stripTrailingHardline(doc: Doc): Doc;
|
153 | }
|