Only allow indented else if there's a newline after the else

This commit is contained in:
Joshua Warner 2024-12-02 07:42:24 -08:00
parent 48c941d542
commit cabe67f88d
No known key found for this signature in database
GPG key ID: 89AD497003F93FDD
5 changed files with 94 additions and 1 deletions

View file

@ -2762,8 +2762,12 @@ fn if_expr_help<'a>(options: ExprParseOptions) -> impl Parser<'a, Expr<'a>, EIf<
}
};
let has_newline_next = require_newline_or_eof(EExpr::IndentEnd)
.parse(arena, state_final_else.clone(), min_indent)
.is_ok();
let else_indent = state_final_else.line_indent();
let indented_else = else_indent > if_indent;
let indented_else = else_indent > if_indent && has_newline_next;
let min_indent = if !indented_else {
else_indent + 1