Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parse error: Malformed arrow function parameter list #435

Closed
ttttmr opened this issue Sep 27, 2022 · 4 comments
Closed

parse error: Malformed arrow function parameter list #435

ttttmr opened this issue Sep 27, 2022 · 4 comments

Comments

@ttttmr
Copy link

ttttmr commented Sep 27, 2022

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

@mstoykov
Copy link
Contributor

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.

@pedronasser
Copy link

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

@mstoykov
Copy link
Contributor

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 🤷

@dop251
Copy link
Owner

dop251 commented Dec 23, 2022

See #460

@dop251 dop251 closed this as completed Dec 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants