machty / emblem.js

Emblem.js - Ember-friendly, indented syntax alternative for Handlebars.js
http://emblemjs.com
MIT License
1.04k stars 81 forks source link

Can't use $ as an attribute name #279

Closed bnetter closed 5 years ago

bnetter commented 8 years ago

I sometimes prefix my attributes with $, as $amount. Then, when using it on my templates, I get the following error:

emblem/parser.js:7689
      throw peg$buildException(null, peg$maxFailExpected, peg$maxFailPos);
      ^
SyntaxError: Expected _4BeginStatement or end of input but "\uEFEF" found.

Example code:

div= transaction.$amount
bnetter commented 7 years ago

Same when you use this as attributes.

component-name amount=transaction.$amount
kketch commented 7 years ago

@bnetter it seems that attributes with the "$" character are incompatible with the cases you mention here. But you can work around it today with this syntax in your first case:

div #{transaction.$amount}

And in the second case:

component-name amount=(get transaction '$amount')

Or (which I think will only work for strings):

component-name amount='#{transaction.$amount}'
tmosmant commented 7 years ago

Thanks @kketch, first syntax works (we were aware of this one but it's a proper workaround), second one won't work unless you're running Ember 2.1.0 for the get keyword (sadly that's not our case yet) and the last one simply transmits a #{transaction.$amount} string. Still, except than maybe write a get helper before going 2.1.0, we're unable to prefix our properties with $.

kketch commented 7 years ago

@tmosmant I'll look soon for a fix, it looks like a parser bug

thec0keman commented 7 years ago

I'm not 100% sure, but I suspect this may be a good place to start.