How to output comments into JS target via macro?

80 views
Skip to first unread message

Haxeator

unread,
Jan 23, 2016, 10:51:20 AM1/23/16
to Haxe
I would like to output comments into javascript generated code, I need both "class comments" and "function comments" and "code comments" to make it more readable for people who don't know haxe. I suppose it could be somehow done with macros, but I can't make it work...

Benjamin Dasnois

unread,
Jan 23, 2016, 11:07:01 AM1/23/16
to haxe...@googlegroups.com
Hi,

As far as I know it is not possible at the moment.

Regards,

On Sat, Jan 23, 2016 at 3:51 PM, Haxeator <jan....@gmail.com> wrote:
I would like to output comments into javascript generated code, I need both "class comments" and "function comments" and "code comments" to make it more readable for people who don't know haxe. I suppose it could be somehow done with macros, but I can't make it work...

--
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.



--

Cristian Baluta

unread,
Jan 23, 2016, 11:54:20 AM1/23/16
to haxe...@googlegroups.com
I don't think a js developer will have problems reading haxe code.

Haxeator

unread,
Jan 23, 2016, 12:16:48 PM1/23/16
to Haxe
I want to be able to create comments with type annotations for JS libraries written in Haxe and I am looking for a solution to this. I want to make comments visible in JS IDE like Atom or Brackets, it is also required from management point of view as the generated code is not that nice as pure JS and if ever someone will continue with my work they might hack on JS directly as learning a new language like Haxe might seem too risky for them, even though I prepared preconfigured FlashDevelop instance in our subversion repository to make it easy for anyone to make change and compile. Right now I have 10 thousand LoC of generated JS of an industrial SCADA application ported from Delphi Pascal to Haxe and it makes it possible to natively target desktop and web platforms and also it makes sure there are no syntactic errors in code. I am old enough not to want to learn weak dynamically typed language like JavaScript that is why I picked Haxe (and not TypeScript that is web only). While any good JS developer should be able to understand generated code, he will have trouble understanding domain concepts, that is what comments are meant for.

Christian Afonso Ferreira

unread,
Jan 23, 2016, 12:54:06 PM1/23/16
to Haxe
I highly doubt that try to understand an auto generated code is easier than learn the source (particularly for generated code of advanced features) but you can do it with build macros.

var fields = Context.getBuildFields();
untyped __js__
('//Comment in ${field.name} is ${field.doc}');

You can get class, functions and field comments but I don't think it's possible for regular code because comments are not parsed as a type of expression.
Maybe manually wrap them in a function to call untyped or later by processed by the macro.

Haxeator

unread,
Jan 23, 2016, 1:09:21 PM1/23/16
to Haxe
Ok, thanks, I will try it. I actually still need to learn macros well, the documentation did not have enough examples so I am still struggling. Anyway, the ability to generate comments is needed as an argument for management that Haxe is good enough solution to our problem and that it is possible to mitigate some risk associated with non-mainstream language and technology.

Philippe Elsass

unread,
Jan 23, 2016, 1:15:17 PM1/23/16
to Haxe

`untyped __js__` is usable to output comments within code blocks, not it front of types in way that week be useful for an editor.

It sounds like you will have to create a custom JS generator. Or to post-process the generated JS.

Philippe

--
Reply all
Reply to author
Forward
0 new messages