Add support for a # prefix in path segments#14
Merged
Conversation
To support embedding Handlebars templates in JavaScript classes and
allow them to access private fields, we need property paths segments
to be able to begin with a `#`.
Since `#` is already a control character (i.e. `{{#block}}`), this
parser change implements a new path separator (`.#`), which effectively
creates a new kind of identifier (a path segment identifier) that has
the same lexical structure as any other identifier, but can only appear
at the beginning of a path segment. The `.` and `#` characters count as
a single token, and cannot be separated by whitespace.
This syntax is intended to be used in embedding environments that are
careful about lexical scope, and require an explicit `this.` prefix to
access the current instance.
In classic Handlebars environments, you would expect `{{this.#foo}}` to
be equivalent to `{{#foo}}`, but that would parse as a block start,
which would be ambiguous.
In the future, it would be helpful to explicitly document the strict
lexical subset of Handlebars, but this change doesn't *break* classic
Handlebars. In classic Handlebars contexts, this change would make
`this.#foo` work without needing `this[#foo]`. It might seem surprising
that `#foo` isn't equivalent to `this.#foo`, but it's not a breaking
change and the reason that `{{#foo}}` can't parse as a path is fairly
obvious.
Member
|
I think you have to either add the changes in |
Contributor
Author
|
@jaylinski Thanks! |
Contributor
Author
|
@jaylinski I updated the infrastructure to use |
Member
|
Looks good! There is no stable release of |
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
To support embedding Handlebars templates in JavaScript classes and allow them to access private fields, we need property paths segments to be able to begin with a
#.Since
#is already a control character (i.e.{{#block}}), this parser change implements a new path separator (.#), which effectively creates a new kind of identifier (a path segment identifier) that has the same lexical structure as any other identifier, but can only appear at the beginning of a path segment. The.and#characters count as a single token, and cannot be separated by whitespace.This syntax is intended to be used in embedding environments that are careful about lexical scope, and require an explicit
this.prefix to access the current instance.In classic Handlebars environments, you would expect
{{this.#foo}}to be equivalent to{{#foo}}, but that would parse as a block start, which would be ambiguous.In the future, it would be helpful to explicitly document the strict lexical subset of Handlebars, but this change doesn't break classic Handlebars. In classic Handlebars contexts, this change would make
this.#foowork without needingthis.[#foo]. It might seem surprising that#fooisn't equivalent tothis.#foo, but it's not a breaking change and the reason that{{#foo}}can't parse as a path is fairly obvious.