handlebars-lang / docs

Documentation for handlebars.js and the handlebars-language
https://handlebarsjs.com
MIT License
36 stars 47 forks source link

remove wrong statement about literal statements #119

Closed nknapp closed 1 year ago

nknapp commented 1 year ago

" and ' are not allowed as literal segment. At best, they may be used as LiteralExpression as parameter for helpers, but a template like

{{'my id containing spaces'}} 

just does not parse

papasmile commented 1 year ago

Hi, All, not sure what you mean, actually... test referenced indeed have examples of non-array literals with quotes (L414,418).

I also tried in sandbox: https://handlebarsjs.com/playground.html#format=1&currentExample=%7B%22template%22%3A%22%7B%7B%5C%22cheese%20test%5C%22%7D%7D%5Cn%7B%7B'cheese%20test'%7D%7D%5Cn%7B%7B%5Bcheese%20test%5D%7D%7D%5Cn%22%2C%22partials%22%3A%5B%5D%2C%22input%22%3A%22%7B%5Cn%20%20'cheese%20test'%3A%20%5C%22wiz%5C%22%2C%5Cn%7D%5Cn%22%2C%22output%22%3A%22wiz%5Cnwiz%5Cnwiz%5Cn%22%2C%22preparationScript%22%3A%22%2F%2F%20Handlebars.registerHelper('loud'%2C%20function(string)%20%7B%5Cn%2F%2F%20%20%20%20return%20string.toUpperCase()%5Cn%2F%2F%20%7D)%3B%5Cn%22%2C%22handlebarsVersion%22%3A%224.7.7%22%7D

Perhaps you meant as a property reference? i.e. array.[0].['some key'] vs array.[0].'some key'? But that would just be incorrect JavaScript...

nknapp commented 1 year ago

Yes, I actually didn't try the statement that I wrote above :flushed:

I meant this

https://handlebarsjs.com/playground.html#format=1&currentExample=%7B%22template%22%3A%22%7B%7Bhello.%5C%22my%20world%5C%22%7D%7D%5Cn%22%2C%22partials%22%3A%5B%5D%2C%22input%22%3A%22%7B%5Cn%20%20%5C%22hello%5C%22%3A%20%7B%20%5C%22my%20world%5C%22%3A%20%5C%22good%20bye%5 C%22%20%7D%2C%5Cn%7D%5Cn%22%2C%22output%22%3A%22good%20bye%5Cn%22%2C%22preparationScript%22%3A%22%2F%2F%20Handlebars.registerHelper('loud'%2C%20function(string)%20%7B%5Cn%2F%2F%20%20%20%20return%20string.toUpperCase()%5Cn%2F%2F%20%7D)%3B%5Cn%22%2C%22handlebarsVersion%22%3A%224.7.7%22%7D

But if this works: {{ 'my id containing spaces' }} then it looks like a bug to me.

I actually came across this, when trying to write the spec. https://handlebars-ng.knappi.org/

This falls into the category: "Should probably work differently". I will add it to the list...

nknapp commented 1 year ago

closing for now, since my changes are not correct. Thanks @jaylinski and @papasmile for pointing to the tests.

Btw. I found out:

{{ 'my id containing spaces' }} is interpreted by the parser as StringLiteral. That's why it works, even though it does not as part of PathExpressions.