I just merged some code that makes Haxe/JS output ES6 classes instead of classic Function+prototype. It’s available in latest nightlies (also installable with Lix) and can be activated with the -D js-es=6 compiler argument.
We decided to include it in already Haxe 4.0, because ES6 class support is becoming critical nowadays, as they are not backwards-compatible with the classic inheritance style, making it impossible to use some ES6 libraries with Haxe.
We might look into adding more ES6 features usage for future versions, and meanwhile, the bravest ones are welcome to give it a try and give feedback!
UPD: I just wrote some documentation on this, describing limitations and required workarounds. Hopefully that will be part of the Haxe Manual soon enough!
Great, was waiting for it! (already had the flag in my hxml xD)
Does the very latest dev version of haxe (#33df799 atm) has known issues that could lead to this, or should I create an issue and try to reproduce it with a minimal example?
Must call super() constructor before accessing this in classes derived from an extern class with constructor
Yes, this is an expected error when you a) extend an extern class with the constructor and b) access this before calling super in the subclass (that might also happen implicitly if you have fields with initializers). The compiler should give you position of such access or field init.
You have to move them into the constructor after the super call in this case. Because Haxe guarantees that field with inits are initialized before any constructor call and with ES6 you cannot have that. For fully Haxe-generated we work that around by extracting constructor body in a method and applying a small hack, but for extern classes we can’t do anything besides printing an error message with a position pointing to the offending code.
Ok, thanks! This is kind of a huge limitation in my use case, but I’ll try to handle this via macros (since it should only happen in classes extending a particular extern class which is already using a lot of macros).
My first tests are good. I could update my web components lib to support the ES6 target and it works well dispite the constructor restriction.
Very good job Dan !
Import/export didn’t change - still one big JS with commonjs-style require/exports. It’s not yet producing separated JS files, just using ES6 classes for code generation.