yesodweb / shakespeare

Haml-like template files that are compile-time checked
http://www.yesodweb.com/book/shakespearean-templates
MIT License
136 stars 76 forks source link

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

Open schoettl opened 2 years ago

schoettl commented 2 years ago

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 commented 2 years ago

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 commented 7 months ago

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