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