sweet-core icon indicating copy to clipboard operation
sweet-core copied to clipboard

TypeError: decl.init.body is undefined

Open jeandrek opened this issue 8 years ago • 2 comments

When I enter

syntax fn = function (ctx) {
  let args = ctx.next().value;
  let body = ctx.next().value; 
  return #`function ${args} ${body}`;
}

(fn () {
  return 42;
})

into the online editor I get this error message:

TypeError: decl.init.body is undefined

I'm using Firefox Nightly version 49.0a1.

jeandrek avatar May 04 '16 02:05 jeandrek

Your example is actually not a valid program because of ASI. It's actually getting parsed as:

syntax fn = function (ctx) {
  let args = ctx.next().value;
  let body = ctx.next().value; 
  return #`function ${args} ${body}`;
}(fn () {
  return 42;
})

Add the necessary ; and everything works out fine (yet another nail in the coffin of semicolon-less style).

That said I'm leaving this issue open so we can make a better error message. It should be able to say the { at (fn () { ... is invalid.

disnet avatar May 07 '16 03:05 disnet

Oh, thanks.

jeandrek avatar May 07 '16 04:05 jeandrek