ocsigen/js_of_ocaml

Minifier variable renaming is buggy

nojb opened this issue · 7 comments

nojb commented

The source

a = function () { return 0 }
try { throw 1; } catch (xx) { a(0) }

gets minified to

a=function(){return 0};try{throw 1}catch(a){a(0)}

Seems related to #1318 (cc @vouillon)

hhugo commented

Is this bug with jsoo_minify only ? if so, the fix is #1351

nojb commented

Is this bug with jsoo_minify only ? if so, the fix is #1351

No, we detected a bug in the code generated by js_of_ocaml that is introduced in the minification phase (the bug is not present when using --pretty). We are trying to extract a small reproduction, but have been unsuccessful so far.

FYI, here's the excerpt of the generated code showing the code

...,bRn=function(d,c,b){var
e=d?d[1]:0,f=e?q(b,bRo):e;if(f)return f;function
a(c){return Ii(0,b)?1:0}if(c){var
g=c[1];try{_R(g,b)}catch(a){return a(0)}return 1}return a(0)},
...

the a in catch(a) is the compilation of a "try ... with _ -> ..."

hhugo commented

I was able to reproduce the isssue in #1351, (no fix yet)

hhugo commented

I've just pushed a possible fix in #1351, can you give it a try ?

It seems to fix the bug indeed. Thanks a lot !
I am not 100% sure though; the bug was fragile; we may get around the
bug because we assign the variable differently with your change.

hhugo commented

fixed by #1351