1 |
|
2 | export namespace builders {
|
3 | type DocCommand =
|
4 | | Align
|
5 | | BreakParent
|
6 | | Cursor
|
7 | | Fill
|
8 | | Group
|
9 | | IfBreak
|
10 | | Indent
|
11 | | IndentIfBreak
|
12 | | Label
|
13 | | Line
|
14 | | LineSuffix
|
15 | | LineSuffixBoundary
|
16 | | Trim;
|
17 | type Doc = string | Doc[] | DocCommand;
|
18 |
|
19 | interface Align {
|
20 | type: "align";
|
21 | contents: Doc;
|
22 | n: number | string | { type: "root" };
|
23 | }
|
24 |
|
25 | interface BreakParent {
|
26 | type: "break-parent";
|
27 | }
|
28 |
|
29 | interface Cursor {
|
30 | type: "cursor";
|
31 | placeholder: symbol;
|
32 | }
|
33 |
|
34 | interface Fill {
|
35 | type: "fill";
|
36 | parts: Doc[];
|
37 | }
|
38 |
|
39 | interface Group {
|
40 | type: "group";
|
41 | contents: Doc;
|
42 | break: boolean;
|
43 | expandedStates: Doc[];
|
44 | }
|
45 |
|
46 | interface HardlineWithoutBreakParent extends Line {
|
47 | hard: true;
|
48 | }
|
49 |
|
50 | interface IfBreak {
|
51 | type: "if-break";
|
52 | breakContents: Doc;
|
53 | flatContents: Doc;
|
54 | }
|
55 |
|
56 | interface Indent {
|
57 | type: "indent";
|
58 | contents: Doc;
|
59 | }
|
60 |
|
61 | interface IndentIfBreak {
|
62 | type: "indent-if-break";
|
63 | }
|
64 |
|
65 | interface Label {
|
66 | type: "label";
|
67 | }
|
68 |
|
69 | interface Line {
|
70 | type: "line";
|
71 | soft?: boolean | undefined;
|
72 | hard?: boolean | undefined;
|
73 | literal?: boolean | undefined;
|
74 | }
|
75 |
|
76 | interface LineSuffix {
|
77 | type: "line-suffix";
|
78 | contents: Doc;
|
79 | }
|
80 |
|
81 | interface LineSuffixBoundary {
|
82 | type: "line-suffix-boundary";
|
83 | }
|
84 |
|
85 | interface LiterallineWithoutBreakParent extends Line {
|
86 | hard: true;
|
87 | literal: true;
|
88 | }
|
89 |
|
90 | type LiteralLine = [LiterallineWithoutBreakParent, BreakParent];
|
91 |
|
92 | interface Softline extends Line {
|
93 | soft: true;
|
94 | }
|
95 |
|
96 | type Hardline = [HardlineWithoutBreakParent, BreakParent];
|
97 |
|
98 | interface Trim {
|
99 | type: "trim";
|
100 | }
|
101 |
|
102 | interface GroupOptions {
|
103 | shouldBreak?: boolean | undefined;
|
104 | id?: symbol | undefined;
|
105 | }
|
106 |
|
107 | function addAlignmentToDoc(doc: Doc, size: number, tabWidth: number): Doc;
|
108 |
|
109 |
|
110 | function align(widthOrString: Align["n"], doc: Doc): Align;
|
111 |
|
112 |
|
113 | const breakParent: BreakParent;
|
114 |
|
115 |
|
116 | function conditionalGroup(alternatives: Doc[], options?: GroupOptions): Group;
|
117 |
|
118 |
|
119 | function dedent(doc: Doc): Align;
|
120 |
|
121 |
|
122 | function dedentToRoot(doc: Doc): Align;
|
123 |
|
124 |
|
125 | function fill(docs: Doc[]): Fill;
|
126 |
|
127 |
|
128 | function group(doc: Doc, opts?: GroupOptions): Group;
|
129 |
|
130 |
|
131 | const hardline: Hardline;
|
132 |
|
133 |
|
134 | const hardlineWithoutBreakParent: HardlineWithoutBreakParent;
|
135 |
|
136 |
|
137 | function ifBreak(
|
138 | ifBreak: Doc,
|
139 | noBreak?: Doc,
|
140 | options?: { groupId?: symbol | undefined }
|
141 | ): IfBreak;
|
142 |
|
143 |
|
144 | function indent(doc: Doc): Indent;
|
145 |
|
146 |
|
147 | function indentIfBreak(
|
148 | doc: Doc,
|
149 | opts: { groupId: symbol; negate?: boolean | undefined }
|
150 | ): IndentIfBreak;
|
151 |
|
152 |
|
153 | function join(sep: Doc, docs: Doc[]): Doc[];
|
154 |
|
155 |
|
156 | function label(label: any | undefined, contents: Doc): Doc;
|
157 |
|
158 |
|
159 | const line: Line;
|
160 |
|
161 |
|
162 | function lineSuffix(suffix: Doc): LineSuffix;
|
163 |
|
164 |
|
165 | const lineSuffixBoundary: LineSuffixBoundary;
|
166 |
|
167 |
|
168 | const literalline: LiteralLine;
|
169 |
|
170 |
|
171 | const literallineWithoutBreakParent: LiterallineWithoutBreakParent;
|
172 |
|
173 |
|
174 | function markAsRoot(doc: Doc): Align;
|
175 |
|
176 |
|
177 | const softline: Softline;
|
178 |
|
179 |
|
180 | const trim: Trim;
|
181 |
|
182 |
|
183 | const cursor: Cursor;
|
184 | }
|
185 |
|
186 | export namespace printer {
|
187 | function printDocToString(
|
188 | doc: builders.Doc,
|
189 | options: Options
|
190 | ): {
|
191 | formatted: string;
|
192 | cursorNodeStart?: number | undefined;
|
193 | cursorNodeText?: string | undefined;
|
194 | };
|
195 | interface Options {
|
196 | |
197 |
|
198 |
|
199 |
|
200 | printWidth: number;
|
201 | |
202 |
|
203 |
|
204 |
|
205 | tabWidth: number;
|
206 | |
207 |
|
208 |
|
209 |
|
210 | useTabs?: boolean;
|
211 | parentParser?: string | undefined;
|
212 | __embeddedInHtml?: boolean | undefined;
|
213 | }
|
214 | }
|
215 |
|
216 | export namespace utils {
|
217 | function willBreak(doc: builders.Doc): boolean;
|
218 | function traverseDoc(
|
219 | doc: builders.Doc,
|
220 | onEnter?: (doc: builders.Doc) => void | boolean,
|
221 | onExit?: (doc: builders.Doc) => void,
|
222 | shouldTraverseConditionalGroups?: boolean
|
223 | ): void;
|
224 | function findInDoc<T = builders.Doc>(
|
225 | doc: builders.Doc,
|
226 | callback: (doc: builders.Doc) => T,
|
227 | defaultValue: T
|
228 | ): T;
|
229 | function mapDoc<T = builders.Doc>(
|
230 | doc: builders.Doc,
|
231 | callback: (doc: builders.Doc) => T
|
232 | ): T;
|
233 | function removeLines(doc: builders.Doc): builders.Doc;
|
234 | function stripTrailingHardline(doc: builders.Doc): builders.Doc;
|
235 | function replaceEndOfLine(
|
236 | doc: builders.Doc,
|
237 | replacement?: builders.Doc
|
238 | ): builders.Doc;
|
239 | function canBreak(doc: builders.Doc): boolean;
|
240 | }
|