yesodweb/shakespeare

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

Opened this issue · 2 comments

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.

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...

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