DanielXMoore / Civet

A TypeScript superset that favors more types and less typing
https://civet.dev
MIT License
1.36k stars 29 forks source link

Indented `if`/`unless` conditions to enable indented function calls (e.g. `(and)`) #1364

Closed edemaine closed 1 month ago

edemaine commented 1 month ago

This PR explores the proposal from https://github.com/DanielXMoore/Civet/issues/1090#issuecomment-2291837213 :

I wonder if it would work (and be unambiguous) to allow an indented condition to use (further) indented function calls:

// if/then/else
if
  (and)
    x
    y
  console.log 'yes'
else
  console.log 'no'

// postfix unless
return unless
  (and)
    x
    y

It does seem to work quite well! I think this is a natural extension of various settings where we allow indented expressions (e.g. after return or yield). It looks a little weird when you don't have an indented application, but the expression still has a clear "end" (from the line break):

if
  a + b < 10
  console.log 'small'

I'd like to propose that this fixes #1090, but that is perhaps subject to debate.