rbxts-transformer-services
v1.1.1
Published
A transformer that converts @rbxts/services imports into plain GetService calls.
Downloads
282
Readme
rbxts-transformer-services
This is a demo transformer that converts @rbxts/services imports into plain GetService calls for increased legibility.
Example
// input.ts
import { Players, ServerScriptService } from "@rbxts/services";
print(Players.LocalPlayer);
print(ServerScriptService.GetChildren().size());
-- output.lua
local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
print(Players.LocalPlayer)
print(#ServerScriptService:GetChildren())
Template
This transformer is intended to be used as a template for those who are interested in creating their own transformers in roblox-ts.
A necessary resource for those starting out with transformers is ts-ast-viewer. It shows you the result of AST, relevant properties, symbol information, type information and it automatically generates factory code for nodes. For example, you can see the code this transformer generates here.
I'd also recommend downloading the TypeScript repo locally as it's extremely helpful when you're using undocumented (the majority of the compiler API), internal or uncommon APIs.
Transformers mutate the TypeScript AST by replacing parts of the AST with new nodes. Transformers are also able to utilize symbol and type information giving you access to TypeScript's advanced control flow analysis.
Other Transformers
Here's a list of transformers if you want to see how they handle working with parts of the TypeScript compiler api not shown here (e.g symbols or types).
- rbxts-transform-debug by @roblox-aurora
- rbxts-transform-env by @roblox-aurora
- Flamework by @rbxts-flamework
One other source you may goto for learning about transformers is actually roblox-ts itself. This generates a Luau AST instead of a TS AST but it may still be a useful resource for learning about the compiler api.