Skip to content

Commit

Permalink
fix: useLingui when t is not used (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
timofei-iatsenko authored Aug 15, 2024
1 parent 05dcef1 commit 4cd7fa7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ impl LinguiMacroFolder {
})
.is_some()
{
self.ctx.should_add_uselingui_import = true;

if let Pat::Object(obj_pat) = declarator.name {
let mut new_props: Vec<ObjectPatProp> =
obj_pat.props.into_iter().map(|prop| {
Expand All @@ -168,7 +170,6 @@ impl LinguiMacroFolder {
to: underscore_ident.clone(),
});

self.ctx.should_add_uselingui_import = true;
ctx.runtime_idents.i18n = new_i18n_ident.clone();

return Some(ObjectPatProp::KeyValue(
Expand Down
21 changes: 21 additions & 0 deletions src/tests/use_lingui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,27 @@ function MyComponent() {
"#
);

to!(
work_when_t_is_not_used,
// input
r#"
import { useLingui } from '@lingui/react/macro';
function MyComponent() {
const { i18n } = useLingui();
console.log(i18n);
}
"#,
// output after transform
r#"
import { useLingui as $_useLingui } from "@lingui/react";
function MyComponent() {
const { i18n, _: $__ } = $_useLingui();
console.log(i18n);
}
"#
);

to!(
work_with_existing_use_lingui_statement,
// input
Expand Down

0 comments on commit 4cd7fa7

Please sign in to comment.