@@ -530,13 +530,14 @@ fn renderExpression(
530
530
const lbracket = tree .prevToken (range .start .firstToken ());
531
531
const dotdot = tree .nextToken (range .start .lastToken ());
532
532
533
- const spaces_around_op = range .start .id == ast .Node .Id .InfixOp or
534
- (if (range .end ) | end | end .id == ast .Node .Id .InfixOp else false );
535
- const op_space = if (spaces_around_op ) Space .Space else Space .None ;
533
+ const after_start_space_bool = nodeCausesSliceOpSpace (range .start ) or
534
+ (if (range .end ) | end | nodeCausesSliceOpSpace (end ) else false );
535
+ const after_start_space = if (after_start_space_bool ) Space .Space else Space .None ;
536
+ const after_op_space = if (range .end != null ) after_start_space else Space .None ;
536
537
537
538
try renderToken (tree , stream , lbracket , indent , start_col , Space .None ); // [
538
- try renderExpression (allocator , stream , tree , indent , start_col , range .start , op_space );
539
- try renderToken (tree , stream , dotdot , indent , start_col , op_space ); // ..
539
+ try renderExpression (allocator , stream , tree , indent , start_col , range .start , after_start_space );
540
+ try renderToken (tree , stream , dotdot , indent , start_col , after_op_space ); // ..
540
541
if (range .end ) | end | {
541
542
try renderExpression (allocator , stream , tree , indent , start_col , end , Space .None );
542
543
}
@@ -1959,3 +1960,11 @@ fn nodeIsBlock(base: &const ast.Node) bool {
1959
1960
else = > false ,
1960
1961
};
1961
1962
}
1963
+
1964
+ fn nodeCausesSliceOpSpace (base : & ast.Node ) bool {
1965
+ const infix_op = base .cast (ast .Node .InfixOp ) ?? return false ;
1966
+ return switch (infix_op .op ) {
1967
+ ast .Node .InfixOp .Op .Period = > false ,
1968
+ else = > true ,
1969
+ };
1970
+ }
0 commit comments