@sentry/bundler-plugins 11.12.0 → 11.14.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.
Files changed (184) hide show
  1. package/build/cjs/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/assertClassBrand.js +6 -0
  2. package/build/cjs/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/checkPrivateRedeclaration.js +5 -0
  3. package/build/cjs/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateFieldGet2.js +6 -0
  4. package/build/cjs/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateFieldInitSpec.js +6 -0
  5. package/build/cjs/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateFieldSet2.js +6 -0
  6. package/build/cjs/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateMethodInitSpec.js +6 -0
  7. package/build/cjs/_virtual/_rolldown/runtime.js +22 -0
  8. package/build/cjs/babel-plugin/component-annotation.js +14 -32
  9. package/build/cjs/babel-plugin/component-annotation.js.map +1 -1
  10. package/build/cjs/babel-plugin/constants.js +140 -122
  11. package/build/cjs/babel-plugin/constants.js.map +1 -1
  12. package/build/cjs/babel-plugin/experimental.js +204 -307
  13. package/build/cjs/babel-plugin/experimental.js.map +1 -1
  14. package/build/cjs/babel-plugin/index.js +315 -437
  15. package/build/cjs/babel-plugin/index.js.map +1 -1
  16. package/build/cjs/bun/index.js +81 -117
  17. package/build/cjs/bun/index.js.map +1 -1
  18. package/build/cjs/core/build-plugin-manager.js +626 -702
  19. package/build/cjs/core/build-plugin-manager.js.map +1 -1
  20. package/build/cjs/core/cli.js +134 -129
  21. package/build/cjs/core/cli.js.map +1 -1
  22. package/build/cjs/core/component-annotate-hooks.js +16 -27
  23. package/build/cjs/core/component-annotate-hooks.js.map +1 -1
  24. package/build/cjs/core/component-annotation-oxc-ast.js +10 -21
  25. package/build/cjs/core/component-annotation-oxc-ast.js.map +1 -1
  26. package/build/cjs/core/component-annotation-oxc-fragments.js +45 -74
  27. package/build/cjs/core/component-annotation-oxc-fragments.js.map +1 -1
  28. package/build/cjs/core/component-annotation-oxc-jsx.js +116 -156
  29. package/build/cjs/core/component-annotation-oxc-jsx.js.map +1 -1
  30. package/build/cjs/core/component-annotation-oxc-walk.js +62 -123
  31. package/build/cjs/core/component-annotation-oxc-walk.js.map +1 -1
  32. package/build/cjs/core/component-annotation-oxc.js +68 -103
  33. package/build/cjs/core/component-annotation-oxc.js.map +1 -1
  34. package/build/cjs/core/debug-id-upload.js +223 -234
  35. package/build/cjs/core/debug-id-upload.js.map +1 -1
  36. package/build/cjs/core/get-code-injection-position.js +59 -74
  37. package/build/cjs/core/get-code-injection-position.js.map +1 -1
  38. package/build/cjs/core/glob.js +9 -7
  39. package/build/cjs/core/glob.js.map +1 -1
  40. package/build/cjs/core/index.js +77 -61
  41. package/build/cjs/core/index.js.map +1 -1
  42. package/build/cjs/core/logger.js +17 -26
  43. package/build/cjs/core/logger.js.map +1 -1
  44. package/build/cjs/core/options-mapping.js +95 -117
  45. package/build/cjs/core/options-mapping.js.map +1 -1
  46. package/build/cjs/core/sentry/telemetry.js +90 -105
  47. package/build/cjs/core/sentry/telemetry.js.map +1 -1
  48. package/build/cjs/core/sentry/transports.js +92 -99
  49. package/build/cjs/core/sentry/transports.js.map +1 -1
  50. package/build/cjs/core/sourcemap-settings.js +98 -61
  51. package/build/cjs/core/sourcemap-settings.js.map +1 -1
  52. package/build/cjs/core/upload-filter.js +41 -46
  53. package/build/cjs/core/upload-filter.js.map +1 -1
  54. package/build/cjs/core/utils.js +228 -221
  55. package/build/cjs/core/utils.js.map +1 -1
  56. package/build/cjs/core/version.js +4 -5
  57. package/build/cjs/core/version.js.map +1 -1
  58. package/build/cjs/esbuild/index.js +183 -213
  59. package/build/cjs/esbuild/index.js.map +1 -1
  60. package/build/cjs/loader-utils/index.js +5 -10
  61. package/build/cjs/rollup/debug-id-injection.js +22 -38
  62. package/build/cjs/rollup/debug-id-injection.js.map +1 -1
  63. package/build/cjs/rollup/debug-id-stamping.js +14 -24
  64. package/build/cjs/rollup/debug-id-stamping.js.map +1 -1
  65. package/build/cjs/rollup/index.js +192 -246
  66. package/build/cjs/rollup/index.js.map +1 -1
  67. package/build/cjs/rollup/source-map-handling.js +151 -175
  68. package/build/cjs/rollup/source-map-handling.js.map +1 -1
  69. package/build/cjs/vite/index.js +19 -21
  70. package/build/cjs/vite/index.js.map +1 -1
  71. package/build/cjs/vite/source-map-hooks.js +112 -89
  72. package/build/cjs/vite/source-map-hooks.js.map +1 -1
  73. package/build/cjs/webpack/component-annotation-transform.js +20 -26
  74. package/build/cjs/webpack/component-annotation-transform.js.map +1 -1
  75. package/build/cjs/webpack/index.js +271 -340
  76. package/build/cjs/webpack/index.js.map +1 -1
  77. package/build/esm/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/assertClassBrand.js +6 -0
  78. package/build/esm/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/checkPrivateRedeclaration.js +5 -0
  79. package/build/esm/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateFieldGet2.js +6 -0
  80. package/build/esm/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateFieldInitSpec.js +6 -0
  81. package/build/esm/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateFieldSet2.js +6 -0
  82. package/build/esm/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/classPrivateMethodInitSpec.js +6 -0
  83. package/build/esm/_virtual/_rolldown/runtime.js +2 -0
  84. package/build/esm/babel-plugin/component-annotation.js +13 -29
  85. package/build/esm/babel-plugin/component-annotation.js.map +1 -1
  86. package/build/esm/babel-plugin/constants.js +140 -120
  87. package/build/esm/babel-plugin/constants.js.map +1 -1
  88. package/build/esm/babel-plugin/experimental.js +204 -305
  89. package/build/esm/babel-plugin/experimental.js.map +1 -1
  90. package/build/esm/babel-plugin/index.js +311 -434
  91. package/build/esm/babel-plugin/index.js.map +1 -1
  92. package/build/esm/bun/index.js +76 -101
  93. package/build/esm/bun/index.js.map +1 -1
  94. package/build/esm/core/build-plugin-manager.js +621 -683
  95. package/build/esm/core/build-plugin-manager.js.map +1 -1
  96. package/build/esm/core/cli.js +134 -127
  97. package/build/esm/core/cli.js.map +1 -1
  98. package/build/esm/core/component-annotate-hooks.js +16 -25
  99. package/build/esm/core/component-annotate-hooks.js.map +1 -1
  100. package/build/esm/core/component-annotation-oxc-ast.js +9 -19
  101. package/build/esm/core/component-annotation-oxc-ast.js.map +1 -1
  102. package/build/esm/core/component-annotation-oxc-fragments.js +44 -72
  103. package/build/esm/core/component-annotation-oxc-fragments.js.map +1 -1
  104. package/build/esm/core/component-annotation-oxc-jsx.js +115 -154
  105. package/build/esm/core/component-annotation-oxc-jsx.js.map +1 -1
  106. package/build/esm/core/component-annotation-oxc-walk.js +61 -121
  107. package/build/esm/core/component-annotation-oxc-walk.js.map +1 -1
  108. package/build/esm/core/component-annotation-oxc.js +65 -96
  109. package/build/esm/core/component-annotation-oxc.js.map +1 -1
  110. package/build/esm/core/debug-id-upload.js +218 -213
  111. package/build/esm/core/debug-id-upload.js.map +1 -1
  112. package/build/esm/core/get-code-injection-position.js +59 -72
  113. package/build/esm/core/get-code-injection-position.js.map +1 -1
  114. package/build/esm/core/glob.js +9 -5
  115. package/build/esm/core/glob.js.map +1 -1
  116. package/build/esm/core/index.js +62 -47
  117. package/build/esm/core/index.js.map +1 -1
  118. package/build/esm/core/logger.js +17 -24
  119. package/build/esm/core/logger.js.map +1 -1
  120. package/build/esm/core/options-mapping.js +95 -115
  121. package/build/esm/core/options-mapping.js.map +1 -1
  122. package/build/esm/core/sentry/telemetry.js +89 -102
  123. package/build/esm/core/sentry/telemetry.js.map +1 -1
  124. package/build/esm/core/sentry/transports.js +90 -83
  125. package/build/esm/core/sentry/transports.js.map +1 -1
  126. package/build/esm/core/sourcemap-settings.js +96 -59
  127. package/build/esm/core/sourcemap-settings.js.map +1 -1
  128. package/build/esm/core/upload-filter.js +39 -30
  129. package/build/esm/core/upload-filter.js.map +1 -1
  130. package/build/esm/core/utils.js +221 -211
  131. package/build/esm/core/utils.js.map +1 -1
  132. package/build/esm/core/version.js +4 -3
  133. package/build/esm/core/version.js.map +1 -1
  134. package/build/esm/esbuild/index.js +179 -197
  135. package/build/esm/esbuild/index.js.map +1 -1
  136. package/build/esm/loader-utils/index.js +4 -3
  137. package/build/esm/package.json +1 -1
  138. package/build/esm/rollup/debug-id-injection.js +22 -36
  139. package/build/esm/rollup/debug-id-injection.js.map +1 -1
  140. package/build/esm/rollup/debug-id-stamping.js +14 -22
  141. package/build/esm/rollup/debug-id-stamping.js.map +1 -1
  142. package/build/esm/rollup/index.js +189 -226
  143. package/build/esm/rollup/index.js.map +1 -1
  144. package/build/esm/rollup/source-map-handling.js +149 -159
  145. package/build/esm/rollup/source-map-handling.js.map +1 -1
  146. package/build/esm/vite/index.js +19 -18
  147. package/build/esm/vite/index.js.map +1 -1
  148. package/build/esm/vite/source-map-hooks.js +109 -72
  149. package/build/esm/vite/source-map-hooks.js.map +1 -1
  150. package/build/esm/webpack/component-annotation-transform.js +17 -24
  151. package/build/esm/webpack/component-annotation-transform.js.map +1 -1
  152. package/build/esm/webpack/index.js +268 -322
  153. package/build/esm/webpack/index.js.map +1 -1
  154. package/build/types/core/build-plugin-manager.d.ts +16 -5
  155. package/build/types/core/build-plugin-manager.d.ts.map +1 -1
  156. package/build/types/core/cli.d.ts +6 -1
  157. package/build/types/core/cli.d.ts.map +1 -1
  158. package/build/types/core/debug-id-upload.d.ts +7 -4
  159. package/build/types/core/debug-id-upload.d.ts.map +1 -1
  160. package/build/types/core/index.d.ts +3 -3
  161. package/build/types/core/index.d.ts.map +1 -1
  162. package/build/types/core/options-mapping.d.ts +4 -3
  163. package/build/types/core/options-mapping.d.ts.map +1 -1
  164. package/build/types/core/sentry/telemetry.d.ts.map +1 -1
  165. package/build/types/core/sourcemap-settings.d.ts +10 -1
  166. package/build/types/core/sourcemap-settings.d.ts.map +1 -1
  167. package/build/types/core/types.d.ts +25 -1
  168. package/build/types/core/types.d.ts.map +1 -1
  169. package/build/types/core/utils.d.ts +4 -0
  170. package/build/types/core/utils.d.ts.map +1 -1
  171. package/build/types/core/version.d.ts +1 -1
  172. package/build/types/esbuild/index.d.ts +2 -2
  173. package/build/types/esbuild/index.d.ts.map +1 -1
  174. package/build/types/rollup/index.d.ts +2 -2
  175. package/build/types/rollup/index.d.ts.map +1 -1
  176. package/build/types/rollup/source-map-handling.d.ts.map +1 -1
  177. package/build/types/vite/index.d.ts +3 -3
  178. package/build/types/vite/index.d.ts.map +1 -1
  179. package/build/types/vite/source-map-hooks.d.ts.map +1 -1
  180. package/build/types/webpack/index.d.ts +7 -3
  181. package/build/types/webpack/index.d.ts.map +1 -1
  182. package/package.json +8 -15
  183. package/build/cjs/loader-utils/index.js.map +0 -1
  184. package/build/esm/loader-utils/index.js.map +0 -1
