can't set a dynamic json key
I tried this:
let url = "http://example.com";
let x= Json{
"{url}": "valid"
};
log("{Json.stringify(x)}");
This happened:
{"{url}":"valid"}
the key isn't set correctly to the value of url
I expected this:
No response
Is there a workaround?
No response
Anything else?
No response
Wing Version
No response
Node.js Version
No response
Platform(s)
No response
Community Notes
- Please vote by adding a 👍 reaction to the issue to help us prioritize.
- If you are interested to work on this issue, please leave a comment.
Hi! Can anyone help me get started with this issue?
@revitalbarletz 👆
Hey @le-incroyable1-dev 👋 - to get started, I recommend first checking out our contributing guide to make sure you can build Wing's CLI and test any changes you make to the code. If you run into issues, please don't hesitate to ask questions!
For this bug, the issue happens when a user creates a Json literal. At a high level, I think we need to update our compiler's representation of Json map literals (for code like Json { key: value }) so that the keys of the map are stored in the AST as expressions instead of as symbols. Here's where this data structure is defined in the compiler code:
https://github.com/winglang/wing/blob/6ebd778219190d3ccf4192af1419bd4224175074/libs/wingc/src/ast.rs#L608-L610
In parser.rs, I think we would want to update the code so that keys like foo or "foo" are parsed as plain string expressions, and keys like "hello {name}" are parsed as interpolated strings. Then, other parts of the compiler code will need to be updated to work with the new representation.
@le-incroyable1-dev let us know if you need further help!
Hi @revitalbarletz ! Thanks for checking in, I unexpectedly got caught up with somethin else but I've started looking into the issues, I'll get back to you soon :)
Hi,
This issue hasn't seen activity in 90 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!