-
Notifications
You must be signed in to change notification settings - Fork 378
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
fix: JSX attribute parsing issue when using double quotes #1226
Conversation
Quoted JSX attributes use XML-style escapes instead of JavaScript-style escapes.
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/lingui-js/js-lingui/4b45GDoiHUkZoH333z3nYLrhfk66 |
Codecov Report
@@ Coverage Diff @@
## main #1226 +/- ##
==========================================
+ Coverage 81.66% 81.69% +0.03%
==========================================
Files 56 56
Lines 1767 1770 +3
Branches 490 491 +1
==========================================
+ Hits 1443 1446 +3
Misses 194 194
Partials 130 130
Continue to review full report at Codecov.
|
@semoal Note that I've been testing this out on a fairly big project and haven't identified any issues. |
Let me know if I can help fixing the Vercel CI error. |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
// Quoted JSX attributes use XML-style escapes instead of JavaScript-style escapes. | ||
// This means that <Trans id="Say \"hi\"!" /> is invalid, but <Trans id={"Say \"hi\"!"} /> is valid. | ||
|
||
// We could consider removing this condition and always wrap in a jsxExpressionContainer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing the conditional here seems safe – I've done this in a larger codebase.
Let me know if we should remove the conditional here (a lot of the tests would need to be updated).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@semoal Let me know if we should remove the conditional here (a lot of the tests would need to be updated).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will that imply a breaking change? Sorry but I don't get why we should update the tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will not introduce a breaking change, but as all id and and message attribute will now be wrapped in an expression, then all the tests would need to be updated.
So instead of <Trans id="test" />
it would be <Trans id={"test"} />
. Again not breaking change.
Keeping the conditional might be a fine tradeoff, then we only wrap the attributes in an expression in case there is a "
in them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should remove the conditional here to handle additional corner cases. This was done in #1234
Super cool, thanks for the contribution mate |
This was the least intrusive way I could come up with by wrapping the relevant
jsxAttribute
string literal value in ajsxExpressionContainer
.This is currently done conditionally in case the message includes a double quote. Note that I believe this could safely be done unconditionally, but it requires updating a lot of tests. I happily do this if we like the suggested solution.
This has been tested out on a fairly big codebase.