add support for numeric keys in map literal#934
Closed
chrisirhc wants to merge 1 commit intoHubSpot:masterfrom
Closed
add support for numeric keys in map literal#934chrisirhc wants to merge 1 commit intoHubSpot:masterfrom
chrisirhc wants to merge 1 commit intoHubSpot:masterfrom
Conversation
Contributor
Author
|
This is a draft, and I intend to make some changes. |
9137419 to
6e2f675
Compare
This is a hack to support numeric keys declared in map literals. Most of such usages typically use the keys as if they were strings, so this hack is likely safe. A hack is used as opposed to overhauling all maps used since full support would require overhauling all maps types to `Map<Object, Object>` which seems overkill.
6e2f675 to
29bdbd6
Compare
Contributor
Author
|
Ok, changes are done and ready for review. |
samukce
reviewed
Jan 10, 2023
| key = entryKey.eval(bindings, context).toString(); | ||
| } else { | ||
| throw new TemplateStateException( | ||
| "Dict key must be a string or identifier, was: " + entryKey |
Contributor
There was a problem hiding this comment.
It's good to update the error message here to include the number as a key possibility, what do you think?
Suggested change
| "Dict key must be a string or identifier, was: " + entryKey | |
| "Dict key must be a string, or identifier, or a number, was: " + entryKey |
Contributor
|
superseded by #1152 |
Contributor
Author
|
Ah apologies I forgot to get back to this. |
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.
Hit this use case in our usage of jinja.
Putting up a PR in case there's interest in merging this functionality.
This is a hack to support numeric keys declared in map literals.
Most of such usages typically use the keys as if they were strings, so this
hack is likely safe.
A hack is used as opposed to overhauling all maps used since full support would
require overhauling all maps types to
Map<Object, Object>which seemsoverkill.
Behavior is also undefined for when defining same key of same number value and number value
{'1': '1', 1: '2'}.