Skip to content

Commit

Permalink
feat: fix incompatibility with latest swc-core
Browse files Browse the repository at this point in the history
  • Loading branch information
timofei-iatsenko committed Oct 30, 2024
1 parent 5e84f3b commit 02ca026
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/ast_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,15 @@ pub fn create_key_value_prop(key: &str, value: Box<Expr>) -> 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,
})
],
Expand Down
4 changes: 3 additions & 1 deletion src/js_macro_folder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{*};
Expand Down Expand Up @@ -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(),
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/jsx_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
)));
}

Expand Down
12 changes: 7 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -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<VarDeclarator> = decl.decls.into_iter().map(|declarator| {
if let Some(init) = &declarator.init {
let expr = init.as_ref();
Expand All @@ -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 {
Expand All @@ -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()
}))),

Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/macro_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 02ca026

Please sign in to comment.