MCPcopy Index your code
hub / github.com/getsentry/sentry / getJsxAttributeExpression

Method getJsxAttributeExpression

scripts/extractFormFields.ts:398–431  ·  view source on GitHub ↗

* Get the expression text of a JSX attribute as-is (preserves t() calls) * Used for 'label' and 'hintText' where we want the full expression

(
    node: ts.JsxElement | ts.JsxSelfClosingElement,
    attributeName: string,
    sourceFile: ts.SourceFile
  )

Source from the content-addressed store, hash-verified

396 * Used for 'label' and 'hintText' where we want the full expression
397 */
398 private getJsxAttributeExpression(
399 node: ts.JsxElement | ts.JsxSelfClosingElement,
400 attributeName: string,
401 sourceFile: ts.SourceFile
402 ): string | null {
403 const attributes = ts.isJsxElement(node)
404 ? node.openingElement.attributes
405 : node.attributes;
406
407 for (const attr of attributes.properties) {
408 if (
409 ts.isJsxAttribute(attr) &&
410 ts.isIdentifier(attr.name) &&
411 attr.name.text === attributeName
412 ) {
413 if (attr.initializer) {
414 // String literal: label="Name"
415 if (ts.isStringLiteral(attr.initializer)) {
416 return `"${attr.initializer.text}"`;
417 }
418 // JSX expression: label={t('Name')} -> t('Name')
419 if (ts.isJsxExpression(attr.initializer) && attr.initializer.expression) {
420 const expr = attr.initializer.expression;
421 if (!isStringTypeExpression(expr)) {
422 return null;
423 }
424 return expr.getText(sourceFile);
425 }
426 }
427 }
428 }
429
430 return null;
431 }
432}
433
434function generateRegistryFile(fields: ExtractedField[], outputPath: string): void {

Callers 1

visitMethod · 0.95

Calls 1

isStringTypeExpressionFunction · 0.85

Tested by

no test coverage detected