Skip to content

Commit

Permalink
Fix useTranslations bug (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
rtsao committed Aug 15, 2023
1 parent 872020d commit 97692da
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
10 changes: 10 additions & 0 deletions fixtures/i18n-use-translate-deep/code.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { useTranslations } from 'fusion-plugin-i18n-react';

const foo = nested(() => {
const bar = () => {
const translate = useTranslations();
return {
[hello]: translate('hello'),
};
};
});
3 changes: 3 additions & 0 deletions fixtures/i18n-use-translate-deep/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ssr": true
}
15 changes: 15 additions & 0 deletions fixtures/i18n-use-translate-deep/output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import _fusionPluginI18nChunkTranslationMap from "virtual:fusion-vite-i18n-map";
import { useTranslations } from 'fusion-plugin-i18n-react';
const foo = nested(() => {
const bar = () => {
const translate = useTranslations();
return {
[hello]: translate('hello')
};
};
});
_fusionPluginI18nChunkTranslationMap.add("/path/to/file.js", [
"vite-i18n-chunk"
], [
"hello"
]);
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use swc_core::{
},
},
};
use tracing::debug;

use super::State;

Expand Down Expand Up @@ -48,12 +47,8 @@ struct Analyzer<'a> {
impl Visit for Analyzer<'_> {
noop_visit_type!();

fn visit_var_declarator(&mut self, var_declarator: &VarDeclarator) {
debug!("use_translation_run: {:?}", var_declarator);
debug!("state: {:?}", self.state);
}

fn visit_call_expr(&mut self, call_expr: &CallExpr) {
call_expr.visit_children_with(self);
match &call_expr.callee {
Callee::Expr(boxed_expr) => match &**boxed_expr {
Expr::Ident(ident) => {
Expand Down

0 comments on commit 97692da

Please sign in to comment.