11"use strict" ;
22import { IToken } from "java-parser" ;
3- import { doc } from "prettier" ;
4- import Doc = doc . builders . Doc ;
5- import Concat = doc . builders . Concat ;
6- import Fill = doc . builders . Fill ;
7-
8- const prettier = require ( "prettier" ) . doc . builders ;
3+ import { builders } from "prettier/doc" ;
4+ import Doc = builders . Doc ;
95
106const { processComments } = require ( "./comments/format-comments" ) ;
11-
127/*
138 * ------------------------------------------------------------------
149 * Wraps the Prettier builder functions to print tokens with comments
@@ -26,50 +21,46 @@ export function concat(docs: (Doc | IToken)[]): Doc {
2621}
2722
2823export function join ( sep : any , docs : ( Doc | IToken ) [ ] ) : Doc {
29- const concatenation = prettier . join (
30- processComments ( sep ) ,
31- processComments ( docs )
32- ) ;
33-
34- return processEmptyDocs ( concatenation ) ;
24+ return builders . join ( processComments ( sep ) , processComments ( docs ) ) ;
3525}
3626
37- export function group ( doc : Doc | IToken , opts ?: any ) {
38- const group = prettier . group ( processComments ( doc ) , opts ) ;
27+ export function group ( docs : Doc | IToken | ( Doc | IToken ) [ ] , opts ?: any ) {
28+ const group = builders . group ( processComments ( docs ) , opts ) ;
3929 return group . contents === undefined ? "" : group ;
4030}
4131
4232export function fill ( docs : ( Doc | IToken ) [ ] ) {
43- const fill = prettier . fill ( processComments ( docs ) ) ;
44-
45- return processEmptyDocs ( fill ) ;
33+ return builders . fill ( processComments ( docs ) ) ;
4634}
4735
4836export function indent ( doc : Doc | IToken ) {
49- const indentedDoc = prettier . indent ( processComments ( doc ) ) ;
50- return indentedDoc . contents . length === 0 ? "" : indentedDoc ;
37+ const processedDoc = processComments ( doc ) ;
38+ if ( processedDoc . length === 0 ) {
39+ return "" ;
40+ }
41+
42+ return builders . indent ( processedDoc ) ;
5143}
5244
5345export function dedent ( doc : Doc | IToken ) {
54- const indentedDoc = prettier . dedent ( processComments ( doc ) ) ;
55- return indentedDoc . contents . length === 0 ? "" : indentedDoc ;
46+ const processedDoc = processComments ( doc ) ;
47+ if ( processedDoc . length === 0 ) {
48+ return "" ;
49+ }
50+
51+ return builders . dedent ( processComments ( doc ) ) ;
5652}
5753
5854export function ifBreak (
5955 breakContents : Doc | IToken ,
6056 flatContents : Doc | IToken
6157) {
62- return prettier . ifBreak (
58+ return builders . ifBreak (
6359 processComments ( breakContents ) ,
6460 processComments ( flatContents )
6561 ) ;
6662}
6763
6864export function indentIfBreak ( contents : Doc | IToken , opts ?: any ) {
69- return prettier . indentIfBreak ( processComments ( contents ) , opts ) ;
65+ return builders . indentIfBreak ( processComments ( contents ) , opts ) ;
7066}
71-
72- // TODO: remove this once prettier 3.0 is released
73- const processEmptyDocs = ( doc : Fill | Concat ) : Doc => {
74- return doc . parts ?. length === 0 ? "" : doc ;
75- } ;
0 commit comments