Haxe and JS Source Maps syntax fidelity

98 views
Skip to first unread message

Huck

unread,
Jul 19, 2013, 10:28:03 AM7/19/13
to haxe...@googlegroups.com
Hello,

Im using haxe to build an html5 game and use source maps for debugging in browsers. Ive noticed that in certain cases, the javascript generated does not quite match the source syntax. for example, this hx file:

class Test {
   
static function main() {
   
var r:Bool = true;
       
if(r)
       
{
            trace
("Hello World !");
       
}
       
else
       
{
            trace
("Hello World 2!");
       
}

   
}
}



will compile to (haxe 3):

(function () { "use strict";
var Test = function() { }
Test.main = function() {
   
var r = true;
   
if(r) console.log("Hello World !"); else console.log("Hello World 2!");
}
Test.main();
})();


as you can see, the multiline "if" statement in haxe is translated as a single line in javascript, which causes some debugging weirdness in chrome/firefox source maps. I was wondering if there was a way to keep the javascript generated in "verbose" mode for debugging so to match the haxe format, as to increase the generated fidelity between the haxe and js file?

thanks!
Message has been deleted

Huck

unread,
Jul 26, 2013, 11:11:06 AM7/26/13
to haxe...@googlegroups.com
(sorry for repost, browser posted the message before it was completed)

Since there are no answers i figure my question  might not have been clear, so i will try to refine it and see if ti helps.

so, when using source mappings with javascript target, there are a few differences in the generated code structure that cause annoying behavior while debugging. example, this haxe code:


if(r)
{
    trace
("Hello World !");
}
else
{
    trace
("Hello World 2!");
}

on multiple lines will generate the following javascript code: (note that it is on a single line):


if(r) console.log("Hello World !"); else console.log("Hello World 2!");

now the issue with that is when debugging with source mappings in chrome, the breakpoints will not go to trace("Hello World !");
 or
trace("Hello World 2!"); depending on runtime branching because the underlying javascript is on a single line, so the breakpoint sticks to the "if" line.

was wondering if there was an option to tell the compiler to stick to the format of the haxe code when generating target code? in short, expecting this javascript:
if(r){
   console.log("Hello World !");
}
else{
   console
.log("Hello World 2!");

}

thanks

 

dlots

unread,
Jul 26, 2013, 8:03:08 PM7/26/13
to haxe...@googlegroups.com
I don't believe there is such an option .

Bruno Garcia

unread,
Jul 26, 2013, 8:05:53 PM7/26/13
to haxe...@googlegroups.com
Source maps should work on JS without newlines. This sounds like a bug
in the generator.

Bruno

On 07/26/2013 08:11 AM, Huck wrote:
> (sorry for repost, browser posted the message before it was completed)
>
> Since there are no answers i figure my question might not have been
> clear, so i will try to refine it and see if ti helps.
>
> so, when using source mappings with javascript target, there are a few
> differences in the generated code structure that cause annoying behavior
> while debugging. example, this haxe code:
>
> |
> if(r)
> {
> trace("Hello World !");
> }
> else
> {
> trace("Hello World 2!");
> }
> |
>
> on multiple lines will generate the following javascript code: (note
> that it is on a single line):
>
> |
> |*if(r)console.log("Hello World !");elseconsole.log("Hello World 2!");*
> |
> |
>
> now the issue with that is when debugging with source mappings in
> chrome, the breakpoints will not go to |trace("Hello World !");
> or ||trace("Hello World 2!");depending on runtime branching because the
> underlying javascript is on a single line, so the breakpoint sticks to
> the "if" line.
>
> was wondering if there was an option to tell the compiler to stick to
> the format of the haxe code when generating target code? in short,
> expecting this javascript:
> |
> |
> |*if(r){
> console.log("Hello World !");
> }
> else{
> console.log("Hello World 2!");*
> }
> |
> |
> |
> thanks
>
> |
>
> --
> 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/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages