Skip to content

refactor: labeled expressions implementation#244

Draft
timofei-iatsenko wants to merge 6 commits into
mainfrom
refactor/labeled-expressions
Draft

refactor: labeled expressions implementation#244
timofei-iatsenko wants to merge 6 commits into
mainfrom
refactor/labeled-expressions

Conversation

@timofei-iatsenko

@timofei-iatsenko timofei-iatsenko commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

This is my attempt on fixing #241 and #239

This is more systematic refactoring rather then ad-hoc fix. The refactoring make closer SWC implementation to a babel's one, so they not diverge.

Previously indexes for expression were allocated during processing a Message Phase in a message builder, in babel version those indexes where assigned during AST scanning phase, so it produced a diffrent result described in #241

Additionally ph macro was not processed uniformly. It was processed in some places but were skipped in other, for example:

<Plural value={ph({count: getCount()})} / > 

With this refactoring, ph support is added everywhere and processed uniformly.

Other changes:

  1. I extracted all tests related to labeled expressions feature into separate file. It's easier to see all cases and work on the feature this way
  2. I changed internal structures,
  • TransformCtx (formerly MacroCtx) — global per-file context holding macro imports, options, directives, and runtime identifiers.
  • MacroCtx<'a> — short-lived, created fresh for each macro invocation. Borrows &'a mut TransformCtx and owns its own expression index counter starting at 0.
  • Free tokenization functions: tokenize_tpl, tokenize_expr_to_arg, try_tokenize_call_expr_as_choice_cmp, try_tokenize_expr, and get_choice_cases_from_obj are now free functions taking &mut MacroCtx explicitly, making the data flow clear.

@codecov

codecov Bot commented Jun 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.83095% with 32 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.81%. Comparing base (4a68dd1) to head (7ff152f).

Files with missing lines Patch % Lines
crates/lingui_macro/src/macro_utils.rs 90.82% 20 Missing ⚠️
crates/lingui_macro/src/jsx_visitor.rs 83.33% 12 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #244      +/-   ##
==========================================
- Coverage   95.06%   94.81%   -0.26%     
==========================================
  Files           9        9              
  Lines        2251     2334      +83     
==========================================
+ Hits         2140     2213      +73     
- Misses        111      121      +10     
Flag Coverage Δ
unittests 94.81% <90.83%> (-0.26%) ⬇️

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

Files with missing lines Coverage Δ
crates/lingui_macro/src/ast_utils.rs 90.80% <ø> (-0.41%) ⬇️
crates/lingui_macro/src/builder.rs 99.15% <100.00%> (+0.17%) ⬆️
crates/lingui_macro/src/js_macro_folder.rs 98.42% <100.00%> (+0.06%) ⬆️
crates/lingui_macro/src/lib.rs 91.09% <100.00%> (+0.01%) ⬆️
crates/lingui_macro/src/jsx_visitor.rs 86.63% <83.33%> (-1.81%) ⬇️
crates/lingui_macro/src/macro_utils.rs 91.90% <90.82%> (+2.69%) ⬆️
🚀 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 title Refactor/labeled expressions refactor: labeled expressions Jun 26, 2026
@timofei-iatsenko timofei-iatsenko changed the title refactor: labeled expressions refactor: labeled expressions implementation Jun 26, 2026
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.

1 participant