Skip to content

Commit

Permalink
WIP: class methods
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 committed Mar 16, 2023
1 parent 3fe1e08 commit 3fe70f6
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions crates/swc_ecma_transforms_proposal/src/decorator_2022_03.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ impl Decorator202203 {
}

/// Returns (name, initilaizer_name)
fn initializer_name(&mut self, name: &mut PropName) -> (Box<Expr>, Ident) {
fn initializer_name(&mut self, name: &mut PropName, prefix: &str) -> (Box<Expr>, Ident) {
match name {
PropName::Ident(i) => (
Box::new(Expr::Lit(Lit::Str(Str {
span: i.span.with_ctxt(SyntaxContext::empty()),
value: i.sym.clone(),
raw: None,
}))),
Ident::new(format!("_init_{}", i.sym).into(), i.span.private()),
Ident::new(format!("_{prefix}_{}", i.sym).into(), i.span.private()),
),
_ => {
let ident = private_ident!("_computedKey");
Expand All @@ -113,7 +113,10 @@ impl Decorator202203 {
expr: ident.clone().into(),
});

let init = Ident::new("_init_computedKey".into(), ident.span.private());
let init = Ident::new(
format!("_{prefix}_computedKey").into(),
ident.span.private(),
);

(Box::new(Expr::Ident(ident)), init)
}
Expand Down Expand Up @@ -147,14 +150,24 @@ impl VisitMut for Decorator202203 {
self.extra_stmts = old_stmts;
}

fn visit_mut_class_method(&mut self, n: &mut ClassMethod) {
n.visit_mut_children_with(self);

if n.function.decorators.is_empty() {
return;
}

let (name, init) = self.initializer_name(&mut n.key, "call");
}

fn visit_mut_class_prop(&mut self, p: &mut ClassProp) {
p.visit_mut_children_with(self);

if p.decorators.is_empty() {
return;
}

let (name, init) = self.initializer_name(&mut p.key);
let (name, init) = self.initializer_name(&mut p.key, "init");

self.extra_vars.push(VarDeclarator {
span: p.span,
Expand Down

0 comments on commit 3fe70f6

Please sign in to comment.