or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-1/

Resilient JSX Prop Value Evaluation

A utility that reads JSX attribute values while staying resilient to unfamiliar expression node types.

Capabilities

Evaluate familiar expressions

  • A JSXAttribute for label="Hello" returns "Hello", and a JSXAttribute for count={4} returns 4. @test

Handle unknown expression nodes safely

  • A JSXAttribute whose value is a JSXExpressionContainer wrapping an ImportExpression triggers one log entry mentioning ImportExpression and returns null without throwing. @test

Keep scanning across mixed attributes

  • Given attributes for label="Hi" and data={ImportExpression}, the result map is { label: "Hi", data: null }, the logger is called once for the unsupported node, and evaluation continues without errors. @test

Implementation

@generates

API

/**
 * Evaluates a single JSXAttribute node into its JavaScript value.
 * @param {object} attributeNode - A JSXAttribute node with a value that may be a literal or an expression container.
 * @param {(message: string) => void} logger - A callback invoked when encountering unsupported expression node types.
 * @returns {unknown} JavaScript value for supported expressions, or null when unsupported.
 */
export function evaluatePropValue(attributeNode, logger);

/**
 * Evaluates multiple JSXAttribute nodes, returning a name-to-value map.
 * Unsupported nodes are logged and set to null without stopping evaluation of other attributes.
 * @param {object[]} attributeNodes - Array of JSXAttribute nodes to evaluate.
 * @param {(message: string) => void} logger - A callback invoked for each unsupported expression node type.
 * @returns {Record<string, unknown>} Map of attribute names to evaluated values (null for unsupported nodes).
 */
export function collectPropValues(attributeNodes, logger);

Dependencies { .dependencies }

jsx-ast-utils { .dependency }

Utilities for inspecting JSX attribute nodes and extracting their values without manual AST traversal.