From 72a7ab5c37252ffef18f2793fa183030e6ab218d Mon Sep 17 00:00:00 2001 From: Andrew Morris Date: Mon, 24 Jul 2023 14:49:38 +1000 Subject: [PATCH] Static eval for arrow functions --- inputs/passing/exportDefaultArrow.ts | 5 +++++ valuescript_compiler/src/module_compiler.rs | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 inputs/passing/exportDefaultArrow.ts diff --git a/inputs/passing/exportDefaultArrow.ts b/inputs/passing/exportDefaultArrow.ts new file mode 100644 index 0000000..8be915c --- /dev/null +++ b/inputs/passing/exportDefaultArrow.ts @@ -0,0 +1,5 @@ +//! test_output("Hi") + +export default () => { + return "Hi"; +}; diff --git a/valuescript_compiler/src/module_compiler.rs b/valuescript_compiler/src/module_compiler.rs index c94cf53..e5b2b79 100644 --- a/valuescript_compiler/src/module_compiler.rs +++ b/valuescript_compiler/src/module_compiler.rs @@ -1046,8 +1046,14 @@ impl ModuleCompiler { Value::String("(error)".to_string()) } }, + swc_ecma_ast::Expr::Arrow(arrow) => { + let p = self.allocate_defn_numbered("_anon"); + let mut fn_defns = self.compile_fn(p.clone(), None, Functionish::Arrow(arrow.clone())); + self.module.definitions.append(&mut fn_defns); + + Value::Pointer(p) + } swc_ecma_ast::Expr::TaggedTpl(_) - | swc_ecma_ast::Expr::Arrow(_) | swc_ecma_ast::Expr::Class(_) | swc_ecma_ast::Expr::Yield(_) | swc_ecma_ast::Expr::MetaProp(_)