Operators such as '+=', '++', etc... can be broken easily right now.
Example 1:
declare function foo(): number;
declare const a: number[];
a[foo()]++;
=>
a[(foo())+1] = (a[(foo())+1]+1);
Here foo() will be called multiple times, producing possibly different values each time or having other undesired side-effects.
Example 2:
declare function bar(): number[];
let f = bar()[0]++;
=>
local f = (function()
local __originalValuebar()[(0)+1]0 = bar()[(0)+1];
bar()[(0)+1] = (bar()[(0)+1]+1);
return __originalValuebar()[(0)+1]0
end
)();
This one won't even compile in lua.
These kinds of issues could be solved by detecting if the value being operated on is a property and caching the object and index parts before performing the operation. This could be wrapped in specialized polyfill functions like the ternary operator is:
function __TS__PropertyPostInc(o, i)
local original = o[i]
o[i] = o[i] + 1
return original
end
--Example 1
__TS__PropertyPostInc(a, foo())
--Example 2
local f = __TS__PropertyPostInc(bar(), 0)
Operators such as '+=', '++', etc... can be broken easily right now.
Example 1:
=>
Here foo() will be called multiple times, producing possibly different values each time or having other undesired side-effects.
Example 2:
=>
This one won't even compile in lua.
These kinds of issues could be solved by detecting if the value being operated on is a property and caching the object and index parts before performing the operation. This could be wrapped in specialized polyfill functions like the ternary operator is: