swc-plugin-component-annotate 1.2.0 → 1.2.2
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 +6 -6
- package/package.json +1 -1
- package/src/lib.rs +14 -3
- package/swc_plugin_component_annotate.wasm +0 -0
package/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# SWC Plugin:
|
1
|
+
# SWC Plugin: Component Annotate
|
2
2
|
|
3
3
|
A SWC plugin that automatically annotates React components with data attributes for component tracking and debugging.
|
4
4
|
|
@@ -23,9 +23,9 @@ This plugin transforms React components by adding data attributes that help with
|
|
23
23
|
## Installation
|
24
24
|
|
25
25
|
```bash
|
26
|
-
npm install --save-dev swc-plugin-
|
26
|
+
npm install --save-dev swc-plugin-component-annotate
|
27
27
|
# or
|
28
|
-
yarn add -D swc-plugin-
|
28
|
+
yarn add -D swc-plugin-component-annotate
|
29
29
|
```
|
30
30
|
|
31
31
|
## Usage
|
@@ -39,7 +39,7 @@ Add the plugin to your `.swcrc` configuration:
|
|
39
39
|
"jsc": {
|
40
40
|
"experimental": {
|
41
41
|
"plugins": [
|
42
|
-
["swc-plugin-
|
42
|
+
["swc-plugin-component-annotate", {}]
|
43
43
|
]
|
44
44
|
}
|
45
45
|
}
|
@@ -53,7 +53,7 @@ Add the plugin to your `.swcrc` configuration:
|
|
53
53
|
"jsc": {
|
54
54
|
"experimental": {
|
55
55
|
"plugins": [
|
56
|
-
["swc-plugin-
|
56
|
+
["swc-plugin-component-annotate", {
|
57
57
|
"native": false,
|
58
58
|
"annotate-fragments": false,
|
59
59
|
"ignored-components": ["MyIgnoredComponent"],
|
@@ -92,7 +92,7 @@ To use Sentry-specific attribute names for compatibility with Sentry's tracking:
|
|
92
92
|
"jsc": {
|
93
93
|
"experimental": {
|
94
94
|
"plugins": [
|
95
|
-
["swc-plugin-
|
95
|
+
["swc-plugin-component-annotate", {
|
96
96
|
"component-attr": "data-sentry-component",
|
97
97
|
"element-attr": "data-sentry-element",
|
98
98
|
"source-file-attr": "data-sentry-source-file"
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "swc-plugin-component-annotate",
|
3
|
-
"version": "1.2.
|
3
|
+
"version": "1.2.2",
|
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",
|
package/src/lib.rs
CHANGED
@@ -13,7 +13,10 @@ use swc_core::{
|
|
13
13
|
ast::*,
|
14
14
|
visit::{noop_visit_mut_type, VisitMut, VisitMutWith},
|
15
15
|
},
|
16
|
-
plugin::{
|
16
|
+
plugin::{
|
17
|
+
metadata::TransformPluginMetadataContextKind, plugin_transform,
|
18
|
+
proxies::TransformPluginProgramMetadata,
|
19
|
+
},
|
17
20
|
};
|
18
21
|
|
19
22
|
pub struct ReactComponentAnnotateVisitor {
|
@@ -310,8 +313,16 @@ pub fn process_transform(
|
|
310
313
|
PluginConfig::default()
|
311
314
|
};
|
312
315
|
|
313
|
-
|
314
|
-
|
316
|
+
// Try to get the actual filename from the metadata context
|
317
|
+
let filename = if let Some(filename_str) =
|
318
|
+
metadata.get_context(&TransformPluginMetadataContextKind::Filename)
|
319
|
+
{
|
320
|
+
FileName::Custom(filename_str)
|
321
|
+
} else {
|
322
|
+
FileName::Custom("unknown".to_string())
|
323
|
+
};
|
324
|
+
|
325
|
+
let mut visitor = ReactComponentAnnotateVisitor::new(config, &filename);
|
315
326
|
program.visit_mut_with(&mut visitor);
|
316
327
|
program
|
317
328
|
}
|
Binary file
|