MCPcopy Create free account
hub / github.com/getsentry/sentry / extractFromRenderProp

Method extractFromRenderProp

scripts/extractFormFields.ts:225–274  ·  view source on GitHub ↗
(
    arrowFn: ts.ArrowFunction,
    sourceFile: ts.SourceFile
  )

Source from the content-addressed store, hash-verified

223 }
224
225 private extractFromRenderProp(
226 arrowFn: ts.ArrowFunction,
227 sourceFile: ts.SourceFile
228 ): Partial<ExtractedField> {
229 const metadata: Partial<ExtractedField> = {};
230
231 // Traverse arrow function body to find label and hintText
232 const visit = (node: ts.Node) => {
233 if (ts.isJsxElement(node) || ts.isJsxSelfClosingElement(node)) {
234 const tagName = this.getJsxTagName(node, sourceFile);
235
236 // Extract label/hintText props from any component
237 const label = this.getJsxAttributeExpression(node, 'label', sourceFile);
238 if (label && !metadata.label) {
239 metadata.label = label;
240 }
241
242 if (this.hasJsxAttribute(node, 'hintText') && !metadata.hintText) {
243 const hintText = this.getJsxAttributeExpression(node, 'hintText', sourceFile);
244 // Attribute present but non-string → serialize as empty string
245 metadata.hintText = hintText ?? "''";
246 }
247
248 // Extract label from Meta.Label (text is in children)
249 if (tagName?.endsWith('.Label') || tagName === 'Meta.Label') {
250 const text = this.getJsxTextContent(node, sourceFile);
251 if (text && !metadata.label) {
252 metadata.label = text;
253 }
254 }
255
256 // Extract hintText from Meta.HintText (text is in children)
257 if (tagName?.endsWith('.HintText') || tagName === 'Meta.HintText') {
258 if (!metadata.hintText) {
259 const text = this.getJsxTextContent(node, sourceFile);
260 // Tag present but non-string content → serialize as empty string
261 metadata.hintText = text ?? "''";
262 }
263 }
264 }
265
266 ts.forEachChild(node, visit);
267 };
268
269 if (arrowFn.body) {
270 visit(arrowFn.body);
271 }
272
273 return metadata;
274 }
275
276 /**
277 * Extract text content from JSX element children as expression (for Meta.Label, Meta.HintText)

Callers 1

extractFieldMetadataMethod · 0.95

Calls 1

visitFunction · 0.70

Tested by

no test coverage detected