@@ -1,335 +1,234 @@
1
+ // src/babel-plugin/experimental.ts
1
2
  const REACT_NATIVE_ELEMENTS = [
2
- "Image",
3
- "Text",
4
- "View",
5
- "ScrollView",
6
- "TextInput",
7
- "TouchableOpacity",
8
- "TouchableHighlight",
9
- "TouchableWithoutFeedback",
10
- "FlatList",
11
- "SectionList",
12
- "ActivityIndicator",
13
- "Button",
14
- "Switch",
15
- "Modal",
16
- "SafeAreaView",
17
- "StatusBar",
18
- "KeyboardAvoidingView",
19
- "RefreshControl",
20
- "Picker",
21
- "Slider"
3
+ "Image",
4
+ "Text",
5
+ "View",
6
+ "ScrollView",
7
+ "TextInput",
8
+ "TouchableOpacity",
9
+ "TouchableHighlight",
10
+ "TouchableWithoutFeedback",
11
+ "FlatList",
12
+ "SectionList",
13
+ "ActivityIndicator",
14
+ "Button",
15
+ "Switch",
16
+ "Modal",
17
+ "SafeAreaView",
18
+ "StatusBar",
19
+ "KeyboardAvoidingView",
20
+ "RefreshControl",
21
+ "Picker",
22
+ "Slider"
22
23
  ];
