scriptsharp icon indicating copy to clipboard operation
scriptsharp copied to clipboard

Optimisation bug with subtracting negative numbers

Open stevehobbsdev opened this issue 13 years ago • 4 comments

I just came across this scenario with a piece of code of ours. The following (valid) C# code:

int number = somevar - -10; // legitimately subtracting a negative number

.. becomes this, when optimised and minified in Javascript:

var $a=somevar--10;

.. which is invalid, both in C# and Javascript. The code works when using the debug script, but it doesn't when minified, causing a discrepency between the two scripts. I think this is maybe more of an issue with the minifier being used thought, just thought I'd make you aware.

stevehobbsdev avatar Nov 29 '12 16:11 stevehobbsdev

Is this with 0.8 or older builds? In the new minimizer I'd expect it gets simplified at minimization time to be +10.

nikhilk avatar Nov 29 '12 16:11 nikhilk

Ah, yes this is with 0.7.5.

stevehobbsdev avatar Nov 29 '12 16:11 stevehobbsdev

Looks like the new minimizer doesn't convert to +10 but it does leave the code as somevar- -10. so it shouldn't result in invalid code. Marking as fixed (for 0.8).

nikhilk avatar Dec 09 '12 02:12 nikhilk

Nice one. It was just the removal of the spaces in between the minus operator that was causing the problem, so as long as that remains intact, it should be fine.

stevehobbsdev avatar Dec 12 '12 12:12 stevehobbsdev