optimize Plugin
Use xray16/plugins/optimize to rewrite returned ternary expressions into direct Lua if / else returns.
Default TypeScriptToLua output for return condition ? first : second introduces a temporary local. This plugin avoids that local while preserving ternary behavior. It has no configuration.
ts
export function pick(value: boolean): number {
return value ? 1 : 2;
}lua
function ____exports.pick(self, value)
if value then
return 1
else
return 2
end
endBehavior
- Only
returnstatements are affected. - Nested ternaries in return branches are expanded recursively.
- Parentheses,
asassertions, angle-bracket assertions, non-null assertions, andsatisfiesare unwrapped before checking for a ternary. - Branch expressions that emit preceding statements keep those statements inside the matching branch.
- Assignment compatibility against the function return type is still checked.
Limitations
- Ternaries whose branches return Lua multiple values (
LuaMultiReturn) are left to the default TypeScriptToLua transform. Those still emit the standardunpack(condition and ({...}) or ({...}))form.