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

Julius arrow function with curly brace body is compiled to expression even if it's not an expression #270

Open
schoettl opened this issue Oct 17, 2022 · 2 comments

Comments

@schoettl
Copy link

It looks like .julius is compiled to invalid JS in a certain situation:

When I use an arrow function which only contains one if statement, the compiler omits the curly braces of the function body. This roduces invalid JS: Uncaught SyntaxError: expected expression, got keyword 'if'

$(function() {
    $('.button').click(() => {
        if (!confirm('Really delete?'))
            return false
        //return // without this line .julius compiles this { ... } to just <expr> which doesn't compile
    })
})

compiled to:


$('.button').click(()=>if(!confirm('Wollen Sie die Reservierung wirklich stornieren?'))return false)

PS: Sorry, I never used Shakespeare alone, so I don't know how to provide a minimal example.

I can't work on this issue right now, only wanted to have it documented somewhere.

@schoettl schoettl changed the title Julius arrow function with curly brace body is compiled to expression even if it's not Julius arrow function with curly brace body is compiled to expression even if it's not an expression Oct 17, 2022
@schoettl
Copy link
Author

Oh, or maybe it's a bug in JS minifier
https://hackage.haskell.org/package/hjsmin-0.2.0.4
for which bugs should be reported here:
https://github.com/erikd/language-javascript

I use this only from a scaffolded Yesod project so I wasn't aware of internals...

@david-sledge
Copy link

Can confirm. My workaround is add a line between the open bracket and the if statement: "";

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

2 participants