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