Skip to content

Commit 13a67c6

Browse files
author
Luca Forstner
committed
move into babel plugin
1 parent 353a0e0 commit 13a67c6

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ interface AnnotationPluginPass extends PluginPass {
5757

5858
type AnnotationPlugin = PluginObj<AnnotationPluginPass>;
5959

60+
const DEFAULT_IGNORED_REACT_COMPONENTS = ["Fragment"];
61+
6062
// We must export the plugin as default, otherwise the Babel loader will not be able to resolve it when configured using its string identifier
6163
export default function componentNameAnnotatePlugin({ types: t }: typeof Babel): AnnotationPlugin {
6264
return {
@@ -69,14 +71,21 @@ export default function componentNameAnnotatePlugin({ types: t }: typeof Babel):
6971
return;
7072
}
7173

74+
const ignoredComponents = [
75+
...new Set([
76+
...(state.opts.ignoredComponents ?? []),
77+
...DEFAULT_IGNORED_REACT_COMPONENTS,
78+
]),
79+
];
80+
7281
functionBodyPushAttributes(
7382
state.opts["annotate-fragments"] === true,
7483
t,
7584
path,
7685
path.node.id.name,
7786
sourceFileNameFromState(state),
7887
attributeNamesFromState(state),
79-
state.opts.ignoredComponents ?? []
88+
ignoredComponents
8089
);
8190
},
8291
ArrowFunctionExpression(path, state) {
@@ -97,14 +106,21 @@ export default function componentNameAnnotatePlugin({ types: t }: typeof Babel):
97106
return;
98107
}
99108

109+
const ignoredComponents = [
110+
...new Set([
111+
...(state.opts.ignoredComponents ?? []),
112+
...DEFAULT_IGNORED_REACT_COMPONENTS,
113+
]),
114+
];
115+
100116
functionBodyPushAttributes(
101117
state.opts["annotate-fragments"] === true,
102118
t,
103119
path,
104120
parent.id.name,
105121
sourceFileNameFromState(state),
106122
attributeNamesFromState(state),
107-
state.opts.ignoredComponents ?? []
123+
ignoredComponents
108124
);
109125
},
110126
ClassDeclaration(path, state) {
@@ -118,7 +134,12 @@ export default function componentNameAnnotatePlugin({ types: t }: typeof Babel):
118134
return;
119135
}
120136

121-
const ignoredComponents = state.opts.ignoredComponents ?? [];
137+
const ignoredComponents = [
138+
...new Set([
139+
...(state.opts.ignoredComponents ?? []),
140+
...DEFAULT_IGNORED_REACT_COMPONENTS,
141+
]),
142+
];
122143

123144
render.traverse({
124145
ReturnStatement(returnStatement) {

packages/babel-plugin-component-annotate/src/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"extends": "@sentry-internal/sentry-bundler-plugin-tsconfig/base-config.json",
44
"include": ["./**/*", "../package.json"],
55
"compilerOptions": {
6-
"esModuleInterop": true
6+
"esModuleInterop": true,
7+
"target": "ES2020" // es2020 needed for "new Set()"
78
}
89
}

packages/bundler-plugin-core/src/options-mapping.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ export type NormalizedOptions = ReturnType<typeof normalizeUserOptions>;
66

77
export const SENTRY_SAAS_URL = "https://sentry.io";
88

9-
const DEFAULT_IGNORED_REACT_COMPONENTS = ["Fragment"];
10-
119
export function normalizeUserOptions(userOptions: UserOptions) {
1210
const options = {
1311
org: userOptions.org ?? process.env["SENTRY_ORG"],
@@ -30,17 +28,7 @@ export function normalizeUserOptions(userOptions: UserOptions) {
3028
vcsRemote: userOptions.release?.vcsRemote ?? process.env["SENTRY_VSC_REMOTE"] ?? "origin",
3129
},
3230
bundleSizeOptimizations: userOptions.bundleSizeOptimizations,
33-
reactComponentAnnotation: userOptions.reactComponentAnnotation
34-
? {
35-
enabled: userOptions.reactComponentAnnotation?.enabled ?? false,
36-
ignoredComponents: [
37-
...new Set([
38-
...(userOptions.reactComponentAnnotation?.ignoredComponents ?? []),
39-
...DEFAULT_IGNORED_REACT_COMPONENTS,
40-
]),
41-
],
42-
}
43-
: undefined,
31+
reactComponentAnnotation: userOptions.reactComponentAnnotation,
4432
_metaOptions: {
4533
telemetry: {
4634
metaFramework: userOptions._metaOptions?.telemetry?.metaFramework,

0 commit comments

Comments
 (0)