feat!: Consolidate Metadata Transformation Options into descriptorFields#208
feat!: Consolidate Metadata Transformation Options into descriptorFields#208timofei-iatsenko wants to merge 4 commits intomainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #208 +/- ##
==========================================
+ Coverage 93.01% 93.24% +0.22%
==========================================
Files 8 8
Lines 1531 1583 +52
==========================================
+ Hits 1424 1476 +52
Misses 107 107
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
03ca76e to
0fdcc91
Compare
There was a problem hiding this comment.
Pull request overview
This PR introduces a new descriptorFields option to control which message-descriptor properties (e.g., message, context, comment) are preserved during SWC macro transformation, replacing the previous boolean stripNonEssentialFields behavior and aligning with the related Babel change.
Changes:
- Add
DescriptorFieldsenum and replacestrip_non_essential_fieldswithdescriptor_fieldsacross config parsing and runtime options (withautoenv-based defaults). - Update macro transforms to conditionally emit
message,context, andcommentbased ondescriptor_fields. - Update docs, tests, and SWC snapshot fixtures to cover the new configuration modes (
id-only,message, etc.).
Reviewed changes
Copilot reviewed 12 out of 16 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/options.rs |
Introduces DescriptorFields, updates config parsing/defaulting, and replaces the old boolean option. |
src/lib.rs |
Updates JSX macro transform to conditionally include descriptor fields and exports DescriptorFields. |
src/js_macro_folder.rs |
Updates JS macro transforms (t, defineMessage, etc.) to respect descriptor_fields for message/context/comment. |
README.md |
Documents descriptorFields behavior and supported values. |
tests/jsx.rs |
Adjusts tests to use descriptor_fields and adds coverage for "message" mode. |
tests/jsx_icu.rs |
Adjusts tests to use descriptor_fields and adds coverage for "message" mode with ICU JSX. |
tests/js_t.rs |
Adjusts tests to use descriptor_fields and adds coverage for "message" mode. |
tests/js_define_message.rs |
Adjusts tests to use descriptor_fields and adds coverage for "message" mode. |
tests/__swc_snapshots__/... |
Updates/adds snapshots reflecting new field-preservation behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if self.ctx.options.descriptor_fields.should_keep_context() { | ||
| if let Some(context_attr) = context_attr { | ||
| let context_attr_val = get_jsx_attr_value_as_string(context_attr).unwrap(); | ||
|
|
There was a problem hiding this comment.
get_jsx_attr_value_as_string(context_attr) can return None for non-literal/unsupported context values (e.g. {expr}), and the current .unwrap() will panic and crash the transform. Please handle the Option safely (e.g., only emit the context prop when a supported literal value is present, otherwise skip or emit a structured diagnostic via HANDLER).
Related PR in Babel version: lingui/js-lingui#2513
Related issue: lingui/js-lingui#2511