23
24
  function experimentalComponentNameAnnotatePlugin(babel) {
24
- return createPlugin(babel);
25
+ return createPlugin(babel);
25
26
  }
26
27
  function createPlugin({ types: t }) {
27
- return {
28
- visitor: {
29
- Program: {
30
- enter(path, state) {
31
- const fragmentContext = collectFragmentContext(path);
32
- state.sentryFragmentContext = fragmentContext;
33
- }
34
- },
35
- FunctionDeclaration(path, state) {
36
- if (!path.node.id?.name) {
37
- return;
38
- }
39
- const context = createJSXProcessingContext(state, t, path.node.id.name);
40
- functionBodyPushAttributes(context, path);
41
- },
42
- ArrowFunctionExpression(path, state) {
43
- const parent = path.parent;
44
- if (!parent || !("id" in parent) || !parent.id || !("name" in parent.id) || !parent.id.name) {
45
- return;
46
- }
47
- const context = createJSXProcessingContext(state, t, parent.id.name);
48
- functionBodyPushAttributes(context, path);
49
- },
50
- ClassDeclaration(path, state) {
51
- const name = path.get("id");
52
- const properties = path.get("body").get("body");
53
- const render = properties.find((prop) => {
54
- return prop.isClassMethod() && prop.get("key").isIdentifier({ name: "render" });
55
- });
56
- if (!render?.traverse) {
57
- return;
58
- }
59
- const context = createJSXProcessingContext(state, t, name.node?.name || "");
60
- render.traverse({
61
- ReturnStatement(returnStatement) {
62
- const arg = returnStatement.get("argument");
63
- if (!arg.isJSXElement() && !arg.isJSXFragment()) {
64
- return;
65
- }
66
- processJSX(context, arg);
67
- }
68
- });
69
- }
70
- }
71
- };
28
+ return { visitor: {
29
+ Program: { enter(path, state) {
30
+ state.sentryFragmentContext = collectFragmentContext(path);
31
+ } },
32
+ FunctionDeclaration(path, state) {
33
+ if (!path.node.id?.name) return;
34
+ functionBodyPushAttributes(createJSXProcessingContext(state, t, path.node.id.name), path);
35
+ },
36
+ ArrowFunctionExpression(path, state) {
37
+ const parent = path.parent;
38
+ if (!parent || !("id" in parent) || !parent.id || !("name" in parent.id) || !parent.id.name) return;
39
+ functionBodyPushAttributes(createJSXProcessingContext(state, t, parent.id.name), path);
40
+ },
41
+ ClassDeclaration(path, state) {
42
+ const name = path.get("id");
43
+ const render = path.get("body").get("body").find((prop) => {
44
+ return prop.isClassMethod() && prop.get("key").isIdentifier({ name: "render" });
45
+ });
46
+ if (!render?.traverse) return;
47
+ const context = createJSXProcessingContext(state, t, name.node?.name || "");
48
+ render.traverse({ ReturnStatement(returnStatement) {
49
+ const arg = returnStatement.get("argument");
50
+ if (!arg.isJSXElement() && !arg.isJSXFragment()) return;
51
+ processJSX(context, arg);
52
+ } });
53
+ }
54
+ } };
72
55
  }
