Skip to content
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
15 changes: 15 additions & 0 deletions crates/lingui_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,21 @@ impl Fold for IdentReplacer {

n
}

/// In a shorthand property `{ t }` the same identifier is both the key
/// and the value. Expand it to `{ t: $__ }` so the key is preserved.
fn fold_prop(&mut self, n: Prop) -> Prop {
if let Prop::Shorthand(ident) = &n {
if ident.to_id() == self.from {
return Prop::KeyValue(KeyValueProp {
key: PropName::Ident(IdentName::new(ident.sym.clone(), ident.span)),
value: Box::new(Expr::Ident(self.to.clone())),
});
}
}

n.fold_children_with(self)
}
}

pub struct LinguiMacroFolder<C>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
source: crates/lingui_macro/tests/use_lingui.rs
---
import { useLingui } from '@lingui/react/macro';

function useGreeting(format) {
const { t } = useLingui();
return format({ t });
}

↓ ↓ ↓ ↓ ↓ ↓

import { useLingui as $_useLingui } from "@lingui/react";
function useGreeting(format) {
const { _: $__ } = $_useLingui();
return format({
t: $__
});
}
12 changes: 12 additions & 0 deletions crates/lingui_macro/tests/use_lingui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,15 @@ function MyComponent() {
}
"#
);

to!(
support_passing_t_in_shorthand_object_property,
r#"
import { useLingui } from '@lingui/react/macro';

function useGreeting(format) {
const { t } = useLingui();
return format({ t });
}
"#
);
Loading