3 ms·
Babel, the defacto JSX (and ES2015+ syntax) "compiler" has basically become a general purpose AST manipulation engine. Pretty much everything it actually "does
by zdragnar 8y ago
Babel, the defacto JSX (and ES2015+ syntax) "compiler" has basically become a general purpose AST manipulation engine.
Pretty much everything it actually "does" for your code is implemented as a plugin, and writing new plugins is relatively trivial if you're familiar with the AST objects and concepts.
Call it macro or AST manipulation, the effect is the same; the language becomes practically infinitely malleable. The only real limits to what JS+Babel can express are those imposed by the host environment (aka DOM APIs, no manual memory mangement, etc.).
To specifically address your last question regarding JSX:
Code such as `<MyComponent attribute={value}>Child Contents</MyComponent` becomes something like `createElement(MyComponent, { attribute: value}, ["Child Contents"])` (sorry, I'm going off of memory here).
The transformation is applied by Babel, so it's parsed from the file as a string, transformed into an AST (with the help of the JSX plugin), and re-written back out as vanilla JavaScript to be executed by your browser / server process.