Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

How does babeljs change syntax in javascript?


Asked by Corinne Figueroa on Nov 30, 2021 JavaScript



BabelJS is a javascript compiler that changes the syntax of the code given based on presets and plugins available. The flow of babel compilation involves the following 3 parts − The code given to babel is given back as it is with just the syntax changed.
Additionally,
Babel can convert JSX syntax! Check out our React preset to get started. Use it together with the babel-sublime package to bring syntax highlighting to a whole new level. and add @babel/preset-react to your Babel configuration. Babel can strip out type annotations!
And, With Babel, developers can write their code using the new features in JavaScript. The users can get the codes transpiled using Babel; the codes can later be used in any browsers without any issues.
In this manner,
BabelJS also works along with react JSX syntax and can be compiled in JSX form. BabelJS has support for plugins, polyfills, babel-cli that makes it easy to work with big projects. BabelJS code changes the syntax while transpiling which makes the code difficult to understand when released on production.
Thereof,
The tokens then pass through a parser for Syntax analysis, where babel creates an AST based on JavaScript language specification. If you want to learn more in-depth on compilers in general, Robert Nystrom 's Crafting Interpreters is a gem.