codegenJsxAttribute() — react Function Reference
Architecture documentation for the codegenJsxAttribute() function in CodegenReactiveFunction.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD 44536f03_459c_da51_f8fc_8670b4e33ce0["codegenJsxAttribute()"] dc7f10c2_c914_a162_d02b_a10a15c64a5f["CodegenReactiveFunction.ts"] 44536f03_459c_da51_f8fc_8670b4e33ce0 -->|defined in| dc7f10c2_c914_a162_d02b_a10a15c64a5f d8edf87e_ea78_c9d0_b5c9_13d68891efec["codegenInstructionValue()"] d8edf87e_ea78_c9d0_b5c9_13d68891efec -->|calls| 44536f03_459c_da51_f8fc_8670b4e33ce0 0b424541_28a8_fc42_ac4b_b6ae2672cb88["codegenPlaceToExpression()"] 44536f03_459c_da51_f8fc_8670b4e33ce0 -->|calls| 0b424541_28a8_fc42_ac4b_b6ae2672cb88 d7fde76c_4fd9_feb3_299b_798689f05bc6["assertExhaustive()"] 44536f03_459c_da51_f8fc_8670b4e33ce0 -->|calls| d7fde76c_4fd9_feb3_299b_798689f05bc6 style 44536f03_459c_da51_f8fc_8670b4e33ce0 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts lines 2345–2400
function codegenJsxAttribute(
cx: Context,
attribute: JsxAttribute,
): t.JSXAttribute | t.JSXSpreadAttribute {
switch (attribute.kind) {
case 'JsxAttribute': {
let propName: t.JSXIdentifier | t.JSXNamespacedName;
if (attribute.name.indexOf(':') === -1) {
propName = createJsxIdentifier(attribute.place.loc, attribute.name);
} else {
const [namespace, name] = attribute.name.split(':', 2);
propName = createJsxNamespacedName(
attribute.place.loc,
createJsxIdentifier(attribute.place.loc, namespace),
createJsxIdentifier(attribute.place.loc, name),
);
}
const innerValue = codegenPlaceToExpression(cx, attribute.place);
let value;
switch (innerValue.type) {
case 'StringLiteral': {
value = innerValue;
if (
STRING_REQUIRES_EXPR_CONTAINER_PATTERN.test(value.value) &&
!cx.fbtOperands.has(attribute.place.identifier.id)
) {
value = createJsxExpressionContainer(value.loc, value);
}
break;
}
default: {
/*
* NOTE JSXFragment is technically allowed as an attribute value per the spec
* but many tools do not support this case. We emit fragments wrapped in an
* expression container for compatibility purposes.
* spec: https://github.com/facebook/jsx/blob/main/AST.md#jsx-attributes
*/
value = createJsxExpressionContainer(attribute.place.loc, innerValue);
break;
}
}
return createJsxAttribute(attribute.place.loc, propName, value);
}
case 'JsxSpreadAttribute': {
return t.jsxSpreadAttribute(
codegenPlaceToExpression(cx, attribute.argument),
);
}
default: {
assertExhaustive(
attribute,
`Unexpected attribute kind \`${(attribute as any).kind}\``,
);
}
}
}
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does codegenJsxAttribute() do?
codegenJsxAttribute() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts.
Where is codegenJsxAttribute() defined?
codegenJsxAttribute() is defined in compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts at line 2345.
What does codegenJsxAttribute() call?
codegenJsxAttribute() calls 2 function(s): assertExhaustive, codegenPlaceToExpression.
What calls codegenJsxAttribute()?
codegenJsxAttribute() is called by 1 function(s): codegenInstructionValue.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free