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