From 292d35280c64748d7fc4c6b8c08b2fe1fb8cdb57 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Thu, 18 Aug 2022 08:33:21 +0100 Subject: [PATCH] Use default export as main JavaScript function --- lib/src/fnc/script/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/fnc/script/main.rs b/lib/src/fnc/script/main.rs index adaf5928..72299135 100644 --- a/lib/src/fnc/script/main.rs +++ b/lib/src/fnc/script/main.rs @@ -32,7 +32,7 @@ pub async fn run( // Enable async code in the runtime run.spawn_executor(&exe).detach(); // Create the main function structure - let src = format!("export async function main() {{ {} }}", src); + let src = format!("export default async function() {{ {} }}", src); // Attempt to execute the script let res: Result, js::Error> = ctx.with(|ctx| { // Get the context global object @@ -48,7 +48,7 @@ pub async fn run( // Attempt to compile the script let res = ctx.compile("script", src)?; // Attempt to fetch the main export - let fnc = res.get::<_, Function>("main")?; + let fnc = res.get::<_, Function>("default")?; // Execute the main function fnc.call((This(doc), Rest(arg))) });