Most basic online code editors use simple Regular Expressions to format code. They look for curly braces {} and add indentation. This approach falls apart instantly when faced with complex ES6 template literals, nested JSX, or ternary operators. Regex cannot understand context.
NitroIDE implements true, context-aware code formatting by leveraging the Babel parser to generate an Abstract Syntax Tree (AST). We don't format strings; we manipulate the underlying logical structure of the code.
When you press Cmd + Shift + F, the editor sends the raw string to a Web Worker. Babel parses the string into an enormous JSON tree representing every variable, function, and operator. We then traverse this tree, applying formatting rules to the nodes themselves, before generating a new, perfectly formatted string.
Destructive Transformations: Because we operate on the AST, we can safely perform destructive actions like removing unused imports or rewriting arrow functions, with mathematical certainty that we won't break the actual execution logic.
Because AST generation is CPU-intensive, running it on the main thread would freeze the editor. By executing the Babel traversal inside a SharedWorker, NitroIDE can format a 10,000-line React component in the background while you continue typing, applying the update seamlessly once complete.
Paste ugly, unformatted React code into our sandbox and watch the AST engine fix it.
Launch React Sandbox