Implement static method props

This commit is contained in:
Andrew Morris
2023-07-24 17:57:51 +10:00
parent 2d58ef5ebd
commit 9a327ababe
2 changed files with 43 additions and 2 deletions

View File

@@ -1007,11 +1007,41 @@ impl ModuleCompiler {
}
swc_ecma_ast::Prop::Assign(_)
| swc_ecma_ast::Prop::Getter(_)
| swc_ecma_ast::Prop::Setter(_)
| swc_ecma_ast::Prop::Method(_) => {
| swc_ecma_ast::Prop::Setter(_) => {
self.todo(prop.span(), "This type of static prop");
return Value::String("(error)".to_string());
}
swc_ecma_ast::Prop::Method(method) => {
let key = match &method.key {
swc_ecma_ast::PropName::Ident(ident) => Value::String(ident.sym.to_string()),
_ => {
self.todo(method.key.span(), "Static non-ident prop names");
Value::String("(error)".to_string())
}
};
let fn_ident = match &method.key {
swc_ecma_ast::PropName::Ident(ident) => Some(ident.clone()),
_ => None,
};
let fn_name = fn_ident.clone().map(|ident| ident.sym.to_string());
let p = match &fn_name {
Some(name) => self.allocate_defn(name),
None => self.allocate_defn_numbered("_anon"),
};
let mut nested_defns = self.compile_fn(
p.clone(),
fn_name.clone(),
Functionish::Fn(fn_ident, method.function.clone()),
);
self.module.definitions.append(&mut nested_defns);
(key, Value::Pointer(p))
}
},
};