rbxts-transformer-switchcase
v1.0.1
Published
Transformer for converting switch cases to simple ifelse blocks so luau can better optimize them
Downloads
6
Maintainers
Readme
rbxts-transformer-switchcase
Converts switch cases into simple if else blocks, to make it faster and to make it more legible.
Example
let a = 2
switch (a) {
case 1:
print("one");
break;
case 2:
print("two");
break;
default:
print("uhh what??");
break;
}
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
local a = 2
-- switch
if a == 1 then
print("one")
-- break
elseif a == 2 then
print("two")
-- break
else
print("uhh what??")
-- break
end
How to use
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
Settings
In the tsconfig.json
you can add settings for the plugin.
{
"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
Setup
Install dependencies using npm i
.
Build the transformer
Run npm run build
in the root of the project.
Build the example
Run npm run build
in /example
.
Run tests
Run npm run test
for quick and simple tests and npm run test:fancy
for more readable results.