sweet-js/sweet-core

Problems returning arrow function expression from macro

gabejohnson opened this issue · 2 comments

While trying to implement a let expression macro I realized I wasn't taking this into account. So instead of using a IIFE I tried using an arrow function:

let (a = 1, b = a) { a + b }

// expected
((a_100 = 1, b_101 = a_100) => { return a_100 + b_101; })()

// actual
  Error: unexpected syntax
=> { return [object Object] }

Here's a minimal repro:

syntax let = function (ctx) {
  let params = ctx.next().value;
  return #`(${params} => 1)`;};

let (a)

Something wrong converting a RawDelimiter to a paren list? Maybe with the template replacement code?

btw, using an arrow will handle this but now you've broken break/continue and return :( Maybe just use a block with a normal let:

let (a = 1, b = a) { a + b }
// -->
{
let a = 1, b = a;
a + b;
}

It's an "expression", so I don't need break/continue. I'm thinking of using it from a ternary:

const foo = n => n > 5 ? n : let(a = 1, b = n) { ...; a + b; };

Was just messing around. I am breaking return though. Can we have shift/reset? 😛