swc-plugin-component-annotate 1.5.0 → 1.7.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/README.md +0 -3
- package/package.json +2 -2
- package/src/config.rs +0 -4
- package/src/lib.rs +19 -33
- package/swc_plugin_component_annotate.wasm +0 -0
package/README.md
CHANGED
@@ -55,7 +55,6 @@ Add the plugin to your `.swcrc` configuration:
|
|
55
55
|
"plugins": [
|
56
56
|
["swc-plugin-component-annotate", {
|
57
57
|
"native": false,
|
58
|
-
"annotate-fragments": false,
|
59
58
|
"ignored-components": ["MyIgnoredComponent"],
|
60
59
|
"component-attr": "data-sentry-component",
|
61
60
|
"element-attr": "data-sentry-element",
|
@@ -73,8 +72,6 @@ Add the plugin to your `.swcrc` configuration:
|
|
73
72
|
- `false`: `data-component`, `data-element`, `data-source-file`
|
74
73
|
- `true`: `dataComponent`, `dataElement`, `dataSourceFile`
|
75
74
|
|
76
|
-
- **`annotate-fragments`** (boolean, default: `false`): Whether to annotate fragment children with component information
|
77
|
-
|
78
75
|
- **`ignored-components`** (array, default: `[]`): List of component names to skip during annotation
|
79
76
|
|
80
77
|
- **`component-attr`** (string, optional): Custom component attribute name (overrides default and native setting)
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "swc-plugin-component-annotate",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.7.0",
|
4
4
|
"description": "Use SWC to automatically annotate React components with data attributes for component tracking",
|
5
5
|
"author": "scttcper <scttcper@gmail.com>",
|
6
6
|
"license": "MIT",
|
@@ -25,5 +25,5 @@
|
|
25
25
|
},
|
26
26
|
"devDependencies": {},
|
27
27
|
"peerDependencies": {},
|
28
|
-
"packageManager": "pnpm@10.
|
28
|
+
"packageManager": "pnpm@10.13.1"
|
29
29
|
}
|
package/src/config.rs
CHANGED
@@ -6,10 +6,6 @@ pub struct PluginConfig {
|
|
6
6
|
#[serde(default)]
|
7
7
|
pub native: bool,
|
8
8
|
|
9
|
-
/// Whether to annotate fragment children with component information
|
10
|
-
#[serde(default, rename = "annotate-fragments")]
|
11
|
-
pub annotate_fragments: bool,
|
12
|
-
|
13
9
|
/// List of component names to ignore during annotation
|
14
10
|
#[serde(default, rename = "ignored-components")]
|
15
11
|
pub ignored_components: Vec<String>,
|
package/src/lib.rs
CHANGED
@@ -55,26 +55,30 @@ impl ReactComponentAnnotateVisitor {
|
|
55
55
|
}
|
56
56
|
|
57
57
|
fn process_jsx_element(&mut self, element: &mut JSXElement) {
|
58
|
-
|
58
|
+
// Check if this is a named fragment (Fragment, React.Fragment)
|
59
|
+
let is_fragment = is_react_fragment(&element.opening.name);
|
59
60
|
|
60
|
-
|
61
|
+
if !is_fragment {
|
62
|
+
self.add_attributes_to_element(&mut element.opening);
|
63
|
+
}
|
64
|
+
|
65
|
+
// Process children - fragments are transparent containers
|
61
66
|
for child in &mut element.children {
|
62
67
|
match child {
|
63
68
|
JSXElementChild::JSXElement(jsx_element) => {
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
69
|
+
if is_fragment {
|
70
|
+
// Fragment children are processed without clearing component name
|
71
|
+
jsx_element.visit_mut_with(self);
|
72
|
+
} else {
|
73
|
+
// Non-fragment children don't get component name, only element name
|
74
|
+
let prev_component = self.current_component_name.take();
|
75
|
+
jsx_element.visit_mut_with(self);
|
76
|
+
self.current_component_name = prev_component;
|
77
|
+
}
|
68
78
|
}
|
69
79
|
JSXElementChild::JSXFragment(jsx_fragment) => {
|
70
|
-
|
71
|
-
// Keep component name for first child of fragment
|
72
|
-
self.current_component_name.clone()
|
73
|
-
} else {
|
74
|
-
self.current_component_name.take()
|
75
|
-
};
|
80
|
+
// Fragments are always transparent containers
|
76
81
|
jsx_fragment.visit_mut_with(self);
|
77
|
-
self.current_component_name = prev_component;
|
78
82
|
}
|
79
83
|
_ => {}
|
80
84
|
}
|
@@ -82,32 +86,14 @@ impl ReactComponentAnnotateVisitor {
|
|
82
86
|
}
|
83
87
|
|
84
88
|
fn process_jsx_fragment(&mut self, fragment: &mut JSXFragment) {
|
85
|
-
//
|
86
|
-
let mut first_element_processed = false;
|
89
|
+
// Fragments are transparent containers - just process children
|
87
90
|
for child in &mut fragment.children {
|
88
91
|
match child {
|
89
92
|
JSXElementChild::JSXElement(jsx_element) => {
|
90
|
-
|
91
|
-
// First child of fragment gets component name
|
92
|
-
first_element_processed = true;
|
93
|
-
jsx_element.visit_mut_with(self);
|
94
|
-
} else {
|
95
|
-
// Other children don't get component name
|
96
|
-
let prev_component = self.current_component_name.take();
|
97
|
-
jsx_element.visit_mut_with(self);
|
98
|
-
self.current_component_name = prev_component;
|
99
|
-
}
|
93
|
+
jsx_element.visit_mut_with(self);
|
100
94
|
}
|
101
95
|
JSXElementChild::JSXFragment(jsx_fragment) => {
|
102
|
-
let prev_component =
|
103
|
-
if self.config.annotate_fragments && !first_element_processed {
|
104
|
-
first_element_processed = true;
|
105
|
-
self.current_component_name.clone()
|
106
|
-
} else {
|
107
|
-
self.current_component_name.take()
|
108
|
-
};
|
109
96
|
jsx_fragment.visit_mut_with(self);
|
110
|
-
self.current_component_name = prev_component;
|
111
97
|
}
|
112
98
|
_ => {}
|
113
99
|
}
|
Binary file
|