56
+ /**
57
+ * Checks if an element name represents an HTML element (as opposed to a React component).
58
+ * HTML elements include standard lowercase HTML tags and React Native elements.
59
+ */
73
60
  function isHtmlElement(elementName) {
74
- if (elementName === UNKNOWN_ELEMENT_NAME) {
75
- return false;
76
- }
77
- if (elementName.length > 0 && elementName.charAt(0) === elementName.charAt(0).toLowerCase()) {
78
- return true;
79
- }
80
- if (REACT_NATIVE_ELEMENTS.includes(elementName)) {
81
- return true;
82
- }
83
- return false;
61
+ if (elementName === UNKNOWN_ELEMENT_NAME) return false;
62
+ if (elementName.length > 0 && elementName.charAt(0) === elementName.charAt(0).toLowerCase()) return true;
63
+ if (REACT_NATIVE_ELEMENTS.includes(elementName)) return true;
64
+ return false;
84
65
  }
66
+ /**
67
+ * Creates a JSX processing context from the plugin state
68
+ */
85
69
  function createJSXProcessingContext(state, t, componentName) {
86
- return {
87
- t,
88
- componentName,
89
- attributeName: attributeNamesFromState(state),
90
- ignoredComponents: state.opts.ignoredComponents ?? [],
91
- fragmentContext: state.sentryFragmentContext
92
- };
70
+ return {
71
+ t,
72
+ componentName,
73
+ attributeName: attributeNamesFromState(state),
74
+ ignoredComponents: state.opts.ignoredComponents ?? [],
75
+ fragmentContext: state.sentryFragmentContext
76
+ };
93
77
  }
