View Source Styler.AliasEnv (Styler v1.5.0)

A datastructure for maintaining something like compiler alias state when traversing AST.

Not anywhere as correct as what the compiler gives us, but close enough for open source work.

An alias env is a map from an alias's as to its resolution in a context.

Given the ast for

alias Foo.Bar

we'd create the env:

%{:Bar => [:Foo, :Bar]}

Summary

Functions

Expands modules from env (wow that was helpful).

Lengthens an alias to its full name, if its first name is defined in the environment"

An inverted AliasEnv is useful for translating a module to its alias, if one existed in the env

Functions

Expands modules from env (wow that was helpful).

Using the examples from expand_ast, this works roughly like so:

expand(%{Foo: [Bar, Baz, Foo]}, [Foo, Woo, Cool]) => [Bar, Baz, Foo, Woo, Cool] expand(%{}, [No, Alias, For, Me]) => [No, Alias, For, Me]

Lengthens an alias to its full name, if its first name is defined in the environment"

Useful for transforming the ast for code like:

alias Bar.Baz.Foo #<- given the env with this alias
Foo.Woo.Cool # <- ast

to the ast for code like:

alias Bar.Baz.Foo
Bar.Baz.Foo.Woo.Cool

An inverted AliasEnv is useful for translating a module to its alias, if one existed in the env

In the case that a module is aliased multiple times, the inverted env will only keep the final alias as lexically sorted