Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

block params as number? #1199

Closed
stevenvachon opened this issue Mar 13, 2016 · 5 comments
Closed

block params as number? #1199

stevenvachon opened this issue Mar 13, 2016 · 5 comments

Comments

@stevenvachon
Copy link

{{#path 1 2 3 as |4|}} text {{4}} {{/path}}

Should we not throw an error if the first char in the variable name is not a letter?:

{{#path 1 2 3 as |a4|}} text {{a4}} {{/path}}
@kpdecker
Copy link
Collaborator

There has never been a requirement that we follow javascript id patterns, so {{4}} is just fine in the language. What is the argument for changing this?

@stevenvachon
Copy link
Author

It conflicts with {{4}} which is already supported by handlebars as a number literal.

@kpdecker
Copy link
Collaborator

I don't believe this to be the case from my test compilation, it resolves
the value (or helper) "4". Can you put together a fiddle showing the
opposite if you are seeing different behavior?
On Wed, Mar 16, 2016 at 10:15 AM Steven Vachon [email protected]
wrote:

It conflicts with {{4}} which is already supported by handlebars as a
number literal.


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#1199 (comment)

@stevenvachon
Copy link
Author

It conflicts semantically and doesn't work as might be expected; no actual error. Because of this, it should probably throw when being parsed.

console.log( require("handlebars").compile("{{#each list as |value 4|}} {{value}} {{4}} {{/each}}")({list:[0]}) )

…produces 0 0.

An example of something similar that does throw a parse error:

{{#each list as ||}} {{/each}}

@kpdecker
Copy link
Collaborator

This is operating as expected, {{4}} is resolving the second block parameter. Without the block parameter it would resolve to context['4'] so both behaviors are consistent. There is some level of oddity as numbers are treated as literals in any other position, but I'm not willing to break a use case that has been around for this long because someone chooses a bad variable name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants