benmerckx / genes

Generates split ES6 modules and Typescript definitions from Haxe modules.
44 stars 8 forks source link

static __init__() missing? #13

Closed kevinresol closed 4 years ago

kevinresol commented 4 years ago

This line of code doesn't seem to appear anywhere in the generate js files. But even if it does I doubt it would work at all.

The magic value is later used in some react render functions:

function render() return {"$$typeof": $$tre, ...};

cc @klabz

benmerckx commented 4 years ago

I'm completely unsure where we could place extern __init__ code and have it be effective. How is that handled in hxgenjs?

benmerckx commented 4 years ago

In this specific case you probably just want to define react_no_inline

kLabz commented 4 years ago

Yeah it's used for jsx inlining.. though do you even use jsx()?

kevinresol commented 4 years ago

How is that handled in hxgenjs?

I can't recall. Perhaps I just used react_no_inline

though do you even use jsx()?

Generally no, yeah. Just happen I am experimenting with something...

kevinresol commented 4 years ago

How bad is the impact if the value is moved to a static variable, say ReactType.__tre?

kLabz commented 4 years ago

No idea, what do you think @elsassph?

elsassph commented 4 years ago

Hey there :)

In the case of React, we generate "global code", where $$tre will be used in every render function.

In Haxe Modular the approach I used was to actually duplicate any top level $* variable in the bundles (not even checking whether they are used). But that's kind of a self-serving hack.

Could it be attached to a class? Yes that could be a cleaner option. It should be hidden from completion though so maybe it could be created purely in macro.

kevinresol commented 4 years ago

It should be hidden from completion

@:noCompletion should do the job.

kevinresol commented 4 years ago

as for genes on this problem, maybe it should just emit a warning for __init__ on extern class

benmerckx commented 4 years ago

Closed this with a warning here. Someday it might make sense to be able to configure for each extern if you want extern __init__ code either appear before main() or in every file the extern is used.