Transformer for converting switch cases to simple ifelse blocks so luau can better optimize them
npm install rbxts-transformer-switchcasets
let a = 2
switch (a) {
case 1:
print("one");
break;
case 2:
print("two");
break;
default:
print("uhh what??");
break;
}
`
lua
local a = 2
repeat
if a == 1 then
print("one")
break
end
if a == 2 then
print("two")
break
end
print("uhh what??")
break
until true
`
lua
local a = 2
-- switch
if a == 1 then
print("one")
-- break
elseif a == 2 then
print("two")
-- break
else
print("uhh what??")
-- break
end
`
1. Add it as a plugin to your tsconfig.json, see options here
`json
{
"compilerOptions": {
...
"plugins": [
{
"transform": "rbxts-transformer-switchcase",
...
}
]
}
}
`
1. Try it out
Settings
In the tsconfig.json you can add settings for the plugin.
Example
`json
{
"compilerOptions": {
...
"plugins": [
{
"transform": "rbxts-transformer-switchcase",
"disableSwitchComments": false,
"disableBreakComments": true
}
]
}
}
`
| Identifier | Type | Default | Description |
| -: | :-: | :-: | - |
| disableSwitchComments | boolean | false | whether or not --switch should be added in front of if statements generated by the transformer |
| disableBreakComments | boolean | false | whether or not removed break statements should get a --break in their place |
Building
$3
Install dependencies using npm i.
$3
Run npm run build in the root of the project.
$3
Run npm run build in /example.
$3
Run npm run test for quick and simple tests and npm run test:fancy` for more readable results.