machty / emblem-brunch

Emblem.js for Brunch.io
7 stars 13 forks source link

Block helpers break minified output #3

Closed lapluviosilla closed 11 years ago

lapluviosilla commented 11 years ago

Not sure if this is a emblem-brunch or emblem bug.

I have an emblem template with the following snippet:

if profile_pic_url
  img src=profile_pic_url
else
  "No profile pic"

If the application is compiled as usual with brunch build the output works just fine. However, if I compile with brunch build --minify then the output breaks. I get the following error in the browser: Uncaught SyntaxError: Unexpected token in templates.js

Also, if I remove the if blocks, the rest of the emblem template works fine.

I compared the two builds and found the following difference:

Non-Minified

stack1 = helpers['if'].call(depth0, depth0.profile_pic_url, {
    hash: {},
    inverse: self.program(7, program7, data),
    fn: self.program(5, program5, data),
    data: data
});

Minified

stack1 = helpers[ =if].call(depth0, depth0.profile_pic_url, {
    hash: {},
    inverse: self.program(7, program7, data),
    fn: self.program(5, program5, data),
    data: data
});

The helpers[ =if] is what is breaking, as =if is not a valid js statement/token.

machty commented 11 years ago

Well, the error message you're getting is strange, but the immediate problem i see is the syntax. The "No profile pic" isn't valid Emblem syntax. Try changing it to this and see what happens:

if profile_pic_url
  img src=profile_pic_url
else
  | No profile pic
lapluviosilla commented 11 years ago

Sorry, I put an old example. Regardless, even without the else I get the same error. Also, just if true or = if true by themselves causes it to blow up.

Here's what I'm actually doing:

if profile_pic_url
  img src=profile_pic_url
else
  i.img-polaroid.icon-user
machty commented 11 years ago

The "if true" blowup makes sense -- I never implemented boolean literals since their use case seems kind of thin, though I'll open an issue for that in emblem.js since it might surprise some people.

Can you post a gist of the full template you're trying to compile? fwiw I think this is an emblem bug if it is one, not an emblem-brunch thing, but let's make sure.

lapluviosilla commented 11 years ago

By blowup I mean, it gives exactly the same error on runtime.

https://gist.github.com/lapluviosilla/5049982

lapluviosilla commented 11 years ago

Oh, and copy and paste error, the browser error is actually: Uncaught SyntaxError: Unexpected token if

machty commented 11 years ago

Can you see if you're still getting this error since #2 has been merged? I bumped the npm package version to 0.1.1

lapluviosilla commented 11 years ago

I believe this was fixed. Thank you.