-
-
Notifications
You must be signed in to change notification settings - Fork 476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛 Quotes within quotes of Formatter IR isn't escaped #1056
Comments
@ematipico |
|
The bug is around how the formatter IR is stringified in the playground regardless of what the inputted code is. I think this will be somewhere in the playground packages, so you can start by bundling that and looking at how the WASM libraries run the actual Rust code. I went along that a bit and found the biome/crates/biome_wasm/src/lib.rs Line 98 in 75dacbb
|
@Yash-Singh1 biome/crates/biome_formatter/src/lib.rs Lines 1062 to 1132 in 75dacbb
|
Hi @Yash-Singh1 , apologies for let you stranded with this PR. The issue isn't related to the playground, it's related to our internal formatter. First, head to Inside How to debug it? Use the playground and inspect the CST. You will notice that it's a
It's possible that we aren't handling string literals correctly. |
Also, the expected result should be the same as prettier, so use prettier's IR as solution |
@ematipico I am very sorry, but I would like someone else to tackle this problem 🙏 |
@ematipico (sorry for pinging, this is not urgent) I have taken a look at the issue, and if there seems to be a solution I would like to try to implement it. First of all, I think this would be a reasonable testcase to try to make pass: await "a";
await 'a';
await "'a'";
await '"a"';
f("a");
f('a');
f("'a'");
f('"a"'); There are two issues as you have mentioned:
The second issue should be (I'm not sure) easier to solve, but the first issue isn't. I have taken a look at the code and since the code formats correctly, I believe that the issue lies in the trait implementation of biome/crates/biome_formatter/src/format_element/document.rs Lines 237 to 256 in 7897935
It seems that we are adding I am not so sure what we can do in order to fix this problem. Some potential solutions I can think of are
Please kindly advise if there are any ideas, or feel free to take over the implementation. |
Thank you @southball for looking into this. This is indeed a tricky issue, and you did a great job to narrow down the culprit! Between the two solutions, my gut tells me to attempt the second solution, mostly because adding a new element to the IR might have more side-effects (memory, performance, etc.). |
Thank you! I may have time to implement this at the end of this month / at the beginning of next month, so if anyone wants to send a PR please feel free to do so! Otherwise I will send a PR as soon as I can get to it! |
I'd like to give this a shot. Thanks @southball for the writeup! |
Environment information
What happened?
Expected result
Expected result is either the double quotes surrounding
"a"
are escaped:Or single quotes used for enclosing quotes instead:
Code of Conduct
The text was updated successfully, but these errors were encountered: