Function swc_ecma_transforms::resolver_with_mark[][src]

pub fn resolver_with_mark(top_level_mark: Mark) -> impl Fold + 'static

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.


top_level_mark should not be root.


let a = 1;
    let a = 2;

resolver does

  1. Define a with top level context.

  2. Found a block, so visit block with a new syntax context.

  3. Defined a with syntax context of the block statement.

  4. Found usage of a, and determines that it’s reference to a in the block. So the reference to a will have same syntax context as a in the block.

  5. Found usage of a (last line), and determines that it’s a reference to top-level a, and change syntax context of a on last line to top-level syntax context.