Is decorator can only be defined by rescript internal? How to defined our own decorator?
I guess what you are asking for is how to write a “syntax extension”.
This is a (natively compiled) program that will take the parsed AST from your source code and rewrites the AST based on specific logic. This is more commonly known as a “PPX”, e.g. there’s the graphql-ppx or rescript-relay ppx.
There are a few challenges related to syntax extensions though:
- You need to know a lot of OCaml and have a good understanding of ASTs
- We don’t offer a curated way of writing ReScript syntax extensions yet (there were plans to expose a particular OPAM package for the compiler utils and write explicit docs to streamline this)
- Adding syntax extensions may make your compilation processes slower, depending on the number and complexity of your extensions
We don’t actively advertise syntax extensions until there’s a curated path. It’s definitely a more advanced topic.