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