Lavash.Template.ASTTransformer (Lavash v0.3.0-rc.5)

Copy Markdown View Source

Transforms compiled HEEx template AST to inject Lavash-specific attributes.

This module post-processes the AST generated by Phoenix's ~H sigil to:

  • Inject __lavash_client_bindings__ into <.lavash_component> calls

This operates on the compiled AST, making it robust and compatible with all HEEx features.

How it works

After ~H compiles a template, the AST contains component calls as maps with keys like :module, :id, :__changed__. We use Macro.prewalk/2 to find these maps and inject additional assigns.

Usage

This is automatically applied via @before_compile in Lavash.Component.Compiler. You don't need to call this directly.

Summary

Functions

Transforms an AST to inject __lavash_client_bindings__ into component calls.

Functions

inject_client_bindings(ast)

Transforms an AST to inject __lavash_client_bindings__ into component calls.

Component call maps are identified by having :module and :id keys. If they don't already have __lavash_client_bindings__, we inject it with the value assigns.__lavash_client_bindings__.