| ... | ... | @@ -441,13 +441,18 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { |
| 441 | 441 | const dot_token = name_token - 1; |
| 442 | 442 | |
| 443 | 443 | try ais.pushIndent(.field_access); |
| 444 | | try renderExpression(r, lhs, .none); |
| 445 | 444 | |
| 446 | | // Allow a line break between the lhs and the dot if the lhs and rhs |
| 447 | | // are on different lines. |
| 448 | 445 | const lhs_last_token = tree.lastToken(lhs); |
| 449 | 446 | const same_line = tree.tokensOnSameLine(lhs_last_token, name_token); |
| 450 | | if (!same_line and !hasComment(tree, lhs_last_token, dot_token)) try ais.insertNewline(); |
| 447 | // Keeping a space after the number ensures it will not turn into a decimal number |
| 448 | // (e.g. "0xF .A"). |
| 449 | const number_space: Space = if (tree.tokenTag(lhs_last_token) == .number_literal and same_line) .space else .none; |
| 450 | try renderExpression(r, lhs, number_space); |
| 451 | |
| 452 | // Allow a line break between the lhs and the dot if the lhs and rhs |
| 453 | // are on different lines. |
| 454 | if (!same_line and !hasComment(tree, lhs_last_token, dot_token)) |
| 455 | try ais.insertNewline(); |
| 451 | 456 | |
| 452 | 457 | try renderToken(r, dot_token, .none); |
| 453 | 458 | |