Analysis of templ AST for tooling and framework development #586
tylermmorton
started this conversation in
General
Replies: 1 comment
-
I agree that this would be great for developing external tools, such as stricter formatters with rules that are too opinionated to be the defaults, and even security checkers. I do believe that the current parser package should be able to support this use case though I've not seen any examples yet. There could be some quality of life changes that would make this easier such as a |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The ability to inspect (and modify) component AST directly is a huge boon for tooling developers in the JSX/React world. This enables things like
prettier
andeslint
to format and lint code effectively. It also opens the door for code migration via AST (dubbed codemods), where transformations are run against UI codebases automatically.At another level, while building a MVC system, it may be helpful for the controller to inspect the view layer for certain properties. A great example of this is Remix's 'nested routes', where an
<Outlet/>
element is added in the view layer, and the controller layer then knows to look for that tag and handle the nesting logic.I wanted to bring this up as a topic of discussion, because to me, great support for static analysis is vital to so many parts of web development. FWIW
html/template
s have ParseTrees that enable this type of work.I will have to dig around in
a-h/templ/parse
package to see what is available. Is there a public API that is meant for this use case and are there any examples of tools being developed with it?Also I know that
templ
files are compiled at build time and converted into Go functions so all of the templ AST is unavailable during runtime. I'm wondering if there is a runtime variant of the compiler that could be used in situations where server frameworks need to inspect template structure?Thanks in advance for the discussion!
Beta Was this translation helpful? Give feedback.
All reactions