goja icon indicating copy to clipboard operation
goja copied to clipboard

parse error: Malformed arrow function parameter list

Open ttttmr opened this issue 3 years ago • 2 comments

I tried to parse this file https://pkg.go.dev/static/frontend/unit/main/main.js, but failed, here is the snippet of the error

import (
	"fmt"

	goja "github.com/dop251/goja/parser"
)

func main() {
	b := `
fetch("/play/compile", {
  method: "POST",
  body: JSON.stringify({
    body: (e = this.inputEl) == null ? void 0 : e.value,
    version: 2,
  }),
})
  .then((t) => t.json())
  .then(async ({ Events: t, Errors: i }) => {
    this.setOutputText(i || "");
    for (let s of t || [])
      this.setOutputText(s.Message),
        await new Promise((r) => setTimeout(r, s.Delay / 1e6));
  })
  .catch((t) => {
    this.setErrorText(t);
  });
`
	_, err := goja.ParseFile(nil, "", b, 0, goja.WithDisableSourceMaps)
	if err != nil {
		fmt.Printf("err: %v", err)
	}

}

https://go.dev/play/p/NV8ldPsDb_a

ttttmr avatar Sep 27 '22 03:09 ttttmr

HI @ttttmr, Goja does not have support for async/await, yet.

As such it seems like while goja is parsing async ({Events: t, Errors: i}) => it fails with the not so great Malformed arrow function parameter list instead of telling you async is not supported.

Removing both async and await from your example code compiles and runs without errors. Although it will need more changes to make it do what the original code was trying to do.

mstoykov avatar Sep 27 '22 07:09 mstoykov

@mstoykov Is there any reason why is it not implemented? Or is it just about priorities?

pedronasser avatar Sep 30 '22 15:09 pedronasser

Hi @pedronasser sorry for the slow response.

The project is mostly (like 99.9+%) been done by @dop251 solo. It also does take quite a lot of work on features of this kind (as I have also tried to implement some stuff) and it is a bit of hobby project.

So I guess the answer is "it is about priorities". The current things that are blocking it are #436 and hopefully when that is done async/await will be worked on.

For the record goja does support a lot of features from ecmascript revisions past es2017 - the one async/await was added in. And usually when features are added they get added with all the functionality from the latest specification.

As I keep telling people on my team the practical things missing from goja at this point are generators, async/await and ESM support. Note that there are others pieces not implemented, but I at least never hear anyone complaining about them missing :shrug:

mstoykov avatar Nov 16 '22 08:11 mstoykov

See #460

dop251 avatar Dec 23 '22 10:12 dop251