Converts switch cases into simple if else blocks, to make it faster and to make it more legible.
Input typescript
let a = 2
switch (a) {
case 1:
print("one");
break;
case 2:
print("two");
break;
default:
print("uhh what??");
break;
}Output luau without the transformer
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 trueOutput luau with the transformer
local a = 2
-- switch
if a == 1 then
print("one")
-- break
elseif a == 2 then
print("two")
-- break
else
print("uhh what??")
-- break
end-
Install by running
npm i rbxts-transformer-switchcase --save-dev -
Add it as a plugin to your
tsconfig.json, see options here{ "compilerOptions": { ... "plugins": [ { "transform": "rbxts-transformer-switchcase", ... } ] } } -
Try it out
In the tsconfig.json you can add settings for the plugin.
Example
{
"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 |
Install dependencies using npm i.
Run npm run build in the root of the project.
Run npm run build in /example.
Run npm run test for quick and simple tests and npm run test:fancy for more readable results.