Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: useLingui when t is not used #107

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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