Using a custom generator only for certain classe

86 views
Skip to first unread message

Marcelo de Moraes Serpa

unread,
Jul 16, 2016, 11:29:11 PM7/16/16
to haxe...@googlegroups.com
Hey there list,

I'm using a custom js generator to generate an Ember-CLI-compatible code from Haxe. This includes some hacks to generate that maps to the Ember way of defining new objects (Ember.extend) and including ES6 imports and exports. It's still very much a POC, but I might be sharing it soon if all works well.

That being said, I'd like to use this generator *only* for certain classes. Other classes might not use Ember features at all and will use the ES5 output from Haxe.

My original idea was to mark the class with a metadata like ":emberObject" and then in the generator check for that. I could indeed access the metadata for the class, but couldn't find a way to fallback to the default js generator.

Is that even possible? I don't see a way of delegating the generation of js to the compiler once `Compiler.setCustomJSGenerator` has been called to use the custom js generator. 

Any insights welcome!

- Marcelo.

Philippe Elsass

unread,
Jul 17, 2016, 2:51:00 AM7/17/16
to Haxe

I'm afraid it's all our nothing.

I'd love to see the foundation provide a reference JS generator, or more granular hooks (at least for JS).

Philippe


--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/d/optout.

Marcelo de Moraes Serpa

unread,
Jul 17, 2016, 4:20:55 PM7/17/16
to haxe...@googlegroups.com
Hi Philippe,

Yeah, it'd be very useful if we could get a reference to any of the underlying built-in generators from the initialisation macro context. I see the custom generator approach as a way to completely customize the build workflow dynamically, something that's not possible with a plain build hxml, unless you use another external build script to orchestrate that. 

This way we could also control from the Haxe macro code what generator to use, basically using pure Haxe as a build orchestration tool instead of interfacing from the CLI/hxml.

As a side note, the example generator seems to be outdated/incomplete when comparing to the built-in one.

@Foundation are there are any plans to expand the generator/build API in that direction?

I guess what I can do now is to write a script in Haxe or some other scripting language that will implement this logic. The problem here is that I won't have access to the AST of each type in order to check for the metatags but I could maybe use an extension to identify what files need to use the ES6 custom generator, like: TypeName.es6.hx. This would run this script through haxe using the ES6 custom generator. For everything else, it uses the built-in generator.

I'll see what I can come up with.
Reply all
Reply to author
Forward
0 new messages