Hi,
I have been trying to improve the ExampleJSGenerator included in Haxe to generate JS code just like the one generated by the native (ocaml) compiler.
For that i needed to be able to check and set "features", that is used by compiler to generate only needed JS.
Unfortunately that API wasn't available for custom JS generators so i submitted a pull request (
https://github.com/HaxeFoundation/haxe/pull/3193) that adds `addFeature` and `hasFeature` to JSGenApi. I have barely no knowledge of ocaml, so that code might not be the best, please someone check it.
The code is available here:
https://gist.github.com/porfirioribeiro/4202abd244e78c8217cfI tried to make it work with dce and all output modes: js-flatten, js-classic, etc...
Had a example compiling with native and macro generators and spend many time on a diff viewer to make macro generated code look like native one.
Currently there are still some cosmetic bugs, some indents are not outputting right and some properties are ordered differently.
The only missing code i found is `Math.__name__ = ["Math"];`, for some reason `Math` is not being passed to the generator.
But everything works ok.
Obviously the macro generating takes a bit more time than the native.
I tough about include these changes to ExampleJSGenerator and include it in the pull request, but it might be too complex for an example.
If someone want to try this generator on their projects, don't forget you need the pull request, while and if it isn't accepted.
Usages for this? Extend it to support other JS libraries, but have a good base to start. Thats the reason i worked on this, extending ExampleJSGenerator wasn't good enough.