mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 05:01:07 +00:00
Update javascript executor to work w/ compiled ts scripts that export a main function; add output to javalin storeRecordAssociatedScript
This commit is contained in:
@ -80,11 +80,20 @@ public class QJavaScriptExecutor implements QCodeExecutor
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// wrap the user's code in an immediately-invoked function expression //
|
||||
// if the user's code (%s below) returns - then our IIFE is done. //
|
||||
// if the user's code doesn't return, but instead created a 'script' //
|
||||
// variable, with a 'main' function on it (e.g., from a compiled //
|
||||
// type script file), then call main function and return its result. //
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
String codeToRun = """
|
||||
(function userDefinedFunction()
|
||||
{
|
||||
%s
|
||||
%s
|
||||
|
||||
if(script && script.main)
|
||||
{
|
||||
return (script.main());
|
||||
}
|
||||
})();
|
||||
""".formatted(code);
|
||||
|
||||
|
@ -100,6 +100,34 @@ class ExecuteCodeActionTest
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testCompiledFromTypeScript() throws QException
|
||||
{
|
||||
OneTestOutput oneTestOutput = testOne(4, """
|
||||
var script = (function (exports) {
|
||||
|
||||
function cooling() {
|
||||
output.setD(7);
|
||||
return (output);
|
||||
}
|
||||
|
||||
cooling();
|
||||
|
||||
exports.cooling = cooling;
|
||||
|
||||
return exports;
|
||||
})({});
|
||||
""");
|
||||
assertEquals(7, oneTestOutput.testOutput().getD());
|
||||
assertTrue(oneTestOutput.executeCodeOutput().getOutput() instanceof TestOutput);
|
||||
assertEquals(7, ((TestOutput) oneTestOutput.executeCodeOutput().getOutput()).getD());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
|
Reference in New Issue
Block a user