@sentry/bundler-plugins 11.12.0 → 11.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/assertClassBrand.js +6 -0
- package/build/cjs/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/checkPrivateRedeclaration.js +5 -0
- package/build/cjs/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateFieldGet2.js +6 -0
- package/build/cjs/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateFieldInitSpec.js +6 -0
- package/build/cjs/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateFieldSet2.js +6 -0
- package/build/cjs/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateMethodInitSpec.js +6 -0
- package/build/cjs/_virtual/_rolldown/runtime.js +22 -0
- package/build/cjs/babel-plugin/component-annotation.js +14 -32
- package/build/cjs/babel-plugin/component-annotation.js.map +1 -1
- package/build/cjs/babel-plugin/constants.js +140 -122
- package/build/cjs/babel-plugin/constants.js.map +1 -1
- package/build/cjs/babel-plugin/experimental.js +204 -307
- package/build/cjs/babel-plugin/experimental.js.map +1 -1
- package/build/cjs/babel-plugin/index.js +315 -437
- package/build/cjs/babel-plugin/index.js.map +1 -1
- package/build/cjs/bun/index.js +81 -117
- package/build/cjs/bun/index.js.map +1 -1
- package/build/cjs/core/build-plugin-manager.js +626 -702
- package/build/cjs/core/build-plugin-manager.js.map +1 -1
- package/build/cjs/core/cli.js +134 -129
- package/build/cjs/core/cli.js.map +1 -1
- package/build/cjs/core/component-annotate-hooks.js +16 -27
- package/build/cjs/core/component-annotate-hooks.js.map +1 -1
- package/build/cjs/core/component-annotation-oxc-ast.js +10 -21
- package/build/cjs/core/component-annotation-oxc-ast.js.map +1 -1
- package/build/cjs/core/component-annotation-oxc-fragments.js +45 -74
- package/build/cjs/core/component-annotation-oxc-fragments.js.map +1 -1
- package/build/cjs/core/component-annotation-oxc-jsx.js +116 -156
- package/build/cjs/core/component-annotation-oxc-jsx.js.map +1 -1
- package/build/cjs/core/component-annotation-oxc-walk.js +62 -123
- package/build/cjs/core/component-annotation-oxc-walk.js.map +1 -1
- package/build/cjs/core/component-annotation-oxc.js +68 -103
- package/build/cjs/core/component-annotation-oxc.js.map +1 -1
- package/build/cjs/core/debug-id-upload.js +223 -234
- package/build/cjs/core/debug-id-upload.js.map +1 -1
- package/build/cjs/core/get-code-injection-position.js +59 -74
- package/build/cjs/core/get-code-injection-position.js.map +1 -1
- package/build/cjs/core/glob.js +9 -7
- package/build/cjs/core/glob.js.map +1 -1
- package/build/cjs/core/index.js +77 -61
- package/build/cjs/core/index.js.map +1 -1
- package/build/cjs/core/logger.js +17 -26
- package/build/cjs/core/logger.js.map +1 -1
- package/build/cjs/core/options-mapping.js +95 -117
- package/build/cjs/core/options-mapping.js.map +1 -1
- package/build/cjs/core/sentry/telemetry.js +90 -105
- package/build/cjs/core/sentry/telemetry.js.map +1 -1
- package/build/cjs/core/sentry/transports.js +92 -99
- package/build/cjs/core/sentry/transports.js.map +1 -1
- package/build/cjs/core/sourcemap-settings.js +98 -61
- package/build/cjs/core/sourcemap-settings.js.map +1 -1
- package/build/cjs/core/upload-filter.js +41 -46
- package/build/cjs/core/upload-filter.js.map +1 -1
- package/build/cjs/core/utils.js +228 -219
- package/build/cjs/core/utils.js.map +1 -1
- package/build/cjs/core/version.js +4 -5
- package/build/cjs/core/version.js.map +1 -1
- package/build/cjs/esbuild/index.js +180 -211
- package/build/cjs/esbuild/index.js.map +1 -1
- package/build/cjs/loader-utils/index.js +5 -10
- package/build/cjs/rollup/debug-id-injection.js +22 -38
- package/build/cjs/rollup/debug-id-injection.js.map +1 -1
- package/build/cjs/rollup/debug-id-stamping.js +14 -24
- package/build/cjs/rollup/debug-id-stamping.js.map +1 -1
- package/build/cjs/rollup/index.js +192 -246
- package/build/cjs/rollup/index.js.map +1 -1
- package/build/cjs/rollup/source-map-handling.js +151 -175
- package/build/cjs/rollup/source-map-handling.js.map +1 -1
- package/build/cjs/vite/index.js +19 -21
- package/build/cjs/vite/index.js.map +1 -1
- package/build/cjs/vite/source-map-hooks.js +112 -89
- package/build/cjs/vite/source-map-hooks.js.map +1 -1
- package/build/cjs/webpack/component-annotation-transform.js +20 -26
- package/build/cjs/webpack/component-annotation-transform.js.map +1 -1
- package/build/cjs/webpack/index.js +271 -340
- package/build/cjs/webpack/index.js.map +1 -1
- package/build/esm/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/assertClassBrand.js +6 -0
- package/build/esm/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/checkPrivateRedeclaration.js +5 -0
- package/build/esm/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateFieldGet2.js +6 -0
- package/build/esm/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateFieldInitSpec.js +6 -0
- package/build/esm/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateFieldSet2.js +6 -0
- package/build/esm/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateMethodInitSpec.js +6 -0
- package/build/esm/_virtual/_rolldown/runtime.js +2 -0
- package/build/esm/babel-plugin/component-annotation.js +13 -29
- package/build/esm/babel-plugin/component-annotation.js.map +1 -1
- package/build/esm/babel-plugin/constants.js +140 -120
- package/build/esm/babel-plugin/constants.js.map +1 -1
- package/build/esm/babel-plugin/experimental.js +204 -305
- package/build/esm/babel-plugin/experimental.js.map +1 -1
- package/build/esm/babel-plugin/index.js +311 -434
- package/build/esm/babel-plugin/index.js.map +1 -1
- package/build/esm/bun/index.js +76 -101
- package/build/esm/bun/index.js.map +1 -1
- package/build/esm/core/build-plugin-manager.js +621 -683
- package/build/esm/core/build-plugin-manager.js.map +1 -1
- package/build/esm/core/cli.js +134 -127
- package/build/esm/core/cli.js.map +1 -1
- package/build/esm/core/component-annotate-hooks.js +16 -25
- package/build/esm/core/component-annotate-hooks.js.map +1 -1
- package/build/esm/core/component-annotation-oxc-ast.js +9 -19
- package/build/esm/core/component-annotation-oxc-ast.js.map +1 -1
- package/build/esm/core/component-annotation-oxc-fragments.js +44 -72
- package/build/esm/core/component-annotation-oxc-fragments.js.map +1 -1
- package/build/esm/core/component-annotation-oxc-jsx.js +115 -154
- package/build/esm/core/component-annotation-oxc-jsx.js.map +1 -1
- package/build/esm/core/component-annotation-oxc-walk.js +61 -121
- package/build/esm/core/component-annotation-oxc-walk.js.map +1 -1
- package/build/esm/core/component-annotation-oxc.js +65 -96
- package/build/esm/core/component-annotation-oxc.js.map +1 -1
- package/build/esm/core/debug-id-upload.js +218 -213
- package/build/esm/core/debug-id-upload.js.map +1 -1
- package/build/esm/core/get-code-injection-position.js +59 -72
- package/build/esm/core/get-code-injection-position.js.map +1 -1
- package/build/esm/core/glob.js +9 -5
- package/build/esm/core/glob.js.map +1 -1
- package/build/esm/core/index.js +62 -47
- package/build/esm/core/index.js.map +1 -1
- package/build/esm/core/logger.js +17 -24
- package/build/esm/core/logger.js.map +1 -1
- package/build/esm/core/options-mapping.js +95 -115
- package/build/esm/core/options-mapping.js.map +1 -1
- package/build/esm/core/sentry/telemetry.js +89 -102
- package/build/esm/core/sentry/telemetry.js.map +1 -1
- package/build/esm/core/sentry/transports.js +90 -83
- package/build/esm/core/sentry/transports.js.map +1 -1
- package/build/esm/core/sourcemap-settings.js +96 -59
- package/build/esm/core/sourcemap-settings.js.map +1 -1
- package/build/esm/core/upload-filter.js +39 -30
- package/build/esm/core/upload-filter.js.map +1 -1
- package/build/esm/core/utils.js +221 -209
- package/build/esm/core/utils.js.map +1 -1
- package/build/esm/core/version.js +4 -3
- package/build/esm/core/version.js.map +1 -1
- package/build/esm/esbuild/index.js +176 -195
- package/build/esm/esbuild/index.js.map +1 -1
- package/build/esm/loader-utils/index.js +4 -3
- package/build/esm/package.json +1 -1
- package/build/esm/rollup/debug-id-injection.js +22 -36
- package/build/esm/rollup/debug-id-injection.js.map +1 -1
- package/build/esm/rollup/debug-id-stamping.js +14 -22
- package/build/esm/rollup/debug-id-stamping.js.map +1 -1
- package/build/esm/rollup/index.js +189 -226
- package/build/esm/rollup/index.js.map +1 -1
- package/build/esm/rollup/source-map-handling.js +149 -159
- package/build/esm/rollup/source-map-handling.js.map +1 -1
- package/build/esm/vite/index.js +19 -18
- package/build/esm/vite/index.js.map +1 -1
- package/build/esm/vite/source-map-hooks.js +109 -72
- package/build/esm/vite/source-map-hooks.js.map +1 -1
- package/build/esm/webpack/component-annotation-transform.js +17 -24
- package/build/esm/webpack/component-annotation-transform.js.map +1 -1
- package/build/esm/webpack/index.js +268 -322
- package/build/esm/webpack/index.js.map +1 -1
- package/build/types/core/build-plugin-manager.d.ts +16 -5
- package/build/types/core/build-plugin-manager.d.ts.map +1 -1
- package/build/types/core/cli.d.ts +6 -1
- package/build/types/core/cli.d.ts.map +1 -1
- package/build/types/core/debug-id-upload.d.ts +7 -4
- package/build/types/core/debug-id-upload.d.ts.map +1 -1
- package/build/types/core/index.d.ts +3 -3
- package/build/types/core/index.d.ts.map +1 -1
- package/build/types/core/options-mapping.d.ts +4 -3
- package/build/types/core/options-mapping.d.ts.map +1 -1
- package/build/types/core/sentry/telemetry.d.ts.map +1 -1
- package/build/types/core/sourcemap-settings.d.ts +10 -1
- package/build/types/core/sourcemap-settings.d.ts.map +1 -1
- package/build/types/core/types.d.ts +25 -1
- package/build/types/core/types.d.ts.map +1 -1
- package/build/types/core/utils.d.ts +4 -0
- package/build/types/core/utils.d.ts.map +1 -1
- package/build/types/core/version.d.ts +1 -1
- package/build/types/esbuild/index.d.ts +2 -2
- package/build/types/esbuild/index.d.ts.map +1 -1
- package/build/types/rollup/index.d.ts +2 -2
- package/build/types/rollup/index.d.ts.map +1 -1
- package/build/types/rollup/source-map-handling.d.ts.map +1 -1
- package/build/types/vite/index.d.ts +3 -3
- package/build/types/vite/index.d.ts.map +1 -1
- package/build/types/vite/source-map-hooks.d.ts.map +1 -1
- package/build/types/webpack/index.d.ts +7 -3
- package/build/types/webpack/index.d.ts.map +1 -1
- package/package.json +8 -15
- package/build/cjs/loader-utils/index.js.map +0 -1
- package/build/esm/loader-utils/index.js.map +0 -1
|
@@ -1,481 +1,359 @@
|
|
|
1
|
-
Object.defineProperties(exports, {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
|
5
|
+
const require_component_annotation = require("./component-annotation.js");
|
|
6
|
+
const require_constants = require("./constants.js");
|
|
7
|
+
const require_experimental = require("./experimental.js");
|
|
8
|
+
// src/babel-plugin/index.ts
|
|
7
9
|
const SENTRY_LABEL_ATTRIBUTE = "sentry-label";
|
|
8
10
|
const MAX_LABEL_LENGTH = 64;
|
|
9
11
|
const DEFAULT_TEXT_COMPONENT_NAMES = ["Text", "text"];
|
|
10
12
|
const MAX_TEXT_SEARCH_DEPTH = 3;
|
|
11
13
|
function componentNameAnnotatePlugin(babel) {
|
|
12
|
-
|
|
14
|
+
return createPlugin(babel);
|
|
13
15
|
}
|
|
14
16
|
function createPlugin({ types: t }) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
ClassDeclaration(path, state) {
|
|
45
|
-
const name = path.get("id");
|
|
46
|
-
const properties = path.get("body").get("body");
|
|
47
|
-
const render = properties.find((prop) => {
|
|
48
|
-
return prop.isClassMethod() && prop.get("key").isIdentifier({ name: "render" });
|
|
49
|
-
});
|
|
50
|
-
if (!render?.traverse || isKnownIncompatiblePluginFromState(state)) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
const context = createJSXProcessingContext(state, t, name.node?.name || "");
|
|
54
|
-
render.traverse({
|
|
55
|
-
ReturnStatement(returnStatement) {
|
|
56
|
-
const arg = returnStatement.get("argument");
|
|
57
|
-
if (!arg.isJSXElement() && !arg.isJSXFragment()) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
processJSX(context, arg);
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
};
|
|
17
|
+
return { visitor: {
|
|
18
|
+
Program: { enter(path, state) {
|
|
19
|
+
state.sentryFragmentContext = collectFragmentContext(path);
|
|
20
|
+
} },
|
|
21
|
+
FunctionDeclaration(path, state) {
|
|
22
|
+
if (!path.node.id?.name) return;
|
|
23
|
+
if (isKnownIncompatiblePluginFromState(state)) return;
|
|
24
|
+
functionBodyPushAttributes(createJSXProcessingContext(state, t, path.node.id.name), path);
|
|
25
|
+
},
|
|
26
|
+
ArrowFunctionExpression(path, state) {
|
|
27
|
+
const parent = path.parent;
|
|
28
|
+
if (!parent || !("id" in parent) || !parent.id || !("name" in parent.id) || !parent.id.name) return;
|
|
29
|
+
if (isKnownIncompatiblePluginFromState(state)) return;
|
|
30
|
+
functionBodyPushAttributes(createJSXProcessingContext(state, t, parent.id.name), path);
|
|
31
|
+
},
|
|
32
|
+
ClassDeclaration(path, state) {
|
|
33
|
+
const name = path.get("id");
|
|
34
|
+
const render = path.get("body").get("body").find((prop) => {
|
|
35
|
+
return prop.isClassMethod() && prop.get("key").isIdentifier({ name: "render" });
|
|
36
|
+
});
|
|
37
|
+
if (!render?.traverse || isKnownIncompatiblePluginFromState(state)) return;
|
|
38
|
+
const context = createJSXProcessingContext(state, t, name.node?.name || "");
|
|
39
|
+
render.traverse({ ReturnStatement(returnStatement) {
|
|
40
|
+
const arg = returnStatement.get("argument");
|
|
41
|
+
if (!arg.isJSXElement() && !arg.isJSXFragment()) return;
|
|
42
|
+
processJSX(context, arg);
|
|
43
|
+
} });
|
|
44
|
+
}
|
|
45
|
+
} };
|
|
66
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Creates a JSX processing context from the plugin state
|
|
49
|
+
*/
|
|
67
50
|
function createJSXProcessingContext(state, t, componentName) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
51
|
+
return {
|
|
52
|
+
annotateFragments: state.opts["annotate-fragments"] === true,
|
|
53
|
+
t,
|
|
54
|
+
componentName,
|
|
55
|
+
sourceFileName: sourceFileNameFromState(state),
|
|
56
|
+
attributeNames: attributeNamesFromState(state),
|
|
57
|
+
ignoredComponents: state.opts.ignoredComponents ?? [],
|
|
58
|
+
fragmentContext: state.sentryFragmentContext,
|
|
59
|
+
autoInjectSentryLabel: !!state.opts.autoInjectSentryLabel,
|
|
60
|
+
textComponentNames: (state.opts.autoInjectSentryLabel && typeof state.opts.autoInjectSentryLabel === "object" ? state.opts.autoInjectSentryLabel.textComponentNames : void 0) ?? DEFAULT_TEXT_COMPONENT_NAMES
|
|
61
|
+
};
|
|
79
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Processes the body of a function to add Sentry tracking attributes to JSX elements.
|
|
65
|
+
* Handles various function body structures including direct JSX returns, conditional expressions,
|
|
66
|
+
* and nested JSX elements.
|
|
67
|
+
*/
|
|
80
68
|
function functionBodyPushAttributes(context, path) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
const alternate = arg.get("alternate");
|
|
111
|
-
if (alternate.isJSXFragment() || alternate.isJSXElement()) {
|
|
112
|
-
processJSX(context, alternate);
|
|
113
|
-
}
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
if (!arg.isJSXFragment() && !arg.isJSXElement()) {
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
jsxNode = arg;
|
|
120
|
-
}
|
|
121
|
-
if (!jsxNode) {
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
processJSX(context, jsxNode);
|
|
69
|
+
let jsxNode;
|
|
70
|
+
const functionBody = path.get("body").get("body");
|
|
71
|
+
if (!("length" in functionBody) && functionBody.parent && (functionBody.parent.type === "JSXElement" || functionBody.parent.type === "JSXFragment")) {
|
|
72
|
+
const maybeJsxNode = functionBody.find((c) => {
|
|
73
|
+
return c.type === "JSXElement" || c.type === "JSXFragment";
|
|
74
|
+
});
|
|
75
|
+
if (!maybeJsxNode) return;
|
|
76
|
+
jsxNode = maybeJsxNode;
|
|
77
|
+
} else {
|
|
78
|
+
const returnStatement = functionBody.find((c) => {
|
|
79
|
+
return c.type === "ReturnStatement";
|
|
80
|
+
});
|
|
81
|
+
if (!returnStatement) return;
|
|
82
|
+
const arg = returnStatement.get("argument");
|
|
83
|
+
if (!arg) return;
|
|
84
|
+
if (Array.isArray(arg)) return;
|
|
85
|
+
if (arg.isConditionalExpression()) {
|
|
86
|
+
const consequent = arg.get("consequent");
|
|
87
|
+
if (consequent.isJSXFragment() || consequent.isJSXElement()) processJSX(context, consequent);
|
|
88
|
+
const alternate = arg.get("alternate");
|
|
89
|
+
if (alternate.isJSXFragment() || alternate.isJSXElement()) processJSX(context, alternate);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (!arg.isJSXFragment() && !arg.isJSXElement()) return;
|
|
93
|
+
jsxNode = arg;
|
|
94
|
+
}
|
|
95
|
+
if (!jsxNode) return;
|
|
96
|
+
processJSX(context, jsxNode);
|
|
125
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Recursively processes JSX elements to add Sentry tracking attributes.
|
|
100
|
+
* Handles both JSX elements and fragments, applying appropriate attributes
|
|
101
|
+
* based on configuration and component context.
|
|
102
|
+
*/
|
|
126
103
|
function processJSX(context, jsxNode, componentName) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
if (Array.isArray(openingElement)) {
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
if (shouldSetComponentName && openingElement?.node) {
|
|
151
|
-
shouldSetComponentName = false;
|
|
152
|
-
processJSX(context, child, currentComponentName);
|
|
153
|
-
} else {
|
|
154
|
-
processJSX(context, child, "");
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
if (isRootElement && context.autoInjectSentryLabel) {
|
|
158
|
-
maybeInjectSentryLabel(context, jsxNode);
|
|
159
|
-
}
|
|
104
|
+
if (!jsxNode) return;
|
|
105
|
+
const currentComponentName = componentName ?? context.componentName;
|
|
106
|
+
const isRootElement = componentName === void 0;
|
|
107
|
+
const paths = jsxNode.get("openingElement");
|
|
108
|
+
(Array.isArray(paths) ? paths : [paths]).forEach((openingElement) => {
|
|
109
|
+
applyAttributes(context, openingElement, currentComponentName);
|
|
110
|
+
});
|
|
111
|
+
let children = jsxNode.get("children");
|
|
112
|
+
if (children && !("length" in children)) children = [children];
|
|
113
|
+
let shouldSetComponentName = context.annotateFragments;
|
|
114
|
+
children.forEach((child) => {
|
|
115
|
+
if (!child.node) return;
|
|
116
|
+
const openingElement = child.get("openingElement");
|
|
117
|
+
if (Array.isArray(openingElement)) return;
|
|
118
|
+
if (shouldSetComponentName && openingElement?.node) {
|
|
119
|
+
shouldSetComponentName = false;
|
|
120
|
+
processJSX(context, child, currentComponentName);
|
|
121
|
+
} else processJSX(context, child, "");
|
|
122
|
+
});
|
|
123
|
+
if (isRootElement && context.autoInjectSentryLabel) maybeInjectSentryLabel(context, jsxNode);
|
|
160
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* Applies Sentry tracking attributes to a JSX opening element.
|
|
127
|
+
* Adds component name, element name, and source file attributes while
|
|
128
|
+
* respecting ignore lists and fragment detection.
|
|
129
|
+
*/
|
|
161
130
|
function applyAttributes(context, openingElement, componentName) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
sourceFileName
|
|
176
|
-
})) {
|
|
177
|
-
openingElement.node.attributes.push(t.jSXAttribute(t.jSXIdentifier(name), t.stringLiteral(value)));
|
|
178
|
-
}
|
|
131
|
+
const { t, attributeNames, ignoredComponents, fragmentContext, sourceFileName } = context;
|
|
132
|
+
if (!openingElement.node) return;
|
|
133
|
+
if (!openingElement.node.attributes) openingElement.node.attributes = [];
|
|
134
|
+
const elementName = getPathName(t, openingElement);
|
|
135
|
+
for (const [name, value] of require_component_annotation.getComponentAnnotationAttributes({
|
|
136
|
+
attributeNames,
|
|
137
|
+
componentName,
|
|
138
|
+
elementName,
|
|
139
|
+
existingAttributes: getExistingAttributeNames(openingElement),
|
|
140
|
+
ignoredComponents,
|
|
141
|
+
isFragment: isReactFragment(t, openingElement, fragmentContext),
|
|
142
|
+
sourceFileName
|
|
143
|
+
})) openingElement.node.attributes.push(t.jSXAttribute(t.jSXIdentifier(name), t.stringLiteral(value)));
|
|
179
144
|
}
|
|
180
145
|
function sourceFileNameFromState(state) {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
return name.split("/").pop();
|
|
187
|
-
} else if (name.indexOf("\\") !== -1) {
|
|
188
|
-
return name.split("\\").pop();
|
|
189
|
-
} else {
|
|
190
|
-
return name;
|
|
191
|
-
}
|
|
146
|
+
const name = fullSourceFileNameFromState(state);
|
|
147
|
+
if (!name) return;
|
|
148
|
+
if (name.indexOf("/") !== -1) return name.split("/").pop();
|
|
149
|
+
else if (name.indexOf("\\") !== -1) return name.split("\\").pop();
|
|
150
|
+
else return name;
|
|
192
151
|
}
|
|
193
152
|
function fullSourceFileNameFromState(state) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}
|
|
198
|
-
return null;
|
|
153
|
+
const name = state.file.opts.parserOpts?.sourceFileName;
|
|
154
|
+
if (typeof name === "string") return name;
|
|
155
|
+
return null;
|
|
199
156
|
}
|
|
200
157
|
function isKnownIncompatiblePluginFromState(state) {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
return true;
|
|
208
|
-
}
|
|
209
|
-
return false;
|
|
210
|
-
});
|
|
158
|
+
const fullSourceFileName = fullSourceFileNameFromState(state);
|
|
159
|
+
if (!fullSourceFileName) return false;
|
|
160
|
+
return require_constants.KNOWN_INCOMPATIBLE_PLUGINS.some((pluginName) => {
|
|
161
|
+
if (fullSourceFileName.includes(`/node_modules/${pluginName}/`) || fullSourceFileName.includes(`\\node_modules\\${pluginName}\\`)) return true;
|
|
162
|
+
return false;
|
|
163
|
+
});
|
|
211
164
|
}
|
|
212
165
|
function attributeNamesFromState(state) {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
166
|
+
if (state.opts.native) return [
|
|
167
|
+
require_component_annotation.NATIVE_COMPONENT_NAME,
|
|
168
|
+
require_component_annotation.NATIVE_ELEMENT_NAME,
|
|
169
|
+
require_component_annotation.NATIVE_SOURCE_FILE_NAME
|
|
170
|
+
];
|
|
171
|
+
return [
|
|
172
|
+
require_component_annotation.WEB_COMPONENT_NAME,
|
|
173
|
+
require_component_annotation.WEB_ELEMENT_NAME,
|
|
174
|
+
require_component_annotation.WEB_SOURCE_FILE_NAME
|
|
175
|
+
];
|
|
217
176
|
}
|
|
218
177
|
function collectFragmentContext(programPath) {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
const properties = varPath.node.id.properties;
|
|
251
|
-
for (const prop of properties) {
|
|
252
|
-
if (prop.type === "ObjectProperty" && prop.key?.type === "Identifier" && prop.value?.type === "Identifier" && prop.key.name === "Fragment") {
|
|
253
|
-
fragmentAliases.add(prop.value.name);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
});
|
|
261
|
-
return { fragmentAliases, reactNamespaceAliases };
|
|
178
|
+
const fragmentAliases = /* @__PURE__ */ new Set();
|
|
179
|
+
const reactNamespaceAliases = /* @__PURE__ */ new Set(["React"]);
|
|
180
|
+
programPath.traverse({
|
|
181
|
+
ImportDeclaration(importPath) {
|
|
182
|
+
const source = importPath.node.source.value;
|
|
183
|
+
if (source === "react" || source === "React") importPath.node.specifiers.forEach((spec) => {
|
|
184
|
+
if (spec.type === "ImportSpecifier" && spec.imported.type === "Identifier") {
|
|
185
|
+
if (spec.imported.name === "Fragment") fragmentAliases.add(spec.local.name);
|
|
186
|
+
} else if (spec.type === "ImportDefaultSpecifier" || spec.type === "ImportNamespaceSpecifier") reactNamespaceAliases.add(spec.local.name);
|
|
187
|
+
});
|
|
188
|
+
},
|
|
189
|
+
VariableDeclarator(varPath) {
|
|
190
|
+
if (varPath.node.init) {
|
|
191
|
+
const init = varPath.node.init;
|
|
192
|
+
if (varPath.node.id.type === "Identifier") {
|
|
193
|
+
if (init.type === "Identifier" && fragmentAliases.has(init.name)) fragmentAliases.add(varPath.node.id.name);
|
|
194
|
+
if (init.type === "MemberExpression" && init.object.type === "Identifier" && init.property.type === "Identifier" && init.property.name === "Fragment" && reactNamespaceAliases.has(init.object.name)) fragmentAliases.add(varPath.node.id.name);
|
|
195
|
+
}
|
|
196
|
+
if (varPath.node.id.type === "ObjectPattern") {
|
|
197
|
+
if (init.type === "Identifier" && reactNamespaceAliases.has(init.name)) {
|
|
198
|
+
const properties = varPath.node.id.properties;
|
|
199
|
+
for (const prop of properties) if (prop.type === "ObjectProperty" && prop.key?.type === "Identifier" && prop.value?.type === "Identifier" && prop.key.name === "Fragment") fragmentAliases.add(prop.value.name);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
return {
|
|
206
|
+
fragmentAliases,
|
|
207
|
+
reactNamespaceAliases
|
|
208
|
+
};
|
|
262
209
|
}
|
|
263
210
|
function isReactFragment(t, openingElement, context) {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
return false;
|
|
287
|
-
}
|
|
288
|
-
const objectName = "name" in nodeNameObject && nodeNameObject.name;
|
|
289
|
-
const propertyName = "name" in nodeNameProperty && nodeNameProperty.name;
|
|
290
|
-
if (objectName === "React" && propertyName === "Fragment") {
|
|
291
|
-
return true;
|
|
292
|
-
}
|
|
293
|
-
if (context) {
|
|
294
|
-
if (context.reactNamespaceAliases.has(objectName) && propertyName === "Fragment") {
|
|
295
|
-
return true;
|
|
296
|
-
}
|
|
297
|
-
if (context.fragmentAliases.has(objectName) && propertyName === "Fragment") {
|
|
298
|
-
return true;
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
return false;
|
|
211
|
+
if (openingElement.isJSXFragment()) return true;
|
|
212
|
+
const elementName = getPathName(t, openingElement);
|
|
213
|
+
if (elementName === "Fragment" || elementName === "React.Fragment") return true;
|
|
214
|
+
if (context && elementName && context.fragmentAliases.has(elementName)) return true;
|
|
215
|
+
if (openingElement.node && "name" in openingElement.node && openingElement.node.name && typeof openingElement.node.name === "object" && "type" in openingElement.node.name && openingElement.node.name.type === "JSXMemberExpression") {
|
|
216
|
+
const nodeName = openingElement.node.name;
|
|
217
|
+
if (typeof nodeName !== "object" || !nodeName) return false;
|
|
218
|
+
if ("object" in nodeName && "property" in nodeName) {
|
|
219
|
+
const nodeNameObject = nodeName.object;
|
|
220
|
+
const nodeNameProperty = nodeName.property;
|
|
221
|
+
if (typeof nodeNameObject !== "object" || typeof nodeNameProperty !== "object") return false;
|
|
222
|
+
if (!nodeNameObject || !nodeNameProperty) return false;
|
|
223
|
+
const objectName = "name" in nodeNameObject && nodeNameObject.name;
|
|
224
|
+
const propertyName = "name" in nodeNameProperty && nodeNameProperty.name;
|
|
225
|
+
if (objectName === "React" && propertyName === "Fragment") return true;
|
|
226
|
+
if (context) {
|
|
227
|
+
if (context.reactNamespaceAliases.has(objectName) && propertyName === "Fragment") return true;
|
|
228
|
+
if (context.fragmentAliases.has(objectName) && propertyName === "Fragment") return true;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return false;
|
|
304
233
|
}
|
|
305
234
|
function getExistingAttributeNames(openingElement) {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
});
|
|
312
|
-
return names;
|
|
235
|
+
const names = /* @__PURE__ */ new Set();
|
|
236
|
+
openingElement.node.attributes.forEach((node) => {
|
|
237
|
+
if (node.type === "JSXAttribute" && typeof node.name.name === "string") names.add(node.name.name);
|
|
238
|
+
});
|
|
239
|
+
return names;
|
|
313
240
|
}
|
|
314
241
|
function getPathName(t, path) {
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
if (t.isIdentifier(name) || t.isJSXIdentifier(name)) {
|
|
324
|
-
return name.name;
|
|
325
|
-
}
|
|
326
|
-
if (t.isJSXNamespacedName(name)) {
|
|
327
|
-
return name.name.name;
|
|
328
|
-
}
|
|
329
|
-
if (t.isJSXMemberExpression(name)) {
|
|
330
|
-
const objectName = getJSXMemberExpressionObjectName(t, name.object);
|
|
331
|
-
const propertyName = name.property.name;
|
|
332
|
-
return `${objectName}.${propertyName}`;
|
|
333
|
-
}
|
|
334
|
-
return UNKNOWN_ELEMENT_NAME;
|
|
242
|
+
if (!path.node) return UNKNOWN_ELEMENT_NAME;
|
|
243
|
+
if (!("name" in path.node)) return UNKNOWN_ELEMENT_NAME;
|
|
244
|
+
const name = path.node.name;
|
|
245
|
+
if (typeof name === "string") return name;
|
|
246
|
+
if (t.isIdentifier(name) || t.isJSXIdentifier(name)) return name.name;
|
|
247
|
+
if (t.isJSXNamespacedName(name)) return name.name.name;
|
|
248
|
+
if (t.isJSXMemberExpression(name)) return `${getJSXMemberExpressionObjectName(t, name.object)}.${name.property.name}`;
|
|
249
|
+
return UNKNOWN_ELEMENT_NAME;
|
|
335
250
|
}
|
|
336
251
|
function getJSXMemberExpressionObjectName(t, object) {
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
if (t.isJSXMemberExpression(object)) {
|
|
341
|
-
const objectName = getJSXMemberExpressionObjectName(t, object.object);
|
|
342
|
-
return `${objectName}.${object.property.name}`;
|
|
343
|
-
}
|
|
344
|
-
return UNKNOWN_ELEMENT_NAME;
|
|
252
|
+
if (t.isJSXIdentifier(object)) return object.name;
|
|
253
|
+
if (t.isJSXMemberExpression(object)) return `${getJSXMemberExpressionObjectName(t, object.object)}.${object.property.name}`;
|
|
254
|
+
return UNKNOWN_ELEMENT_NAME;
|
|
345
255
|
}
|
|
256
|
+
/**
|
|
257
|
+
* Extracts static text content from JSX children, searching up to a depth limit.
|
|
258
|
+
* Collects text from JSXText nodes of the root element and from recognized
|
|
259
|
+
* text components (e.g. <Text>). Non-text custom components are traversed
|
|
260
|
+
* but their own JSXText is not collected.
|
|
261
|
+
*
|
|
262
|
+
* Returns null when dynamic content is found anywhere in the subtree,
|
|
263
|
+
* signaling that the entire label should be skipped.
|
|
264
|
+
*/
|
|
346
265
|
function extractStaticTextFromChildren(t, node, textComponentNames, depth, isRoot) {
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
}
|
|
374
|
-
} else if (t.isJSXFragment(child)) {
|
|
375
|
-
const result = extractStaticTextFromChildren(t, child, textComponentNames, depth, isRoot);
|
|
376
|
-
if (result === null) {
|
|
377
|
-
return null;
|
|
378
|
-
}
|
|
379
|
-
texts.push(...result);
|
|
380
|
-
} else if (t.isJSXExpressionContainer(child)) {
|
|
381
|
-
if (!t.isJSXEmptyExpression(child.expression)) {
|
|
382
|
-
return null;
|
|
383
|
-
}
|
|
384
|
-
} else if (t.isJSXSpreadChild(child)) {
|
|
385
|
-
return null;
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
return texts;
|
|
266
|
+
if (depth <= 0) return [];
|
|
267
|
+
const texts = [];
|
|
268
|
+
for (const child of node.children) if (t.isJSXText(child)) {
|
|
269
|
+
if (isRoot) {
|
|
270
|
+
const trimmed = child.value.replace(/\s+/g, " ").trim();
|
|
271
|
+
if (trimmed) texts.push(trimmed);
|
|
272
|
+
}
|
|
273
|
+
} else if (t.isJSXElement(child)) {
|
|
274
|
+
const childName = getElementName(t, child.openingElement);
|
|
275
|
+
if (textComponentNames.includes(childName)) {
|
|
276
|
+
const innerTexts = extractTextFromTextComponent(t, child, textComponentNames);
|
|
277
|
+
if (innerTexts === null) return null;
|
|
278
|
+
texts.push(...innerTexts);
|
|
279
|
+
} else {
|
|
280
|
+
const result = extractStaticTextFromChildren(t, child, textComponentNames, depth - 1, false);
|
|
281
|
+
if (result === null) return null;
|
|
282
|
+
texts.push(...result);
|
|
283
|
+
}
|
|
284
|
+
} else if (t.isJSXFragment(child)) {
|
|
285
|
+
const result = extractStaticTextFromChildren(t, child, textComponentNames, depth, isRoot);
|
|
286
|
+
if (result === null) return null;
|
|
287
|
+
texts.push(...result);
|
|
288
|
+
} else if (t.isJSXExpressionContainer(child)) {
|
|
289
|
+
if (!t.isJSXEmptyExpression(child.expression)) return null;
|
|
290
|
+
} else if (t.isJSXSpreadChild(child)) return null;
|
|
291
|
+
return texts;
|
|
389
292
|
}
|
|
293
|
+
/**
|
|
294
|
+
* Recursively extracts static text from within a recognized text component.
|
|
295
|
+
* Handles nested text components (e.g. <Text>Hello <Text style={bold}>world</Text></Text>)
|
|
296
|
+
* which is the standard React Native pattern for inline styling.
|
|
297
|
+
*
|
|
298
|
+
* Returns null when any dynamic content is found, signaling bail-out.
|
|
299
|
+
*/
|
|
390
300
|
function extractTextFromTextComponent(t, node, textComponentNames) {
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
} else {
|
|
411
|
-
const innerTexts = extractTextFromTextComponent(t, child, textComponentNames);
|
|
412
|
-
if (innerTexts === null) {
|
|
413
|
-
return null;
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
} else if (t.isJSXFragment(child)) {
|
|
417
|
-
const innerTexts = extractTextFromTextComponent(t, child, textComponentNames);
|
|
418
|
-
if (innerTexts === null) {
|
|
419
|
-
return null;
|
|
420
|
-
}
|
|
421
|
-
texts.push(...innerTexts);
|
|
422
|
-
} else if (t.isJSXSpreadChild(child)) {
|
|
423
|
-
return null;
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
return texts;
|
|
301
|
+
const texts = [];
|
|
302
|
+
for (const child of node.children) if (t.isJSXText(child)) {
|
|
303
|
+
const trimmed = child.value.replace(/\s+/g, " ").trim();
|
|
304
|
+
if (trimmed) texts.push(trimmed);
|
|
305
|
+
} else if (t.isJSXExpressionContainer(child)) {
|
|
306
|
+
if (!t.isJSXEmptyExpression(child.expression)) return null;
|
|
307
|
+
} else if (t.isJSXElement(child)) {
|
|
308
|
+
const childName = getElementName(t, child.openingElement);
|
|
309
|
+
if (textComponentNames.includes(childName)) {
|
|
310
|
+
const innerTexts = extractTextFromTextComponent(t, child, textComponentNames);
|
|
311
|
+
if (innerTexts === null) return null;
|
|
312
|
+
texts.push(...innerTexts);
|
|
313
|
+
} else if (extractTextFromTextComponent(t, child, textComponentNames) === null) return null;
|
|
314
|
+
} else if (t.isJSXFragment(child)) {
|
|
315
|
+
const innerTexts = extractTextFromTextComponent(t, child, textComponentNames);
|
|
316
|
+
if (innerTexts === null) return null;
|
|
317
|
+
texts.push(...innerTexts);
|
|
318
|
+
} else if (t.isJSXSpreadChild(child)) return null;
|
|
319
|
+
return texts;
|
|
427
320
|
}
|
|
428
321
|
function getElementName(t, openingElement) {
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
if (t.isJSXMemberExpression(name)) {
|
|
434
|
-
return `${getJSXMemberExpressionObjectName(t, name.object)}.${name.property.name}`;
|
|
435
|
-
}
|
|
436
|
-
return "";
|
|
322
|
+
const name = openingElement.name;
|
|
323
|
+
if (t.isJSXIdentifier(name)) return name.name;
|
|
324
|
+
if (t.isJSXMemberExpression(name)) return `${getJSXMemberExpressionObjectName(t, name.object)}.${name.property.name}`;
|
|
325
|
+
return "";
|
|
437
326
|
}
|
|
327
|
+
/**
|
|
328
|
+
* Injects a sentry-label attribute on the root JSX element of a component if
|
|
329
|
+
* static text content can be extracted from its children.
|
|
330
|
+
*
|
|
331
|
+
* When the root is a JSX fragment, the first JSXElement child is used as the
|
|
332
|
+
* target for both text extraction and attribute injection (since fragments
|
|
333
|
+
* cannot carry attributes).
|
|
334
|
+
*/
|
|
438
335
|
function maybeInjectSentryLabel(context, jsxNode) {
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
if (targetElement.openingElement.attributes.some(
|
|
458
|
-
(attr) => t.isJSXAttribute(attr) && attr.name.name === SENTRY_LABEL_ATTRIBUTE
|
|
459
|
-
)) {
|
|
460
|
-
return;
|
|
461
|
-
}
|
|
462
|
-
const texts = extractStaticTextFromChildren(t, targetElement, textComponentNames, MAX_TEXT_SEARCH_DEPTH, true);
|
|
463
|
-
if (texts === null) {
|
|
464
|
-
return;
|
|
465
|
-
}
|
|
466
|
-
let label = texts.join(" ").replace(/\s+/g, " ").trim();
|
|
467
|
-
if (!label) {
|
|
468
|
-
return;
|
|
469
|
-
}
|
|
470
|
-
if (label.length > MAX_LABEL_LENGTH) {
|
|
471
|
-
label = `${label.substring(0, MAX_LABEL_LENGTH - 3)}...`;
|
|
472
|
-
}
|
|
473
|
-
targetElement.openingElement.attributes.push(
|
|
474
|
-
t.jSXAttribute(t.jSXIdentifier(SENTRY_LABEL_ATTRIBUTE), t.stringLiteral(label))
|
|
475
|
-
);
|
|
336
|
+
const { t, textComponentNames, ignoredComponents, componentName } = context;
|
|
337
|
+
const node = jsxNode.node;
|
|
338
|
+
let targetElement;
|
|
339
|
+
if (t.isJSXElement(node)) targetElement = node;
|
|
340
|
+
else if (t.isJSXFragment(node)) {
|
|
341
|
+
const firstChild = node.children.find((c) => t.isJSXElement(c));
|
|
342
|
+
if (!firstChild) return;
|
|
343
|
+
targetElement = firstChild;
|
|
344
|
+
} else return;
|
|
345
|
+
const targetElementName = getElementName(t, targetElement.openingElement);
|
|
346
|
+
if (ignoredComponents.some((ignored) => ignored === componentName || ignored === targetElementName)) return;
|
|
347
|
+
if (targetElement.openingElement.attributes.some((attr) => t.isJSXAttribute(attr) && attr.name.name === SENTRY_LABEL_ATTRIBUTE)) return;
|
|
348
|
+
const texts = extractStaticTextFromChildren(t, targetElement, textComponentNames, MAX_TEXT_SEARCH_DEPTH, true);
|
|
349
|
+
if (texts === null) return;
|
|
350
|
+
let label = texts.join(" ").replace(/\s+/g, " ").trim();
|
|
351
|
+
if (!label) return;
|
|
352
|
+
if (label.length > MAX_LABEL_LENGTH) label = `${label.substring(0, 61)}...`;
|
|
353
|
+
targetElement.openingElement.attributes.push(t.jSXAttribute(t.jSXIdentifier(SENTRY_LABEL_ATTRIBUTE), t.stringLiteral(label)));
|
|
476
354
|
}
|
|
477
355
|
const UNKNOWN_ELEMENT_NAME = "unknown";
|
|
478
|
-
|
|
479
|
-
exports.experimentalComponentNameAnnotatePlugin = experimental.experimentalComponentNameAnnotatePlugin;
|
|
480
356
|
exports.default = componentNameAnnotatePlugin;
|
|
481
|
-
|
|
357
|
+
exports.experimentalComponentNameAnnotatePlugin = require_experimental.experimentalComponentNameAnnotatePlugin;
|
|
358
|
+
|
|
359
|
+
//# sourceMappingURL=index.js.map
|