compiler/docs/DESIGN_GOALS.md
This document describes the goals, design principles, and high-level architecture of React Compiler. See the code for specifics of the data structures and compiler passes.
The idea of React Compiler is to allow developers to use React's familiar declarative, component-based programming model, while ensuring that apps are fast by default. Concretely we seek to achieve the following goals:
The following are explicitly not goals for React Compiler:
eval() is unsafe. We aim to support the vast majority of JavaScript code (and the TypeScript and Flow dialects)Many aspects of the design follow naturally from the above goals:
a ?? b) into an if statement, we retain the high-level form of the logical expression. Rather than convert all looping constructs to a single form, we retain the original form of the loop. This follows from our goals:
React Compiler has two primary public interfaces: a Babel plugin for transforming code, and an ESLint plugin for reporting violations of the Rules of React. Internally, both use the same core compiler logic.
The core of the compiler is largely decoupled from Babel, using its own intermediate representations. The high-level flow is as follows:
The ESLint plugin works similarly. For now, it effectively invokes the Babel plugin on the code and reports back a subset of the errors. The compiler can report a variety of errors, including that the code is simply invalid JavaScript, but the ESLint plugin filters to only show the React-specific errors.