78
+ /**
79
+ * Processes the body of a function to add Sentry tracking attributes to JSX elements.
80
+ * Handles various function body structures including direct JSX returns, conditional expressions,
81
+ * and nested JSX elements.
82
+ */
94
83
  function functionBodyPushAttributes(context, path) {
95
- let jsxNode;
96
- const functionBody = path.get("body").get("body");
97
- if (!("length" in functionBody) && functionBody.parent && (functionBody.parent.type === "JSXElement" || functionBody.parent.type === "JSXFragment")) {
98
- const maybeJsxNode = functionBody.find((c) => {
99
- return c.type === "JSXElement" || c.type === "JSXFragment";
100
- });
101
- if (!maybeJsxNode) {
102
- return;
103
- }
104
- jsxNode = maybeJsxNode;
105
- } else {
106
- const returnStatement = functionBody.find((c) => {
107
- return c.type === "ReturnStatement";
108
- });
109
- if (!returnStatement) {
110
- return;
111
- }
112
- const arg = returnStatement.get("argument");
113
- if (!arg) {
114
- return;
115
- }
116
- if (Array.isArray(arg)) {
117
- return;
118
- }
119
- if (arg.isConditionalExpression()) {
120
- const consequent = arg.get("consequent");
121
- if (consequent.isJSXFragment() || consequent.isJSXElement()) {
122
- processJSX(context, consequent);
123
- }
124
- const alternate = arg.get("alternate");
125
- if (alternate.isJSXFragment() || alternate.isJSXElement()) {
126
- processJSX(context, alternate);
127
- }
128
- return;
129
- }
130
- if (!arg.isJSXFragment() && !arg.isJSXElement()) {
131
- return;
132
- }
133
- jsxNode = arg;
134
- }
135
- if (!jsxNode) {
136
- return;
137
- }
138
- processJSX(context, jsxNode);
84
+ let jsxNode;
85
+ const functionBody = path.get("body").get("body");
86
+ if (!("length" in functionBody) && functionBody.parent && (functionBody.parent.type === "JSXElement" || functionBody.parent.type === "JSXFragment")) {
87
+ const maybeJsxNode = functionBody.find((c) => {
88
+ return c.type === "JSXElement" || c.type === "JSXFragment";
89
+ });
90
+ if (!maybeJsxNode) return;
91
+ jsxNode = maybeJsxNode;
92
+ } else {
93
+ const returnStatement = functionBody.find((c) => {
94
+ return c.type === "ReturnStatement";
95
+ });
96
+ if (!returnStatement) return;
97
+ const arg = returnStatement.get("argument");
98
+ if (!arg) return;
99
+ if (Array.isArray(arg)) return;
100
+ if (arg.isConditionalExpression()) {
101
+ const consequent = arg.get("consequent");
102
+ if (consequent.isJSXFragment() || consequent.isJSXElement()) processJSX(context, consequent);
103
+ const alternate = arg.get("alternate");
104
+ if (alternate.isJSXFragment() || alternate.isJSXElement()) processJSX(context, alternate);
105
+ return;
106
+ }
107
+ if (!arg.isJSXFragment() && !arg.isJSXElement()) return;
108
+ jsxNode = arg;
109
+ }
110
+ if (!jsxNode) return;
111
+ processJSX(context, jsxNode);
139
112
  }
