@@ -50,6 +50,7 @@ const {
5050 dedent,
5151 ifBreak,
5252 hardline,
53+ hardlineWithoutBreakParent,
5354 softline,
5455 literalline,
5556 align,
@@ -741,6 +742,32 @@ function shouldInlineLogicalExpression(node) {
741742// precedence level and the AST is structured based on precedence
742743// level, things are naturally broken up correctly, i.e. `&&` is
743744// broken before `+`.
745+ function printPipeChain ( path , print , trailingSemicolon = false ) {
746+ const elements = [ ] ;
747+
748+ function collect ( ) {
749+ const { node } = path ;
750+ if ( node . kind === "bin" && node . type === "|>" ) {
751+ elements . push ( path . call ( print , "left" ) ) ;
752+ path . call ( collect , "right" ) ;
753+ } else {
754+ elements . push ( print ( ) ) ;
755+ }
756+ }
757+
758+ collect ( ) ;
759+
760+ const [ first , ...rest ] = elements ;
761+ const semicolon = trailingSemicolon
762+ ? ifBreak ( [ hardlineWithoutBreakParent , ";" ] , ";" )
763+ : "" ;
764+ return group ( [
765+ first ,
766+ indent ( rest . flatMap ( ( el ) => [ line , "|> " , el ] ) ) ,
767+ semicolon ,
768+ ] ) ;
769+ }
770+
744771function printBinaryExpression (
745772 path ,
746773 print ,
@@ -1219,7 +1246,7 @@ function printClass(path, options, print) {
12191246 declaration . push ( "abstract " ) ;
12201247 }
12211248
1222- if ( node . isReadonly ) {
1249+ if ( node . isReadonly && ! isAnonymousClass ) {
12231250 declaration . push ( "readonly " ) ;
12241251 }
12251252
@@ -1524,6 +1551,7 @@ function printAssignmentRight(
15241551
15251552 const canBreak =
15261553 ( pureRightNode . kind === "bin" &&
1554+ pureRightNode . type !== "|>" &&
15271555 ! shouldInlineLogicalExpression ( pureRightNode ) ) ||
15281556 ( pureRightNode . kind === "retif" &&
15291557 ( ( ! pureRightNode . trueExpr &&
@@ -2094,7 +2122,7 @@ function printNode(path, options, print) {
20942122 ( ) => printAttrs ( path , options , print , { inline : true } ) ,
20952123 "what"
20962124 ) ,
2097- "class" ,
2125+ node . what . isReadonly ? "readonly class" : "class" ,
20982126 node . arguments . length > 0
20992127 ? [ " " , printArgumentsList ( path , options , print ) ]
21002128 : "" ,
@@ -2487,6 +2515,16 @@ function printNode(path, options, print) {
24872515 ) ;
24882516 }
24892517 case "bin" : {
2518+ if ( node . type === "|>" ) {
2519+ const { parent, grandparent } = path ;
2520+ const isStatementLevel =
2521+ parent . kind === "expressionstatement" ||
2522+ ( parent . kind === "assign" &&
2523+ grandparent &&
2524+ grandparent . kind === "expressionstatement" ) ;
2525+ return printPipeChain ( path , print , isStatementLevel ) ;
2526+ }
2527+
24902528 const { parent, grandparent : parentParent } = path ;
24912529 const isInsideParenthesis =
24922530 node !== parent . body &&
0 commit comments