@@ -199,7 +199,11 @@ const formatter = conf => {
199
199
let left_pp = prettyPrint ( left , indent )
200
200
let right_pp = prettyPrint ( right , indent )
201
201
if ( isBinaryExpression ( left ) && precedency [ left . operator ] < op_precedency ) left_pp = "(" + left_pp + ")"
202
- if ( isBinaryExpression ( right ) && precedency [ right . operator ] < op_precedency || ( right . operator !== ".." && precedency [ right . operator ] == op_precedency ) ) right_pp = "(" + right_pp + ")"
202
+ if (
203
+ ( isBinaryExpression ( right ) && precedency [ right . operator ] < op_precedency ) ||
204
+ ( right . operator !== ".." && precedency [ right . operator ] == op_precedency )
205
+ )
206
+ right_pp = "(" + right_pp + ")"
203
207
return left_pp + " " + operator + " " + right_pp
204
208
}
205
209
@@ -322,7 +326,7 @@ const formatter = conf => {
322
326
const end_spacing = inline ? " " : indentationNewline ( indent - 1 )
323
327
let table = [ end_spacing + "}" ]
324
328
let beforeField = false
325
- for ( let i = length - 1 ; i > - 1 ; i -- ) {
329
+ for ( let i = length - 1 ; i > - 1 ; i -- ) {
326
330
const field = node . fields [ i ]
327
331
const isField = field . type !== "Comment"
328
332
if ( beforeField && isField ) {
@@ -389,15 +393,23 @@ const formatter = conf => {
389
393
return nodeFormatter ( node , indent )
390
394
}
391
395
396
+ return prettyPrint
397
+ }
398
+
399
+ const astFormatter = conf => ( ast , indent ) => formatter ( conf ) ( ast , indent === undefined ? 0 : indent )
400
+
401
+ const textFormatter = conf => {
402
+ const formatter = astFormatter ( conf )
392
403
return text => {
393
404
const ast = parse ( text )
394
405
fixRanges ( ast )
395
406
insertComments ( ast )
396
- return prettyPrint ( ast , 0 )
407
+ return formatter ( ast )
397
408
}
398
409
}
399
410
400
411
module . exports = {
401
- formatChunk : formatter ( ) ,
402
- formatter
412
+ ast : { fixRanges, insertComments, formatter : astFormatter } ,
413
+ formatChunk : textFormatter ( ) ,
414
+ formatter : textFormatter
403
415
}
0 commit comments