MCPcopy Create free account
hub / github.com/Snapchat/Valdi / outputJSXComponent

Method outputJSXComponent

compiler/companion/src/JSXProcessor.ts:955–1047  ·  view source on GitHub ↗
(
    jsxElement: JSXElement,
    output: JSXOutputState,
    transformContext: ts.TransformationContext,
    nodeTypeStr: string,
    attributeStatements: JSXAttributeStatements,
  )

Source from the content-addressed store, hash-verified

953 }
954
955 private outputJSXComponent(
956 jsxElement: JSXElement,
957 output: JSXOutputState,
958 transformContext: ts.TransformationContext,
959 nodeTypeStr: string,
960 attributeStatements: JSXAttributeStatements,
961 ): JSXNodeOutput {
962 let makeComponentPrototypeParams: ts.Expression[] = [];
963
964 if (attributeStatements.staticAttributesLiteral) {
965 makeComponentPrototypeParams.push(attributeStatements.staticAttributesLiteral);
966 }
967
968 const componentIdentifier = this.appendInitializedVariable(
969 '__component',
970 nodeTypeStr,
971 this.createRendererCallExpr('makeComponentPrototype', makeComponentPrototypeParams, transformContext),
972 output,
973 transformContext,
974 );
975
976 const componentRef = attributeStatements.nodeRef ?? transformContext.factory.createIdentifier('undefined');
977 if (jsxElement.nodeType.kind === ts.SyntaxKind.JsxNamespacedName) {
978 this.onError(jsxElement.nodeType, 'JSX Namespaced Names are not supported');
979 }
980 const beginRenderStatement = this.createRendererCall(
981 'beginComponent',
982 [
983 jsxElement.nodeType,
984 componentIdentifier,
985 attributeStatements.key || transformContext.factory.createIdentifier('undefined'),
986 componentRef,
987 ],
988 undefined,
989 transformContext,
990 );
991
992 const statements: ts.Statement[] = [];
993 statements.push(beginRenderStatement);
994
995 if (attributeStatements.componentContext) {
996 let foundComponentContext: boolean;
997 if (ts.isIdentifier(attributeStatements.componentContext)) {
998 foundComponentContext = attributeStatements.componentContext.text !== 'undefined';
999 } else {
1000 foundComponentContext = isExpressionNode(attributeStatements.componentContext);
1001 }
1002
1003 if (foundComponentContext) {
1004 const hasContextCallExpr = this.createRendererCallExpr('hasContext', [], transformContext);
1005 const setContextCall = this.createRendererCall(
1006 'setContext',
1007 [attributeStatements.componentContext],
1008 attributeStatements.componentContext,
1009 transformContext,
1010 );
1011
1012 const ifStatement = transformContext.factory.createIfStatement(

Callers 1

outputJSXMethod · 0.95

Calls 12

onErrorMethod · 0.95
createRendererCallMethod · 0.95
transformNodeMethod · 0.95
toExpressionMethod · 0.95
isExpressionNodeFunction · 0.90
createStringLiteralFunction · 0.85
isIdentifierMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected