Skip to content

Commit

Permalink
fix(es/quote): Fix macro (#9270)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 committed Jul 18, 2024
1 parent 5f91339 commit 93d9e44
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 13 deletions.
6 changes: 5 additions & 1 deletion crates/swc_ecma_quote_macros/src/ast/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ impl_struct!(
Class,
[
span,
ctxt,
decorators,
body,
super_class,
Expand All @@ -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!(
Expand Down Expand Up @@ -74,6 +75,9 @@ impl_struct!(
AutoAccessor,
[
span,
is_abstract,
is_override,
definite,
key,
value,
type_ann,
Expand Down
4 changes: 2 additions & 2 deletions crates/swc_ecma_quote_macros/src/ast/decl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
14 changes: 8 additions & 6 deletions crates/swc_ecma_quote_macros/src/ast/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ impl_struct!(
ArrowExpr,
[
span,
ctxt,
params,
body,
is_async,
Expand All @@ -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]);
Expand All @@ -111,6 +112,7 @@ impl_struct!(ParenExpr, [span, expr]);
impl_struct!(
Function,
[
ctxt,
params,
decorators,
span,
Expand Down Expand Up @@ -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]);
4 changes: 3 additions & 1 deletion crates/swc_ecma_quote_macros/src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);
)*

Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_quote_macros/src/ast/module_decl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
4 changes: 3 additions & 1 deletion crates/swc_ecma_quote_macros/src/ast/prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ impl_struct!(
PrivateProp,
[
span,
ctxt,
definite,
key,
value,
type_ann,
Expand All @@ -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]);
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_quote_macros/src/ast/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down

0 comments on commit 93d9e44

Please sign in to comment.