113
+ /**
114
+ * Recursively processes JSX elements to add Sentry tracking attributes.
115
+ * Handles both JSX elements and fragments, applying appropriate attributes
116
+ * based on configuration and component context.
117
+ */
140
118
  function processJSX(context, jsxNode) {
141
- if (!jsxNode) {
142
- return;
143
- }
144
- const paths = jsxNode.get("openingElement");
145
- const openingElements = Array.isArray(paths) ? paths : [paths];
146
- const hasInjectedAttributes = openingElements.reduce(
147
- (prev, openingElement) => prev || applyAttributes(context, openingElement, context.componentName),
148
- false
149
- );
150
- if (hasInjectedAttributes) {
151
- return;
152
- }
153
- let children = jsxNode.get("children");
154
- if (children && !("length" in children)) {
155
- children = [children];
156
- }
157
- children.forEach((child) => {
158
- if (!child.node) {
159
- return;
160
- }
161
- const openingElement = child.get("openingElement");
162
- if (Array.isArray(openingElement)) {
163
- return;
164
- }
165
- processJSX(context, child);
166
- });
119
+ if (!jsxNode) return;
120
+ const paths = jsxNode.get("openingElement");
121
+ if ((Array.isArray(paths) ? paths : [paths]).reduce((prev, openingElement) => prev || applyAttributes(context, openingElement, context.componentName), false)) return;
122
+ let children = jsxNode.get("children");
123
+ if (children && !("length" in children)) children = [children];
124
+ children.forEach((child) => {
125
+ if (!child.node) return;
126
+ const openingElement = child.get("openingElement");
127
+ if (Array.isArray(openingElement)) return;
128
+ processJSX(context, child);
129
+ });
167
130
  }
131
+ /**
132
+ * Applies Sentry tracking attributes to a JSX opening element.
133
+ * Adds component name, element name, and source file attributes while
134
+ * respecting ignore lists and fragment detection.
135
+ */
168
136
  function applyAttributes(context, openingElement, componentName) {
169
- const { t, attributeName: componentAttributeName, ignoredComponents, fragmentContext } = context;
170
- if (!openingElement.node) {
171
- return false;
172
- }
173
- const isFragment = isReactFragment(t, openingElement, fragmentContext);
174
- if (isFragment) {
175
- return false;
176
- }
177
- if (!openingElement.node.attributes) {
178
- openingElement.node.attributes = [];
179
- }
180
- const elementName = getPathName(t, openingElement);
181
- if (!isHtmlElement(elementName)) {
182
- return false;
183
- }
184
- const isAnIgnoredComponent = ignoredComponents.some(
185
- (ignoredComponent) => ignoredComponent === componentName || ignoredComponent === elementName
186
- );
187
- if (!isAnIgnoredComponent && !hasAttributeWithName(openingElement, componentAttributeName)) {
188
- if (componentAttributeName) {
189
- openingElement.node.attributes.push(
190
- t.jSXAttribute(t.jSXIdentifier(componentAttributeName), t.stringLiteral(componentName))
191
- );
192
- }
193
- }
194
- return true;
137
+ const { t, attributeName: componentAttributeName, ignoredComponents, fragmentContext } = context;
138
+ if (!openingElement.node) return false;
139
+ if (isReactFragment(t, openingElement, fragmentContext)) return false;
140
+ if (!openingElement.node.attributes) openingElement.node.attributes = [];
141
+ const elementName = getPathName(t, openingElement);
142
+ if (!isHtmlElement(elementName)) return false;
143
+ if (!ignoredComponents.some((ignoredComponent) => ignoredComponent === componentName || ignoredComponent === elementName) && !hasAttributeWithName(openingElement, componentAttributeName)) {
144
+ if (componentAttributeName) openingElement.node.attributes.push(t.jSXAttribute(t.jSXIdentifier(componentAttributeName), t.stringLiteral(componentName)));
145
+ }
146
+ return true;
195
147
  }
196
148
  function attributeNamesFromState(state) {
197
- if (state.opts.native) {
198
- return "dataSentryComponent";
199
- }
200
- return "data-sentry-component";
149
+ if (state.opts.native) return "dataSentryComponent";
150
+ return "data-sentry-component";
201
151
  }
