doc.d.ts
3.63 KB
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
import { Doc } from './';
// https://github.com/prettier/prettier/blob/master/src/doc/index.js
export namespace builders {
type Doc =
| string
| Align
| BreakParent
| Concat
| Fill
| Group
| IfBreak
| Indent
| Line
| LineSuffix
| LineSuffixBoundary
| Trim
| Cursor;
interface Align {
type: 'align';
contents: Doc;
n: number | string | { type: 'root' };
}
interface BreakParent {
type: 'break-parent';
}
interface Concat {
type: 'concat';
parts: Doc[];
}
interface Fill {
type: 'fill';
parts: Doc[];
}
interface Group {
type: 'group';
contents: Doc;
break: boolean;
expandedStates: Doc[];
}
interface IfBreak {
type: 'if-break';
breakContents: Doc;
flatContents: Doc;
}
interface Indent {
type: 'indent';
contents: Doc;
}
interface Line {
type: 'line';
soft?: boolean;
hard?: boolean;
literal?: boolean;
}
interface LineSuffix {
type: 'line-suffix';
contents: Doc;
}
interface LineSuffixBoundary {
type: 'line-suffix-boundary';
}
interface Trim {
type: 'trim';
}
interface Cursor {
type: 'cursor';
placeholder: symbol;
}
function addAlignmentToDoc(doc: Doc, size: number, tabWidth: number): Doc;
function align(n: Align['n'], contents: Doc): Align;
const breakParent: BreakParent;
function concat(contents: Doc[]): Concat;
function conditionalGroup(states: Doc[], opts?: { shouldBreak: boolean }): Group;
function dedent(contents: Doc): Align;
function dedentToRoot(contents: Doc): Align;
function fill(parts: Doc[]): Fill;
function group(contents: Doc, opts?: { shouldBreak: boolean }): Group;
const hardline: Concat;
function ifBreak(breakContents: Doc, flatContents: Doc): IfBreak;
function indent(contents: Doc): Indent;
function join(separator: Doc, parts: Doc[]): Concat;
const line: Line;
function lineSuffix(contents: Doc): LineSuffix;
const lineSuffixBoundary: LineSuffixBoundary;
const literalline: Concat;
function markAsRoot(contents: Doc): Align;
const softline: Line;
const trim: Trim;
const cursor: Cursor;
}
export namespace debug {
function printDocToDebug(doc: Doc): string;
}
export namespace printer {
function printDocToString(
doc: Doc,
options: Options,
): {
formatted: string;
cursorNodeStart?: number;
cursorNodeText?: string;
};
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;
}
}
export namespace utils {
function isEmpty(doc: Doc): boolean;
function isLineNext(doc: Doc): boolean;
function willBreak(doc: Doc): boolean;
function traverseDoc(
doc: Doc,
onEnter?: (doc: Doc) => void | boolean,
onExit?: (doc: Doc) => void,
shouldTraverseConditionalGroups?: boolean,
): void;
function mapDoc<T>(doc: Doc, callback: (doc: Doc) => T): T;
function propagateBreaks(doc: Doc): void;
function removeLines(doc: Doc): Doc;
function stripTrailingHardline(doc: Doc): Doc;
}