diff --git a/Cargo.lock b/Cargo.lock index a69888a..558da77 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -539,7 +539,7 @@ checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1" [[package]] name = "lingui_macro_plugin" -version = "4.1.0" +version = "5.0.0-next.2" dependencies = [ "data-encoding", "once_cell", diff --git a/src/ast_utils.rs b/src/ast_utils.rs index f717a13..040af9a 100644 --- a/src/ast_utils.rs +++ b/src/ast_utils.rs @@ -163,15 +163,15 @@ pub fn create_key_value_prop(key: &str, value: Box) -> PropOrSpread { ))); } -pub fn create_import(source: JsWord, imported: Ident, local: Ident) -> ModuleItem { +pub fn create_import(source: JsWord, imported: IdentName, local: IdentName) -> ModuleItem { ModuleItem::ModuleDecl(ModuleDecl::Import(ImportDecl { span: DUMMY_SP, phase: ImportPhase::default(), specifiers: vec![ ImportSpecifier::Named(ImportNamedSpecifier { span: DUMMY_SP, - local, - imported: Some(ModuleExportName::Ident(imported)), + local: local.into(), + imported: Some(ModuleExportName::Ident(imported.into())), is_type_only: false, }) ], diff --git a/src/js_macro_folder.rs b/src/js_macro_folder.rs index a92ce61..db6a95d 100644 --- a/src/js_macro_folder.rs +++ b/src/js_macro_folder.rs @@ -6,6 +6,7 @@ use swc_core::{ visit::{Fold, FoldWith}, }, }; +use swc_core::common::SyntaxContext; use crate::ast_utils::{*}; use crate::builder::MessageBuilder; use crate::macro_utils::{*}; @@ -66,10 +67,11 @@ impl<'a> JsMacroFolder<'a> { return Box::new(self.ctx.runtime_idents.i18n.clone().into()); }), - prop: MemberProp::Ident(Ident::new("_".into(), DUMMY_SP)), + prop: MemberProp::Ident(IdentName::new("_".into(), DUMMY_SP)), }).as_callee(), args, type_args: None, + ctxt: SyntaxContext::empty(), } } diff --git a/src/jsx_visitor.rs b/src/jsx_visitor.rs index a98a18e..2337c93 100644 --- a/src/jsx_visitor.rs +++ b/src/jsx_visitor.rs @@ -212,7 +212,7 @@ impl<'a> Visit for TransJSXVisitor<'a> { fn visit_jsx_text(&mut self, el: &JSXText) { self.tokens .push(MsgToken::String(clean_jsx_element_literal_child( - &el.raw.to_string(), + &el.value.to_string(), ))); } diff --git a/src/lib.rs b/src/lib.rs index 29b484b..7d59609 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,5 @@ use std::collections::HashSet; -use swc_core::common::DUMMY_SP; +use swc_core::common::{SyntaxContext, DUMMY_SP}; use swc_core::plugin::errors::HANDLER; use swc_core::{ @@ -140,7 +140,7 @@ impl LinguiMacroFolder { Stmt::Decl(Decl::Var(var_decl)) => { let decl = *var_decl; - let underscore_ident = quote_ident!("$__"); + let underscore_ident = quote_ident!(SyntaxContext::empty(), "$__"); let decls: Vec = decl.decls.into_iter().map(|declarator| { if let Some(init) = &declarator.init { let expr = init.as_ref(); @@ -163,14 +163,14 @@ impl LinguiMacroFolder { &ident.to_id(), ); - let new_i18n_ident = quote_ident!(ident.span, "$__i18n"); + let new_i18n_ident = quote_ident!(ident.ctxt, "$__i18n"); ident_replacer = Some(IdentReplacer { from: ident.to_id(), to: underscore_ident.clone(), }); - ctx.runtime_idents.i18n = new_i18n_ident.clone(); + ctx.runtime_idents.i18n = new_i18n_ident.clone().into(); return Some(ObjectPatProp::KeyValue( KeyValuePatProp { @@ -191,7 +191,7 @@ impl LinguiMacroFolder { return VarDeclarator { init: Some(Box::new(Expr::Call(CallExpr { - callee: Callee::Expr(Box::new(Expr::Ident(ctx.runtime_idents.use_lingui.clone()))), + callee: Callee::Expr(Box::new(Expr::Ident(ctx.runtime_idents.use_lingui.clone().into()))), ..call.clone() }))), @@ -228,6 +228,7 @@ r#"You have to destructure `t` when using the `useLingui` macro, i.e: decls, declare: false, kind: decl.kind, + ctxt: SyntaxContext::empty() }))) } _ => stmt, @@ -238,6 +239,7 @@ r#"You have to destructure `t` when using the `useLingui` macro, i.e: let mut block = BlockStmt { span: n.span, stmts, + ctxt: SyntaxContext::empty() }; // use lingui matched above diff --git a/src/macro_utils.rs b/src/macro_utils.rs index 57450eb..c33e602 100644 --- a/src/macro_utils.rs +++ b/src/macro_utils.rs @@ -24,9 +24,9 @@ pub struct MacroCtx { #[derive(Clone)] pub struct RuntimeIdents { - pub i18n: Ident, - pub trans: Ident, - pub use_lingui: Ident, + pub i18n: IdentName, + pub trans: IdentName, + pub use_lingui: IdentName, } impl Default for RuntimeIdents {