Skip to content

Commit

Permalink
fix: nested macros used in useLingui in arrow functions (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
timofei-iatsenko authored Dec 23, 2024
1 parent 625b4f2 commit d88ade0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
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);

folder.fold_expr(expr).fold_children_with(self)
}

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

0 comments on commit d88ade0

Please sign in to comment.