DanielXMoore / Civet

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

Ampersand bugs #1231

Closed edemaine closed 1 month ago

edemaine commented 1 month ago

if/then

e.children = e.children.map
  if & is e.block then block else &
// ↓↓↓
e.children = e.children.map(($) =>
  $ === e.block ? block : ($1) => $1
);

I expected this to be a single function, but each & gets treated as its own function wrapper. By contrast, ?: works fine:

e.children = e.children.map(($) =>
  $ === e.block ? block : $
);

Assignment

The docs say that we don't lift beyond an assignment, but I find this not to be the case:

f = & + 1
// ↓↓↓
($) => (f = $ + 1);
bbrk24 commented 1 month ago

I ran into the first one the other day, but in a slightly different way so I didn't file an issue about it:

arr.map
  if &.x
    foo
  else if &.y
    bar
  else
    baz
arr.map(($) =>
  $.x
    ? foo
    : ($1) => {
        if ($1.y) {
          return bar;
        } else {
          return baz;
        }
      }
);