Skip to content

Commit 7d8f775

Browse files
antonisclaude
andcommitted
refactor(babel): Combine autoInjectSentryLabel and textComponentNames into single option
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent e20692b commit 7d8f775

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,16 @@ const MAX_LABEL_LENGTH = 64;
5050
const DEFAULT_TEXT_COMPONENT_NAMES = ["Text", "text"];
5151
const MAX_TEXT_SEARCH_DEPTH = 3;
5252

53+
interface AutoInjectSentryLabelOpts {
54+
textComponentNames?: string[];
55+
}
56+
5357
interface AnnotationOpts {
5458
native?: boolean;
5559
"annotate-fragments"?: boolean;
5660
ignoredComponents?: string[];
57-
autoInjectSentryLabel?: boolean;
58-
textComponentNames?: string[];
61+
/** @hidden */
62+
autoInjectSentryLabel?: boolean | AutoInjectSentryLabelOpts;
5963
}
6064

6165
interface FragmentContext {
@@ -181,8 +185,11 @@ function createJSXProcessingContext(
181185
attributeNames: attributeNamesFromState(state),
182186
ignoredComponents: state.opts.ignoredComponents ?? [],
183187
fragmentContext: state.sentryFragmentContext,
184-
autoInjectSentryLabel: state.opts.autoInjectSentryLabel === true,
185-
textComponentNames: state.opts.textComponentNames ?? DEFAULT_TEXT_COMPONENT_NAMES,
188+
autoInjectSentryLabel: !!state.opts.autoInjectSentryLabel,
189+
textComponentNames:
190+
(typeof state.opts.autoInjectSentryLabel === "object"
191+
? state.opts.autoInjectSentryLabel.textComponentNames
192+
: undefined) ?? DEFAULT_TEXT_COMPONENT_NAMES,
186193
};
187194
}
188195

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ describe("autoInjectSentryLabel", () => {
468468
);
469469
}
470470
`,
471-
{ textComponentNames: ["Label", "Text"] }
471+
{ autoInjectSentryLabel: { textComponentNames: ["Label", "Text"] } }
472472
);
473473
expect(result?.code).toContain('"sentry-label": "Custom text"');
474474
});
@@ -930,7 +930,7 @@ describe("autoInjectSentryLabel", () => {
930930
);
931931
}
932932
`,
933-
{ textComponentNames: ["Text", "MyLib.Text"] }
933+
{ autoInjectSentryLabel: { textComponentNames: ["Text", "MyLib.Text"] } }
934934
);
935935
expect(result?.code).toContain('"sentry-label": "Matched"');
936936
});

0 commit comments

Comments
 (0)