dop251 / goja

ECMAScript/JavaScript engine in pure Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

parse error: Malformed arrow function parameter list

ttttmr opened this issue · comments

commented

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

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 Is there any reason why is it not implemented? Or is it just about priorities?

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 🤷