winglang / wing

A programming language for the cloud ☁️ A unified programming model, combining infrastructure and runtime code into one language ⚡
https://winglang.io
Other
5.07k stars 198 forks source link

can't set a dynamic json key #5917

Open eladcon opened 8 months ago

eladcon commented 8 months ago

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

le-incroyable1-dev commented 8 months ago

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

ekeren commented 8 months ago

@revitalbarletz 👆

Chriscbr commented 8 months ago

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.

revitalbarletz commented 8 months ago

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

le-incroyable1-dev commented 8 months ago

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

github-actions[bot] commented 4 months ago

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!