liveBook · Manning

referencedAttributesInValueOf

As explained in Building User-Friendly DSLs

A book-specific query function that returns the distinct attributes referenced anywhere in an attribute's value expression.

referencedAttributesInValueOf returns the distinct attributes referenced by an attribute’s value expression. It supports dependency ordering before generated fields are initialized. section 9.3.4 section 11.4

The query’s implementation follows the value expression rather than assuming a single direct reference:

  • Read the attribute’s value expression and collect every Attribute Reference nested in its AST. section 11.4
  • Extract each reference’s target attribute, ignoring unresolved references that are not valid AST references. section 11.4 section 9.3.4
  • Remove duplicates so repeated references and multiple paths to one attribute produce one dependency. section 11.4

Computed rental values

A rental-price expression can reference two distinct attributes through three Attribute References. The query returns those two attributes once each, allowing dependencyOrderOf to place their generated fields safely. section 11.4 section 9.3.4

Listing 11.21 The reworked version of referencedAttributesInValueOf
const referencedAttributesInValueOf = (attribute) =>
     referencedAttributesIn(attribute.settings["value"])

This compact implementation delegates value-expression analysis to the generic referencedAttributesIn query. section 11.4

How Building User-Friendly DSLs covers it

How deep it goes
Explains direct references, nested binary expressions, deduplication, and generic AST traversal, but not traversal implementation details beyond depth-first visiting.
Examples
Uses Rental attributes, an initial attribute reference, and a computed expression containing repeated references to distinct attributes.
What it assumes
Assumes AST objects, attribute references, and generated attributes; teaches how dependency queries evolve from direct references to expressions.
What you can do after
Apply it via JavaScript AST queries to derive unique attribute dependencies for safe generated initialization.
How it connects
Connects attribute references, abstract syntax trees, binary operations, dependency ordering, and topological sorting.

This explainer was generated by Manning's knowledge graph from the text of Building User-Friendly DSLs. The section links point to the parts of the book it draws on.