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: nested macros used in useLingui in arrow functions #133

Merged
merged 1 commit into from
Dec 23, 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
8 changes: 6 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,11 +366,15 @@ impl<'a> Fold for LinguiMacroFolder {
return expr;
}

if let Expr::Arrow(arrow_expr) = expr {
return Expr::Arrow(self.fold_arrow_expr(arrow_expr))
}

let mut folder = JsMacroFolder::new(&mut self.ctx);

andrii-bodnar marked this conversation as resolved.
Show resolved Hide resolved
folder.fold_expr(expr).fold_children_with(self)
}

andrii-bodnar marked this conversation as resolved.
Show resolved Hide resolved
fn fold_call_expr(&mut self, expr: CallExpr) -> CallExpr {
// If no package that we care about is imported, skip the following
// transformation logic.
Expand Down
33 changes: 33 additions & 0 deletions src/tests/use_lingui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,39 @@ function MyComponent() {
"#
);

to!(
support_nested_macro_when_in_arrow_function_issue_2095,
// input
r#"
import { plural } from '@lingui/core/macro'
import { useLingui } from '@lingui/react/macro'

const MyComponent = () => {
const { t } = useLingui();
const a = t`Text ${plural(users.length, {
offset: 1,
0: "No books",
1: "1 book",
other: "\# books"
})}`;
}
"#,
// output after transform
r#"
import { useLingui as $_useLingui } from "@lingui/react";
const MyComponent = () => {
const { i18n: $__i18n, _: $__ } = $_useLingui();
const a = $__i18n._({
id: "hJRCh6",
message: "Text {0, plural, offset:1 =0 {No books} =1 {1 book} other {# books}}",
values: {
0: users.length
}
});
}
"#
);

to!(
support_passing_t_variable_as_dependency,
// input
Expand Down
Loading