Lavash.Component.CompilerHelpers (Lavash v0.3.0-rc.3)

Copy Markdown View Source

Shared compiler utilities for Lavash components.

Summary

Functions

Converts an Elixir function source to a JS expression for item-level transformations.

Gets the target directory for colocated hooks/JS.

Whether an Ash resource module is compiled and available.

Functions

fn_source_to_js_item_transform(source)

Converts an Elixir function source to a JS expression for item-level transformations.

Used for key-based array mutations (map_by) where the function receives an item and value, and returns an updated item (or :remove).

Examples

fn_source_to_js_item_transform("fn item, _id -> %{item | quantity: item.quantity + 1} end")
# => "({...item, quantity: item.quantity + 1})"

get_target_dir()

Gets the target directory for colocated hooks/JS.

Matches Phoenix's logic for the target directory, checking the :phoenix_live_view config for :colocated_js settings.

resource_available?(resource)

Whether an Ash resource module is compiled and available.

Uses Code.ensure_compiled/1 (which waits for parallel compilation to finish) rather than Code.ensure_loaded?/1. Safe for use from transformers because Ash resources never depend on Lavash LiveViews/Components — no circular-dependency risk.