Skip to content

Commit

Permalink
Implement static method props
Browse files Browse the repository at this point in the history
  • Loading branch information
voltrevo committed Jul 24, 2023
1 parent 2d58ef5 commit 9a327ab
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
11 changes: 11 additions & 0 deletions inputs/passing/staticMethodProp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//! test_output("foo")

export default () => {
return stuff.foo();
};

const stuff = {
foo() {
return 'foo';
}
};
34 changes: 32 additions & 2 deletions valuescript_compiler/src/module_compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
},
};

Expand Down

0 comments on commit 9a327ab

Please sign in to comment.