diff --git a/packages/babel-plugin-component-annotate/src/index.ts b/packages/babel-plugin-component-annotate/src/index.ts index 0cd087d9..27d5b91f 100644 --- a/packages/babel-plugin-component-annotate/src/index.ts +++ b/packages/babel-plugin-component-annotate/src/index.ts @@ -57,6 +57,8 @@ interface AnnotationPluginPass extends PluginPass { type AnnotationPlugin = PluginObj; +const DEFAULT_IGNORED_REACT_COMPONENTS = ["Fragment"]; + // We must export the plugin as default, otherwise the Babel loader will not be able to resolve it when configured using its string identifier export default function componentNameAnnotatePlugin({ types: t }: typeof Babel): AnnotationPlugin { return { @@ -69,6 +71,13 @@ export default function componentNameAnnotatePlugin({ types: t }: typeof Babel): return; } + const ignoredComponents = [ + ...new Set([ + ...(state.opts.ignoredComponents ?? []), + ...DEFAULT_IGNORED_REACT_COMPONENTS, + ]), + ]; + functionBodyPushAttributes( state.opts["annotate-fragments"] === true, t, @@ -76,7 +85,7 @@ export default function componentNameAnnotatePlugin({ types: t }: typeof Babel): path.node.id.name, sourceFileNameFromState(state), attributeNamesFromState(state), - state.opts.ignoredComponents ?? [] + ignoredComponents ); }, ArrowFunctionExpression(path, state) { @@ -97,6 +106,13 @@ export default function componentNameAnnotatePlugin({ types: t }: typeof Babel): return; } + const ignoredComponents = [ + ...new Set([ + ...(state.opts.ignoredComponents ?? []), + ...DEFAULT_IGNORED_REACT_COMPONENTS, + ]), + ]; + functionBodyPushAttributes( state.opts["annotate-fragments"] === true, t, @@ -104,7 +120,7 @@ export default function componentNameAnnotatePlugin({ types: t }: typeof Babel): parent.id.name, sourceFileNameFromState(state), attributeNamesFromState(state), - state.opts.ignoredComponents ?? [] + ignoredComponents ); }, ClassDeclaration(path, state) { @@ -118,7 +134,12 @@ export default function componentNameAnnotatePlugin({ types: t }: typeof Babel): return; } - const ignoredComponents = state.opts.ignoredComponents ?? []; + const ignoredComponents = [ + ...new Set([ + ...(state.opts.ignoredComponents ?? []), + ...DEFAULT_IGNORED_REACT_COMPONENTS, + ]), + ]; render.traverse({ ReturnStatement(returnStatement) { diff --git a/packages/babel-plugin-component-annotate/src/tsconfig.json b/packages/babel-plugin-component-annotate/src/tsconfig.json index fd37e123..1933b4cb 100644 --- a/packages/babel-plugin-component-annotate/src/tsconfig.json +++ b/packages/babel-plugin-component-annotate/src/tsconfig.json @@ -3,6 +3,7 @@ "extends": "@sentry-internal/sentry-bundler-plugin-tsconfig/base-config.json", "include": ["./**/*", "../package.json"], "compilerOptions": { - "esModuleInterop": true + "esModuleInterop": true, + "target": "ES2020" // es2020 needed for "new Set()" } } diff --git a/packages/bundler-plugin-core/src/index.ts b/packages/bundler-plugin-core/src/index.ts index fc28d1c1..0065cb36 100644 --- a/packages/bundler-plugin-core/src/index.ts +++ b/packages/bundler-plugin-core/src/index.ts @@ -438,7 +438,7 @@ export function sentryUnpluginFactory({ if (options.reactComponentAnnotation) { if (!options.reactComponentAnnotation.enabled) { logger.debug( - "The component name annotate plugin is currently disabled. Skipping component name annotations." + "The component name annotate plugin is disabled. Skipping component name annotations." ); } else if (options.reactComponentAnnotation.enabled && !componentNameAnnotatePlugin) { logger.warn(