-
-
Notifications
You must be signed in to change notification settings - Fork 114
Expand file tree
/
Copy pathprettier-builder.ts
More file actions
68 lines (55 loc) · 1.78 KB
/
prettier-builder.ts
File metadata and controls
68 lines (55 loc) · 1.78 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
import { IToken } from "java-parser";
import { builders } from "prettier/doc";
import Doc = builders.Doc;
import * as formatComments from "./comments/format-comments.js";
const processComments = formatComments.processComments as any;
/*
* ------------------------------------------------------------------
* Wraps the Prettier builder functions to print tokens with comments
* ------------------------------------------------------------------
*/
export function concat(docs: (Doc | IToken)[]): Doc {
const concatenation = processComments(docs);
if (!Array.isArray(docs)) {
return "";
}
return concatenation;
}
export function join(sep: any, docs: (Doc | IToken)[]): Doc {
return builders.join(processComments(sep), processComments(docs));
}
export function group(docs: Doc | IToken | (Doc | IToken)[], opts?: any) {
const group = builders.group(processComments(docs), opts);
return group.contents === undefined ? "" : group;
}
export function fill(docs: (Doc | IToken)[]) {
return builders.fill(processComments(docs));
}
export function indent(doc: Doc | IToken) {
const processedDoc = processComments(doc);
if (processedDoc.length === 0) {
return "";
}
return builders.indent(processedDoc);
}
export function dedent(doc: Doc | IToken) {
const processedDoc = processComments(doc);
if (processedDoc.length === 0) {
return "";
}
return builders.dedent(processComments(doc));
}
export function ifBreak(
breakContents: Doc | IToken,
flatContents: Doc | IToken,
options?: { groupId?: symbol | undefined }
) {
return builders.ifBreak(
processComments(breakContents),
processComments(flatContents),
options
);
}
export function indentIfBreak(contents: Doc | IToken, opts?: any) {
return builders.indentIfBreak(processComments(contents), opts);
}