Juggernaut.Mutator.AST (Juggernaut v0.4.0)

Copy Markdown View Source

Helpers over Sourceror's AST (docs/dependencies/sourceror.md).

Sourceror wraps every literal in a one-element :__block__ (1 is {:__block__, [token: "1", ...], [1]}); a two-element tuple is wrapped the same way. These helpers build and read such literals, resolve aliases, compare nodes without their metadata and render a node back to source.

Summary

Functions

The module an __aliases__ node names, with the module's aliases expanded.

node with all metadata removed, for structural comparison.

The elements of a list literal, or :error.

A literal node, wrapped as Sourceror wraps literals.

Whether node is a wrapped literal for which guard holds.

The value of a wrapped literal, or :error for any other node.

Whether node is a variable whose name does not start with _.

Renders node to source with the Elixir formatter, without reading the project's .formatter.exs and without comments.

Whether two nodes are equal apart from metadata.

node without comment metadata, so rendering never re-emits comments.

A tuple node of elements, keeping the metadata of original when given.

The elements of a tuple literal ({a, b} or {a, b, c}), or :error.

Whether node is a variable (any name, _ included).

Functions

alias_module(arg1, aliases, current)

@spec alias_module(Macro.t(), %{required([atom()]) => module()}, module() | nil) ::
  {:ok, module()} | :error

The module an __aliases__ node names, with the module's aliases expanded.

bare(node)

@spec bare(Macro.t()) :: Macro.t()

node with all metadata removed, for structural comparison.

list_elements(arg1)

@spec list_elements(Macro.t()) :: {:ok, [Macro.t()]} | :error

The elements of a list literal, or :error.

literal(value)

@spec literal(term()) :: Macro.t()

A literal node, wrapped as Sourceror wraps literals.

literal?(node, guard)

@spec literal?(Macro.t(), (term() -> boolean())) :: boolean()

Whether node is a wrapped literal for which guard holds.

literal_value(arg1)

@spec literal_value(Macro.t()) :: {:ok, term()} | :error

The value of a wrapped literal, or :error for any other node.

named_var?(node)

@spec named_var?(Macro.t()) :: boolean()

Whether node is a variable whose name does not start with _.

render(node)

@spec render(Macro.t()) :: String.t()

Renders node to source with the Elixir formatter, without reading the project's .formatter.exs and without comments.

same?(left, right)

@spec same?(Macro.t(), Macro.t()) :: boolean()

Whether two nodes are equal apart from metadata.

strip_comments(node)

@spec strip_comments(Macro.t()) :: Macro.t()

node without comment metadata, so rendering never re-emits comments.

tuple(elements, meta \\ [])

@spec tuple([Macro.t()], keyword()) :: Macro.t()

A tuple node of elements, keeping the metadata of original when given.

tuple_elements(arg1)

@spec tuple_elements(Macro.t()) :: {:ok, [Macro.t()]} | :error

The elements of a tuple literal ({a, b} or {a, b, c}), or :error.

var?(arg1)

@spec var?(Macro.t()) :: boolean()

Whether node is a variable (any name, _ included).