Skip to content

feat!: Consolidate Metadata Transformation Options into descriptorFields#208

Open
timofei-iatsenko wants to merge 4 commits intomainfrom
feat/descriptorFields
Open

feat!: Consolidate Metadata Transformation Options into descriptorFields#208
timofei-iatsenko wants to merge 4 commits intomainfrom
feat/descriptorFields

Conversation

@timofei-iatsenko
Copy link
Copy Markdown
Collaborator

Related PR in Babel version: lingui/js-lingui#2513

Related issue: lingui/js-lingui#2511

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.24%. Comparing base (0e5c2d9) to head (535d47f).

Additional details and impacted files

Impacted file tree graph

@@            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              
Flag Coverage Δ
unittests 93.24% <100.00%> (+0.22%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/js_macro_folder.rs 97.89% <100.00%> (ø)
src/lib.rs 92.05% <100.00%> (+0.07%) ⬆️
src/options.rs 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@timofei-iatsenko timofei-iatsenko changed the base branch from next to main April 14, 2026 13:17
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 DescriptorFields enum and replace strip_non_essential_fields with descriptor_fields across config parsing and runtime options (with auto env-based defaults).
  • Update macro transforms to conditionally emit message, context, and comment based on descriptor_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.

Comment on lines +169 to 172
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();

Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants