When I convert haxe
to JavaScript
, I need to make its methods asynchronous.
Here is the original Haxe
code:
@:expose
class Main implements IAsync {
static function main() {
trace("test");
}
static function testAwait() {
return 1;
}
}
The converted code looks like this:
. . .
Main.testAwait = function() {
return Main.test();
};
. . .
I want to replace function
with async function
in the code, but I am limited to changing just the method name using code macros:
package haxe_test;
import haxe.macro.Expr;
import haxe.macro.Context;
using haxe.macro.Tools;
using haxe_test.AsyncBuilder;
class BuildHub {
macro static public function build():Array<Field> {
var fields = Context.getBuildFields();
var testFunc:Function = {
expr: macro return $v{1},
ret: null,
params: [],
args: []
};
fields.push({
name: "testAwait",
access: [Access.AStatic],
kind: FieldType.FFun(testFunc),
pos: Context.currentPos(),
});
return fields;
}
Is there a way to replace function
with async function
?
UPD: The code has been simplified. Are there any compiler options or JSGenApi that can help me achieve this?