DEV Community

SieR
SieR

Posted on

Stop Using "AST" Directly

This is my first post on dev.to! Hello everyone!

Hello!

I'm making tool for typescript transform named "transformer-query", which can query typescript AST and able to change its structure more intuitively. Despite it is still developing, I wanted to share my concept.

Why not "AST"?

As with any programming language, ASTs are complex. The AST corresponds to the grammar, but has additional information. That's why interacting with the AST was complicated. Typescript wasn't exception.

What is "transformer-query"?

Here's repository: transformer-query (still no readme, complicated code)

It provides more intuitive way for interacting with ASTs.
Thanks for ttypescript, this made it easy to develop this library.

How to use

Image description

makeTransform() returns ttypescript transform function. So, we can use like that.

Query should be tagged string literal. And it accepts imported variable or interal wildcard.

And call chain, which appears next of query, can return valid typescript code or ts.Node interface.

That's it! after this, just register it with the method described on ttypescript.

Top comments (0)