From 93d9e44f1c7a3afea673f056d99001a026c0a6d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Thu, 18 Jul 2024 10:12:26 +0900 Subject: [PATCH] fix(es/quote): Fix macro (#9270) --- crates/swc_ecma_quote_macros/src/ast/class.rs | 6 +++++- crates/swc_ecma_quote_macros/src/ast/decl.rs | 4 ++-- crates/swc_ecma_quote_macros/src/ast/expr.rs | 14 ++++++++------ crates/swc_ecma_quote_macros/src/ast/mod.rs | 4 +++- .../swc_ecma_quote_macros/src/ast/module_decl.rs | 2 +- crates/swc_ecma_quote_macros/src/ast/prop.rs | 4 +++- crates/swc_ecma_quote_macros/src/ast/stmt.rs | 2 +- 7 files changed, 23 insertions(+), 13 deletions(-) diff --git a/crates/swc_ecma_quote_macros/src/ast/class.rs b/crates/swc_ecma_quote_macros/src/ast/class.rs index decd01eab9d3..2018d90f6ceb 100644 --- a/crates/swc_ecma_quote_macros/src/ast/class.rs +++ b/crates/swc_ecma_quote_macros/src/ast/class.rs @@ -4,6 +4,7 @@ impl_struct!( Class, [ span, + ctxt, decorators, body, super_class, @@ -16,7 +17,7 @@ impl_struct!( impl_struct!( Constructor, - [span, key, params, body, accessibility, is_optional] + [span, ctxt, key, params, body, accessibility, is_optional] ); impl_struct!( @@ -74,6 +75,9 @@ impl_struct!( AutoAccessor, [ span, + is_abstract, + is_override, + definite, key, value, type_ann, diff --git a/crates/swc_ecma_quote_macros/src/ast/decl.rs b/crates/swc_ecma_quote_macros/src/ast/decl.rs index fe3fcc3ccb7b..64e9490b0fce 100644 --- a/crates/swc_ecma_quote_macros/src/ast/decl.rs +++ b/crates/swc_ecma_quote_macros/src/ast/decl.rs @@ -14,8 +14,8 @@ impl_enum!( ] ); -impl_struct!(ClassDecl, [ident, class]); -impl_struct!(FnDecl, [ident, function]); +impl_struct!(ClassDecl, [ident, declare, class]); +impl_struct!(FnDecl, [ident, declare, function]); impl_struct!(VarDecl, [span, ctxt, kind, declare, decls]); impl_struct!(VarDeclarator, [span, name, init, definite]); impl_struct!(UsingDecl, [span, is_await, decls]); diff --git a/crates/swc_ecma_quote_macros/src/ast/expr.rs b/crates/swc_ecma_quote_macros/src/ast/expr.rs index bdcc8244ae2f..fb4d36548d2f 100644 --- a/crates/swc_ecma_quote_macros/src/ast/expr.rs +++ b/crates/swc_ecma_quote_macros/src/ast/expr.rs @@ -71,6 +71,7 @@ impl_struct!( ArrowExpr, [ span, + ctxt, params, body, is_async, @@ -89,19 +90,19 @@ impl_struct!(MemberExpr, [span, obj, prop]); impl_struct!(SuperPropExpr, [span, obj, prop]); impl_struct!(CondExpr, [span, test, cons, alt]); -impl_struct!(CallExpr, [span, callee, args, type_args]); +impl_struct!(CallExpr, [span, ctxt, callee, args, type_args]); impl_struct!(ExprOrSpread, [spread, expr]); impl_struct!(Super, [span]); impl_struct!(Import, [span, phase]); -impl_struct!(NewExpr, [span, callee, args, type_args]); +impl_struct!(NewExpr, [span, ctxt, callee, args, type_args]); impl_struct!(SeqExpr, [span, exprs]); -impl_struct!(TaggedTpl, [span, tag, type_params, tpl]); +impl_struct!(TaggedTpl, [span, ctxt, tag, type_params, tpl]); impl_struct!(YieldExpr, [span, arg, delegate]); impl_struct!(MetaPropExpr, [span, kind]); impl_struct!(AwaitExpr, [span, arg]); -impl_struct!(JSXMemberExpr, [obj, prop]); -impl_struct!(JSXNamespacedName, [ns, name]); +impl_struct!(JSXMemberExpr, [span, obj, prop]); +impl_struct!(JSXNamespacedName, [span, ns, name]); impl_struct!(JSXEmptyExpr, [span]); impl_struct!(JSXElement, [span, opening, closing, children]); impl_struct!(JSXFragment, [span, opening, closing, children]); @@ -111,6 +112,7 @@ impl_struct!(ParenExpr, [span, expr]); impl_struct!( Function, [ + ctxt, params, decorators, span, @@ -150,6 +152,6 @@ impl_enum!(JSXAttrName, [Ident, JSXNamespacedName]); impl_enum!(JSXExpr, [Expr, JSXEmptyExpr]); -impl_struct!(OptCall, [span, callee, args, type_args]); +impl_struct!(OptCall, [span, ctxt, callee, args, type_args]); impl_enum!(Callee, [Super, Import, Expr]); diff --git a/crates/swc_ecma_quote_macros/src/ast/mod.rs b/crates/swc_ecma_quote_macros/src/ast/mod.rs index 3fc846b41c06..08d68bdd0a37 100644 --- a/crates/swc_ecma_quote_macros/src/ast/mod.rs +++ b/crates/swc_ecma_quote_macros/src/ast/mod.rs @@ -65,10 +65,12 @@ macro_rules! impl_struct { fn to_code(&self, cx: &crate::ctxt::Ctx) -> syn::Expr { let mut builder = crate::builder::Builder::new(stringify!($name)); + let Self { $($v,)* } = self; + $( builder.add( stringify!($v), - crate::ast::ToCode::to_code(&self.$v, cx), + crate::ast::ToCode::to_code($v, cx), ); )* diff --git a/crates/swc_ecma_quote_macros/src/ast/module_decl.rs b/crates/swc_ecma_quote_macros/src/ast/module_decl.rs index 2559fa1089ae..702e819075d6 100644 --- a/crates/swc_ecma_quote_macros/src/ast/module_decl.rs +++ b/crates/swc_ecma_quote_macros/src/ast/module_decl.rs @@ -19,7 +19,7 @@ impl_struct!(ImportDecl, [span, specifiers, src, type_only, with, phase]); impl_struct!(ExportDecl, [span, decl]); impl_struct!(ExportDefaultDecl, [span, decl]); impl_struct!(ExportDefaultExpr, [span, expr]); -impl_struct!(ExportAll, [span, src, with]); +impl_struct!(ExportAll, [span, type_only, src, with]); impl_struct!(NamedExport, [span, specifiers, src, type_only, with]); impl_enum!(ImportSpecifier, [Named, Default, Namespace]); diff --git a/crates/swc_ecma_quote_macros/src/ast/prop.rs b/crates/swc_ecma_quote_macros/src/ast/prop.rs index 8d267ff252a3..173f010ad12b 100644 --- a/crates/swc_ecma_quote_macros/src/ast/prop.rs +++ b/crates/swc_ecma_quote_macros/src/ast/prop.rs @@ -6,6 +6,8 @@ impl_struct!( PrivateProp, [ span, + ctxt, + definite, key, value, type_ann, @@ -20,7 +22,7 @@ impl_struct!( impl_struct!(KeyValueProp, [key, value]); -impl_struct!(AssignProp, [key, value]); +impl_struct!(AssignProp, [span, key, value]); impl_struct!(GetterProp, [span, key, type_ann, body]); impl_struct!(SetterProp, [span, key, param, this_param, body]); diff --git a/crates/swc_ecma_quote_macros/src/ast/stmt.rs b/crates/swc_ecma_quote_macros/src/ast/stmt.rs index b90cb03cf235..07d30a484d47 100644 --- a/crates/swc_ecma_quote_macros/src/ast/stmt.rs +++ b/crates/swc_ecma_quote_macros/src/ast/stmt.rs @@ -9,7 +9,7 @@ impl_enum!( ); impl_struct!(EmptyStmt, [span]); -impl_struct!(BlockStmt, [span, stmts]); +impl_struct!(BlockStmt, [span, ctxt, stmts]); impl_struct!(DebuggerStmt, [span]); impl_struct!(WithStmt, [span, obj, body]); impl_struct!(LabeledStmt, [span, label, body]);