Variable Management
SWC uses a very unique way to manage variables.
Syntax context
SWC uses a syntax context to manage variables. Internals are documented at the rustdoc of the resolver pass.
Basically the order of processing is like this. This processing should be wrapped by GLOBALS.set(&Default::default(), || { ... }).
resolveryour_pass(can be multiple passes)hygienefixer(Optional, but if your transform may produce invalid syntax, this would add necessary parentheses)
Terms
A private identifier is a identifier that is guaranteed to be unique, and it's renamed by the hygiene pass if there's a conflict.
Creating a private identifier
You can use Ident::new_private to create a private identifier. Note that this requires an access to GLOBALS, which is a scoped thread-local storage.
Full example
Full example:
