Member-only story
Revealing the magic of AST by writing babel plugins

When you hear Abstract syntax trees, what is the first thought that occurs in your mind?
Something to do with compilers? Some complex tree manipulation? Bit manipulations? 🤔
At the beginning of my career, this AST seemed like a complex term with low level compilers and transpilers magic sprinkled in it.
💡 Motivation
The motivation behind writing this blog is to make it easy for everyone to understand what Abstract syntax trees are and how they play an important part in most of the tools we use on a daily basis.
Be it babel, webpack, parcel, eslint, codemods, css parsers, css in js — all of these tools use the magic of AST’s to manipulate our code and transform it into something else.
In this post, we will unravel this magic and in the process learn to write some super simple babel plugins. Yeah 🎉
🤔 What is an AST?
Like every new concept, we will start with a concrete definition.
According to wikipedia
An abstract syntax tree is a tree representation of source code written in a programming language. Each node of the tree denotes a construct occurring in the source code.