wing icon indicating copy to clipboard operation
wing copied to clipboard

can't set a dynamic json key

Open eladcon opened this issue 1 year ago • 6 comments

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.

eladcon avatar Mar 12 '24 16:03 eladcon

Hi! Can anyone help me get started with this issue?

le-incroyable1-dev avatar Mar 14 '24 10:03 le-incroyable1-dev

@revitalbarletz 👆

ekeren avatar Mar 15 '24 16:03 ekeren

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.

Chriscbr avatar Mar 15 '24 19:03 Chriscbr

@le-incroyable1-dev let us know if you need further help!

revitalbarletz avatar Mar 19 '24 11:03 revitalbarletz

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 :)

le-incroyable1-dev avatar Mar 19 '24 11:03 le-incroyable1-dev

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!

github-actions[bot] avatar Aug 05 '24 06:08 github-actions[bot]