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

Property indexers not working as intended? #16

Closed
julealgon opened this issue Dec 8, 2020 · 3 comments
Closed

Property indexers not working as intended? #16

julealgon opened this issue Dec 8, 2020 · 3 comments

Comments

@julealgon
Copy link

While attempting to access a specific property on my template, the following syntax does not appear to be working as documented:

{ {value: @p[propName]} }

When running the application, the Value property is not emitted in the final log.

However, these work:

  • { {value: @p['propName']} }
  • { {value: @p.propName} }

The documentation mentions that anything that is a valid identifier can be used directly, and "non-identifiers" can be single quoted. propName is a valid identifier, however it is not working without the single quotes for me.

In particular, there is this section in the readme:

Data type Description Examples
Object A mapping of string keys to values; keys that are valid identifiers do not need to be quoted {a: 1, 'b c': 2, d}

If a is a "valid identifier that doesn't need to be escaped", then my property name shouldn't need to as well.

I suspect either the documentation is a bit misleading when talking about these indexers, or there is a bug in the interpreter that is not allowing this to work as it should.

@nblumhardt
Copy link
Member

Thanks for the note. The README might not be clear enough, here - the comment's only referring to keys in object literals, not the indexer notation. I'll run back over it and try to clarify with some more examples. The intention is for object literals to work pretty closely to how they do in JavaScript.

@julealgon
Copy link
Author

So are you saying that @p[propName] not working is working as intended, and that it is always supposed to have the ' around the name?

There are places in the README that mention a @p[a] syntax, which would also be kinda misleading then.

Can you elaborate?

@nblumhardt
Copy link
Member

Yes, that's the case. The a[b] example in the README was intended to show that b could be any expression - 'b', 0, some other property b, etc., but I can see it's confusing - just pushed an update 👍

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