202
152
  function collectFragmentContext(programPath) {
203
- const fragmentAliases = /* @__PURE__ */ new Set();
204
- const reactNamespaceAliases = /* @__PURE__ */ new Set(["React"]);
205
- programPath.traverse({
206
- ImportDeclaration(importPath) {
207
- const source = importPath.node.source.value;
208
- if (source === "react" || source === "React") {
209
- importPath.node.specifiers.forEach((spec) => {
210
- if (spec.type === "ImportSpecifier" && spec.imported.type === "Identifier") {
211
- if (spec.imported.name === "Fragment") {
212
- fragmentAliases.add(spec.local.name);
213
- }
214
- } else if (spec.type === "ImportDefaultSpecifier" || spec.type === "ImportNamespaceSpecifier") {
215
- reactNamespaceAliases.add(spec.local.name);
216
- }
217
- });
218
- }
219
- },
220
- // Handle simple variable assignments only (avoid complex cases)
221
- VariableDeclarator(varPath) {
222
- if (varPath.node.init) {
223
- const init = varPath.node.init;
224
- if (varPath.node.id.type === "Identifier") {
225
- if (init.type === "Identifier" && fragmentAliases.has(init.name)) {
226
- fragmentAliases.add(varPath.node.id.name);
227
- }
228
- if (init.type === "MemberExpression" && init.object.type === "Identifier" && init.property.type === "Identifier" && init.property.name === "Fragment" && reactNamespaceAliases.has(init.object.name)) {
229
- fragmentAliases.add(varPath.node.id.name);
230
- }
231
- }
232
- if (varPath.node.id.type === "ObjectPattern") {
233
- if (init.type === "Identifier" && reactNamespaceAliases.has(init.name)) {
234
- const properties = varPath.node.id.properties;
235
- for (const prop of properties) {
236
- if (prop.type === "ObjectProperty" && prop.key?.type === "Identifier" && prop.value?.type === "Identifier" && prop.key.name === "Fragment") {
237
- fragmentAliases.add(prop.value.name);
238
- }
239
- }
240
- }
241
- }
242
- }
243
- }
244
- });
245
- return { fragmentAliases, reactNamespaceAliases };
153
+ const fragmentAliases = /* @__PURE__ */ new Set();
154
+ const reactNamespaceAliases = /* @__PURE__ */ new Set(["React"]);
155
+ programPath.traverse({
156
+ ImportDeclaration(importPath) {
157
+ const source = importPath.node.source.value;
158
+ if (source === "react" || source === "React") importPath.node.specifiers.forEach((spec) => {
159
+ if (spec.type === "ImportSpecifier" && spec.imported.type === "Identifier") {
160
+ if (spec.imported.name === "Fragment") fragmentAliases.add(spec.local.name);
161
+ } else if (spec.type === "ImportDefaultSpecifier" || spec.type === "ImportNamespaceSpecifier") reactNamespaceAliases.add(spec.local.name);
162
+ });
163
+ },
164
+ VariableDeclarator(varPath) {
165
+ if (varPath.node.init) {
166
+ const init = varPath.node.init;
167
+ if (varPath.node.id.type === "Identifier") {
168
+ if (init.type === "Identifier" && fragmentAliases.has(init.name)) fragmentAliases.add(varPath.node.id.name);
169
+ 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);
170
+ }
171
+ if (varPath.node.id.type === "ObjectPattern") {
172
+ if (init.type === "Identifier" && reactNamespaceAliases.has(init.name)) {
173
+ const properties = varPath.node.id.properties;
174
+ 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);
175
+ }
176
+ }
177
+ }
178
+ }
179
+ });
180
+ return {
181
+ fragmentAliases,
182
+ reactNamespaceAliases
183
+ };
246
184
  }
