docs
evals
scenario-1
scenario-10
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
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.
"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"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. @testcaseSensitive: true, resolving "data-id" does not match "DATA-id"; by default, casing is ignored and either spelling matches. @test<Button {...props} /> are present, or when the prop is missing entirely, returns source: "absent" with attribute and value undefined. @testtype 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;Utilities for inspecting JSX AST nodes, including resolving props that originate from object-literal spread attributes. @satisfied-by