Convert Javascript to Haxe?

Javascript has tons and tons of libraries out there, with huge mindshare.

Has anyone built or attempted to build a javascript to haxe converter?

This would ultimately allow the effort put into opensource javascript to be reused in haxe/openfl.

NOTE: I’m not interested in building haxe externs to javascript. I’d like to convert javascript to haxe, so great javascript libs can be reused cross-platform via haxe.


I don’t know of any, and there’s probably none out there.

It’s probably not a big technical challenge,
if you hack the v8 engine (or similar) to get javascript => ast (assuming there’s such a thing, but I imagine there is) then all you need is ast => haxe which should be straightforward.

Well at least that’s a theory.

I’ve definitely converted JavaScript to Haxe, but I’ve always done so by hand. Depending on how it’s written, you basically copy and paste, though you need to adapt into classes, generally it isn’t too bad.

I’m not sure how well you could automate it, since it’s untyped?

A bit of inference and Dynamic elsewhere I guess, though that does complicate the conversion.

Even if every variable was declared as dynamic, and it ported somewhat automatically, it’d be a boon to lots of devs.

I’m sure there would be some drawbacks (no compile time type checking), but most libraries don’t need to be optimized to work - it’s only when you find a stress point that you should need to optimize… which I’m sure would come up more often in games, but still, i think would have some merit…

You can also use universal-transpiler to convert a subset of JavaScript into Haxe.

Cool… thanks for the info!

If anyone runs into this post there is also haxe refactor 4.2.0