or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-10/

JSX Attribute Resolver

Implement a helper that resolves a named JSX prop from an opening element's attributes, even when the prop comes from object-literal spreads. The helper should identify whether the prop was declared directly or surfaced through a spread, and surface the found attribute node together with its literal value when one is available.

Capabilities

Returns direct attributes

  • Resolving "label" for attributes representing <Button label="Save" /> yields source: "direct", retains the original attribute node, and exposes the literal value "Save" in the result. @test

Reads object-literal spreads

  • Resolving "label" for attributes representing <Button {...{ label: 'Save', key: 'k1' }} /> yields source: "spread", produces an attribute node named "label" with a literal value "Save", and ignores the "key" property inside the spread. @test

Supports case sensitivity option

  • With caseSensitive: true, resolving "data-id" does not match "DATA-id"; by default, casing is ignored and either spelling matches. @test

Treats non-object spreads as unknown

  • Resolving any prop when only non-literal spreads like <Button {...props} /> are present, or when the prop is missing entirely, returns source: "absent" with attribute and value undefined. @test

Implementation

@generates

API

type AttributeNode = JSXAttribute | JSXSpreadAttribute;

interface ResolveOptions {
  /** When true, matching is case-sensitive. Default: false. */
  caseSensitive?: boolean;
}

type ResolveSource = 'direct' | 'spread' | 'absent';

interface ResolveResult {
  source: ResolveSource;
  attribute?: JSXAttribute;
  /** Literal primitive when available, otherwise the attribute's expression node. */
  value?: unknown;
}

/**
 * Resolves a named prop from a JSX opening element's attributes,
 * honoring object-literal spreads and ignoring unknown spread sources.
 */
export function resolveJsxAttribute(
  attributes: AttributeNode[],
  propName: string,
  options?: ResolveOptions
): ResolveResult;

Dependencies { .dependencies }

jsx-ast-utils { .dependency }

Utilities for inspecting JSX AST nodes, including resolving props that originate from object-literal spread attributes. @satisfied-by