Function swc_ecma_transforms::resolver::resolver_with_mark
source · [−]Expand description
See Ident for know how does swc manages identifiers.
When to run
The resolver expects ‘clean’ ast. You can get clean ast by parsing, or by removing all syntax context in ast nodes.
What does it do
Firstly all scopes (fn, block) has it’s own SyntaxContext. Resolver visits all identifiers in module, and look for binding identifies in the scope. Those identifiers now have the SyntaxContext of scope (fn, block). While doing so, resolver tries to resolve normal identifiers (no hygiene info) as a reference to identifier of scope. If the resolver find suitable variable, the identifier reference will have same context as the variable.
Panics
top_level_mark
should not be root.
Example
let a = 1;
{
let a = 2;
use(a);
}
use(a)
resolver does
-
Define
a
with top level context. -
Found a block, so visit block with a new syntax context.
-
Defined
a
with syntax context of the block statement. -
Found usage of
a
, and determines that it’s reference toa
in the block. So the reference toa
will have same syntax context asa
in the block. -
Found usage of
a
(last line), and determines that it’s a reference to top-levela
, and change syntax context ofa
on last line to top-level syntax context.