Skip to content

Commit 0e5c99c

Browse files
antonisclaude
andcommitted
fix(babel): Extract text from non-text wrapper elements inside text components
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 7d8f775 commit 0e5c99c

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

packages/babel-plugin-component-annotate/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,7 @@ function extractTextFromTextComponent(
790790
if (innerTexts === null) {
791791
return null;
792792
}
793+
texts.push(...innerTexts);
793794
}
794795
} else if (t.isJSXFragment(child)) {
795796
const innerTexts = extractTextFromTextComponent(t, child, textComponentNames);

packages/babel-plugin-component-annotate/test/sentry-label.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -571,20 +571,20 @@ describe("autoInjectSentryLabel", () => {
571571
expect(result?.code).toContain('"sentry-label": "Hello World more"');
572572
});
573573

574-
it("handles Text wrapping only a non-text element", () => {
574+
it("extracts text from non-text wrapper inside Text", () => {
575575
const result = transformWith(`
576576
import React from 'react';
577577
import { Text, View } from 'react-native';
578578
579579
export default function MyComponent() {
580580
return (
581581
<View>
582-
<Text><Bold>hello</Bold></Text>
582+
<Text>Hello <Bold>world</Bold></Text>
583583
</View>
584584
);
585585
}
586586
`);
587-
expect(result?.code).not.toContain("sentry-label");
587+
expect(result?.code).toContain('"sentry-label": "Hello world"');
588588
});
589589
});
590590

0 commit comments

Comments
 (0)