COMMUNITY

Transpile JavaScript back to Haxe

Hy there👋🏻

I am currently exploring the Haxe compiler. Now my question is: Is there a way to transpile JavaScript back to Haxe?

Thanks and regards

Timo

Welcome to the forum!
No (unfortunatly not); Haxe only compiles Haxe sources to other languages, not the other way around. There are some tool that convert sources to Haxe, but I don’t think JavaScript is one of them.

Hi!

It’s not an easy task since JS is dynamically typed and all the type information is lost from the source code. So, if we’re talking about Haxe-generated JS, it’s totally not possible to do 100% correct translation back to the original source.

However, I believe it is indeed theoretically possible to restore some type information in sane JS code by tracing the data flow (like JIT compilers do) and generate a compileable Haxe code out of that. It’s not going to look pretty, but it’s an interesting excersice :slight_smile:

We could probably port this Java code over to Haxe as a starting point, it does not seem to have any really special dependancies and is not excessively large.

Do you think it’s useful, or powerful enough?

I gave a talk about that exact topic at the HaxeUp in Linz by the way. I’ll provide a useful summary of that talk right here: Good luck!

4 Likes

Here’s the video: https://haxe.org/videos/conferences/haxeup-sessions-2019/robert-kondrad-kha-v-html5.html