refactor: jsx named placeholders, reuse methods, fix readability#210
refactor: jsx named placeholders, reuse methods, fix readability#210andrii-bodnar merged 14 commits intomainfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #210 +/- ##
==========================================
+ Coverage 93.50% 94.16% +0.65%
==========================================
Files 8 8
Lines 1740 1731 -9
==========================================
+ Hits 1627 1630 +3
+ Misses 113 101 -12
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR refactors the JSX named placeholder feature implementation for readability/reuse, splits the JSX named placeholder tests into a dedicated integration test file, and updates README compatibility documentation formatting.
Changes:
- Extract JSX named placeholder tests from
tests/jsx.rsintotests/jsx_named_placeholders.rswith corresponding new snapshots. - Refactor JSX placeholder handling in
MessageBuilderto reuse new AST utility helpers (omit_jsx_attrs,is_jsx_elements_equal). - Reformat/clean up README sections (notably the SWC compatibility table formatting).
Reviewed changes
Copilot reviewed 9 out of 19 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
tests/jsx_named_placeholders.rs |
New dedicated test suite for JSX named placeholders, including new cases like string-literal JSX expression placeholders. |
tests/jsx.rs |
Removes JSX named placeholder tests now covered by the new test file. |
tests/__swc_snapshots__/tests/jsx_named_placeholders.rs/* |
Adds snapshots for the extracted/updated named placeholder test cases. |
tests/__swc_snapshots__/tests/jsx.rs/* |
Removes snapshots corresponding to the moved named placeholder tests. |
src/builder.rs |
Refactors placeholder attribute extraction and JSX element equality comparison to use shared helpers. |
src/ast_utils.rs |
Introduces helper utilities for omitting JSX attrs and comparing JSX opening elements. |
README.md |
Updates formatting/structure around configuration notes and the compatibility table. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| }, | ||
| r#" | ||
| import { Trans } from '@lingui/react/macro'; | ||
| <Trans><em _t="same" class="hello">A</em> and <em _t="same" class="hello" data-testId="bla">B</strong></Trans> |
There was a problem hiding this comment.
The JSX in this test has mismatched closing tags (<em ...>B</strong>). This likely causes the test to panic due to a TSX parse error rather than the intended “same placeholder, different attributes count” plugin validation. Fix the closing tag so the input remains valid TSX and the panic originates from the plugin logic being tested.
| <Trans><em _t="same" class="hello">A</em> and <em _t="same" class="hello" data-testId="bla">B</strong></Trans> | |
| <Trans><em _t="same" class="hello">A</em> and <em _t="same" class="hello" data-testId="bla">B</em></Trans> |
| } else { | ||
| a.attrs | ||
| .iter() | ||
| .all(|a| b.attrs.iter().any(|b| a.eq_ignore_span(b))) | ||
| } |
There was a problem hiding this comment.
is_jsx_elements_equal can return a false positive when there are duplicate attributes: the all(|a| any(|b| ...)) check doesn’t account for multiplicity (e.g. a has two identical attrs, b has one identical + one different). Consider comparing attributes as multisets (e.g. match-and-remove from a mutable copy of b.attrs, or sort+compare with eq_ignore_span) when there are no spread elements.
There was a problem hiding this comment.
current implementation is good enough as long as test passing. Could not imagine a valid case where this would be a problem.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 198 out of 200 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This PR improves readability of the added feature, reuse some existing methods etc. Also i extracted tests into separate file to split the concepts.
I updated readme, because found some outdated info there.
UPD: this PR get a bit bigger then expected
I replaced an SWC based snapshot testing framework to Insta.
I was not satisfied with the fact that snapshot has only an output code. That make a reviewing a snapshots pretty inconvinient because to understand is the snapshot generated correctly or not you need to also look into source code which generated that snapshot. Now the snapshotting framework capture:
input code + output code + macro options if they differs from defaults.
I also improved a
to_panicmacro, so it also captures error payload in snaphot. Previously it just testing the fact that transform paniced.Side changes:
I added claude.md + skill for rust + some project overview claude crunched from the codebase and swc crates.