247
185
  function isReactFragment(t, openingElement, context) {
248
- if (openingElement.isJSXFragment()) {
249
- return true;
250
- }
251
- const elementName = getPathName(t, openingElement);
252
- if (elementName === "Fragment" || elementName === "React.Fragment") {
253
- return true;
254
- }
255
- if (context && elementName && context.fragmentAliases.has(elementName)) {
256
- return true;
257
- }
258
- 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") {
259
- const nodeName = openingElement.node.name;
260
- if (typeof nodeName !== "object" || !nodeName) {
261
- return false;
262
- }
263
- if ("object" in nodeName && "property" in nodeName) {
264
- const nodeNameObject = nodeName.object;
265
- const nodeNameProperty = nodeName.property;
266
- if (typeof nodeNameObject !== "object" || typeof nodeNameProperty !== "object") {
267
- return false;
268
- }
269
- if (!nodeNameObject || !nodeNameProperty) {
270
- return false;
271
- }
272
- const objectName = "name" in nodeNameObject && nodeNameObject.name;
273
- const propertyName = "name" in nodeNameProperty && nodeNameProperty.name;
274
- if (objectName === "React" && propertyName === "Fragment") {
275
- return true;
276
- }
277
- if (context) {
278
- if (context.reactNamespaceAliases.has(objectName) && propertyName === "Fragment") {
279
- return true;
280
- }
281
- if (context.fragmentAliases.has(objectName) && propertyName === "Fragment") {
282
- return true;
283
- }
284
- }
285
- }
286
- }
287
- return false;
186
+ if (openingElement.isJSXFragment()) return true;
187
+ const elementName = getPathName(t, openingElement);
188
+ if (elementName === "Fragment" || elementName === "React.Fragment") return true;
189
+ if (context && elementName && context.fragmentAliases.has(elementName)) return true;
190
+ 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") {
191
+ const nodeName = openingElement.node.name;
192
+ if (typeof nodeName !== "object" || !nodeName) return false;
193
+ if ("object" in nodeName && "property" in nodeName) {
194
+ const nodeNameObject = nodeName.object;
195
+ const nodeNameProperty = nodeName.property;
196
+ if (typeof nodeNameObject !== "object" || typeof nodeNameProperty !== "object") return false;
197
+ if (!nodeNameObject || !nodeNameProperty) return false;
198
+ const objectName = "name" in nodeNameObject && nodeNameObject.name;
199
+ const propertyName = "name" in nodeNameProperty && nodeNameProperty.name;
200
+ if (objectName === "React" && propertyName === "Fragment") return true;
201
+ if (context) {
202
+ if (context.reactNamespaceAliases.has(objectName) && propertyName === "Fragment") return true;
203
+ if (context.fragmentAliases.has(objectName) && propertyName === "Fragment") return true;
204
+ }
205
+ }
206
+ }
207
+ return false;
288
208
  }
289
209
  function hasAttributeWithName(openingElement, name) {
290
- if (!name) {
291
- return false;
292
- }
293
- return openingElement.node.attributes.some((node) => {
294
- if (node.type === "JSXAttribute") {
295
- return node.name.name === name;
296
- }
297
- return false;
298
- });
210
+ if (!name) return false;
211
+ return openingElement.node.attributes.some((node) => {
212
+ if (node.type === "JSXAttribute") return node.name.name === name;
213
+ return false;
214
+ });
299
215
  }
300
216
  function getPathName(t, path) {
301
- if (!path.node) return UNKNOWN_ELEMENT_NAME;
302
- if (!("name" in path.node)) {
303
- return UNKNOWN_ELEMENT_NAME;
304
- }
305
- const name = path.node.name;
306
- if (typeof name === "string") {
307
- return name;
308
- }
309
- if (t.isIdentifier(name) || t.isJSXIdentifier(name)) {
310
- return name.name;
311
- }
312
- if (t.isJSXNamespacedName(name)) {
313
- return name.name.name;
314
- }
315
- if (t.isJSXMemberExpression(name)) {
316
- const objectName = getJSXMemberExpressionObjectName(t, name.object);
317
- const propertyName = name.property.name;
318
- return `${objectName}.${propertyName}`;
319
- }
320
- return UNKNOWN_ELEMENT_NAME;
217
+ if (!path.node) return UNKNOWN_ELEMENT_NAME;
218
+ if (!("name" in path.node)) return UNKNOWN_ELEMENT_NAME;
219
+ const name = path.node.name;
220
+ if (typeof name === "string") return name;
221
+ if (t.isIdentifier(name) || t.isJSXIdentifier(name)) return name.name;
222
+ if (t.isJSXNamespacedName(name)) return name.name.name;
223
+ if (t.isJSXMemberExpression(name)) return `${getJSXMemberExpressionObjectName(t, name.object)}.${name.property.name}`;
224
+ return UNKNOWN_ELEMENT_NAME;
321
225
  }
322
226
  function getJSXMemberExpressionObjectName(t, object) {
323
- if (t.isJSXIdentifier(object)) {
324
- return object.name;
325
- }
326
- if (t.isJSXMemberExpression(object)) {
327
- const objectName = getJSXMemberExpressionObjectName(t, object.object);
328
- return `${objectName}.${object.property.name}`;
329
- }
330
- return UNKNOWN_ELEMENT_NAME;
227
+ if (t.isJSXIdentifier(object)) return object.name;
228
+ if (t.isJSXMemberExpression(object)) return `${getJSXMemberExpressionObjectName(t, object.object)}.${object.property.name}`;
229
+ return UNKNOWN_ELEMENT_NAME;
331
230
  }
332
231
  const UNKNOWN_ELEMENT_NAME = "unknown";
333
-
334
232
  export { experimentalComponentNameAnnotatePlugin };
335
- //# sourceMappingURL=experimental.js.map
233
+
234
+ //# sourceMappingURL=experimental.js.map