feat(vue-extractor): add reactivity transform support for props destructuring#2414
Conversation
|
@mister-what is attempting to deploy a commit to the Crowdin Team on Vercel. A member of the Team first needs to authorize it. |
|
Hey, you also can mitigate that by using a named placeholder, which is going to be recommended way when we finish with V6 release const { selectedCount } = defineProps({ selectedCount: Number });
// {selectedCount} shortcut to {selectedCount: selectedCount}, which is {label: value}
const text = plural({selectedCount}, {
one: "# item",
other: "# items",
}); |
|
@mister-what we currently have a code-freeze for the This fix would be included in upcoming v6 release. |
a22b982 to
a9f3764
Compare
|
@timofei-iatsenko alright 👍 I changed the target branch to |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
3ac8bd5 to
4dab83c
Compare
|
I fixed the failing snapshot tests and annotated some type-only imports. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## next #2414 +/- ##
===========================================
+ Coverage 76.66% 88.75% +12.08%
===========================================
Files 81 118 +37
Lines 2083 3300 +1217
Branches 532 975 +443
===========================================
+ Hits 1597 2929 +1332
+ Misses 375 333 -42
+ Partials 111 38 -73 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Thanks for the contribution! Is this something only relevant to the experimental (dependency tree) extractor and not the regular extractor? It introduces the framework-specific configuration in the // lingui.config.js
import { createVueExtractor } from '@lingui/extractor-vue'
export default {
extractors: [
createVueExtractor({
reactivityTransform: false,
// ...
})
]
}Although it's more complicated, it's more future-proof as we can easily add more options if needed. @mister-what @timofei-iatsenko what do you think? |
|
This would be the best option - but a breaking change for existing users. If that would be implemented for the vue extractor the same should be done for babel extractor for consistency. So instead of object both vue and babel would export a factory function from the package similarly to formatters. |
|
I could make it non breaking by exposing the factory and exposing the configured extractor. The latter could then be deprecated. |
…tractor-reactivity-transform
…ateVueExtractor`
timofei-iatsenko
left a comment
There was a problem hiding this comment.
LGTM for me. Added one minor suggestion.
Co-authored-by: Timofei Iatsenko <1586852+timofei-iatsenko@users.noreply.github.com>
|
@mister-what please update the PR description for consistency. Thanks! |
|
@andrii-bodnar description is updated 👍 |
Description
This PR adds support for Vue's Reactivity Transform in the
vue-extractorto fix message ID mismatches when using destructured props fromdefineProps().Problem
When using destructured props with Lingui macros like
plural()orselect(), the extractor and the runtime macro see different code representations:Extractor sees:
plural(selectedCount, ...)and generates message ID for{selectedCount, plural, ...}Runtime macro sees:
plural(__props.selectedCount, ...)and generates message ID for{0, plural, ...}This mismatch causes the translations to fail at runtime.
Solution
The extractor now runs Vue’s
compileScript()when thereactivityTransformoption is enabled.This applies the same reactivity transform that Vue uses internally, so both the extractor and the runtime macro operate on identical code (i.e.
__props.xinstead of destructured bindings). As a result, message IDs are generated consistently and no longer mismatch at runtime.The feature is opt-in (
reactivityTransform: falseby default) to avoid breaking existing setups that rely on the previous behavior.To support this configuration cleanly, the extractor API was changed to a factory-based approach. A preconfigured extractor instance is still exported for backwards compatibility, but it is now marked as deprecated in favor of
createVueExtractor().Usage
Types of changes
Checklist