How to prevent the compiler on js to put if-else in one line

135 views
Skip to first unread message

Rafael Oliveira

unread,
Sep 11, 2015, 3:25:31 PM9/11/15
to Haxe
The compiler on js takes a code like this:

if (a == 0)
      trace("aaa");
else
      trace("bbb");

and transform in this:

if(a == 0) console.log("aaa"); else console.log("bbb");

this is hard to debug because I can't put a breakpoint on the else because everything is on the same line.
is there a compiler flag to respect the lines in the source?

Benjamin Dubois

unread,
Sep 11, 2015, 3:54:17 PM9/11/15
to haxe...@googlegroups.com
Is there a reason you are not using source mapping so that you can put the breakpoint in your haxe code ?

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

Rafael Oliveira

unread,
Sep 11, 2015, 4:21:22 PM9/11/15
to Haxe
With source mapping I can't see the values of all the variables, same variables Google Chrome don't show the value (maybe because the implementation is using a different code). And the if-else in the same line prevent me to set a breakpoint on the else. If I click in the line with the else, Chrome put the breakpoint some lines above the else.

Raoul Duke

unread,
Sep 11, 2015, 4:26:52 PM9/11/15
to haxe...@googlegroups.com
> implementation is using a different code). And the if-else in the same line
> prevent me to set a breakpoint on the else. If I click in the line with the
> else, Chrome put the breakpoint some lines above the else.

agreed, i think that sucks.

even if sourcemaps did not have some trouble, i think it is still
better to generate code that is as debuggable as possible from the
get-go, rather than having to make people jump through more hoops.

Philippe Elsass

unread,
Sep 12, 2015, 8:21:40 AM9/12/15
to Haxe

+1 I prefer working without source mapping and I'm often annoyed by these one liners.

michael solomon

unread,
Sep 12, 2015, 2:29:00 PM9/12/15
to Haxe
Why not use "debugger" js keyword?
http://try.haxe.org/#07804

Rafael Oliveira

unread,
Sep 13, 2015, 1:03:19 AM9/13/15
to Haxe
Works, but is not the best solution. I opened a issue:

https://github.com/HaxeFoundation/haxe/issues/4542

Juraj Kirchheim

unread,
Sep 15, 2015, 2:04:19 AM9/15/15
to haxe...@googlegroups.com
Can't you simply run your Haxe output through a JS beautifier/formatter of your choice?



--

Raoul Duke

unread,
Sep 15, 2015, 11:55:06 AM9/15/15
to haxe...@googlegroups.com
> Can't you simply run your Haxe output through a JS beautifier/formatter of
> your choice?

Sounds like quite possibly a perfectly reasonable work around. Good idea.

In the long run, it would still be really nice if Haxe's output was
written with debugability in mind from the get-go. Ideally. Some day.
In a perfect world. In the future. :-)

Rafael Oliveira

unread,
Sep 15, 2015, 12:01:39 PM9/15/15
to Haxe
I tested these options, but none of them worked. does anyone know other options?

Zach Lym

unread,
Dec 1, 2015, 4:54:58 PM12/1/15
to Haxe
Can't you simply run your Haxe output through a JS beautifier/formatter of your choice? 

FWIW, there is support for chaining together map outputs, but this would break it by default.

So it's still a PITA.
Reply all
Reply to author
Forward
0 new messages