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

Immediately-invoked function expressions #286

Closed
patrickjm opened this issue May 16, 2021 · 3 comments
Closed

Immediately-invoked function expressions #286

patrickjm opened this issue May 16, 2021 · 3 comments

Comments

@patrickjm
Copy link

patrickjm commented May 16, 2021

Does Goja support these?

At the moment, this is what I'm getting:

(()=>{ printHello() })()

// ... Line 1:3 Unexpected token ) (and 2 more errors)

Expected behavior

(()=>{ printHello() })()

// ... Hello

Webpack relies heavily on these to isolate modules (unless you set output.iife: false), so it would be very useful to see them supported

@mstoykov
Copy link
Contributor

Hi @patrickjm,

Immediately invoking functions is supported, but what isn't is arrow functions.

Some people (us at k6 including) use babel to transpile our code down to what is supported by goja. We even only use the plugins for things that aren't supported ;) Note that we use babel 6.26.0, for ... reasons, but the latest versions seem to also work with goja.

We also have a template repository doing the transformation outside of k6. Which also uses webpack and babe,l which can possibly help you find which configurations will make webpack not emit arrow functions ;)

@jvatic
Copy link

jvatic commented May 16, 2021

@patrickjm As @mstoykov said, arrow functions are not supported and you may want to consider using something like babel to transpile your code first. You might consider using the goja-babel package which uses the standalone version of babel running within goja to transpile code into something you could then run within goja.

@patrickjm
Copy link
Author

Awesome, thank you both!

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

3 participants