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 | cursorNodeStart?: number | undefined;
|
196 | cursorNodeText?: string | undefined;
|
197 | };
|
198 | interface Options {
|
199 | |
200 |
|
201 |
|
202 |
|
203 | printWidth: number;
|
204 | |
205 |
|
206 |
|
207 |
|
208 | tabWidth: number;
|
209 | |
210 |
|
211 |
|
212 |
|
213 | useTabs?: boolean;
|
214 | parentParser?: string | undefined;
|
215 | __embeddedInHtml?: boolean | undefined;
|
216 | }
|
217 | }
|
218 |
|
219 | export namespace utils {
|
220 | function willBreak(doc: builders.Doc): boolean;
|
221 | function traverseDoc(
|
222 | doc: builders.Doc,
|
223 | onEnter?: (doc: builders.Doc) => void | boolean,
|
224 | onExit?: (doc: builders.Doc) => void,
|
225 | shouldTraverseConditionalGroups?: boolean,
|
226 | ): void;
|
227 | function findInDoc<T = builders.Doc>(
|
228 | doc: builders.Doc,
|
229 | callback: (doc: builders.Doc) => T,
|
230 | defaultValue: T,
|
231 | ): T;
|
232 | function mapDoc<T = builders.Doc>(
|
233 | doc: builders.Doc,
|
234 | callback: (doc: builders.Doc) => T,
|
235 | ): T;
|
236 | function removeLines(doc: builders.Doc): builders.Doc;
|
237 | function stripTrailingHardline(doc: builders.Doc): builders.Doc;
|
238 | function replaceEndOfLine(
|
239 | doc: builders.Doc,
|
240 | replacement?: builders.Doc,
|
241 | ): builders.Doc;
|
242 | function canBreak(doc: builders.Doc): boolean;
|
243 | }
|