swc-plugin-component-annotate 1.2.1 → 1.3.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/package.json +1 -1
- package/src/lib.rs +15 -4
- package/swc_plugin_component_annotate.wasm +0 -0
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "swc-plugin-component-annotate",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.3.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",
|
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 {
|
@@ -42,7 +45,7 @@ impl ReactComponentAnnotateVisitor {
|
|
42
45
|
}
|
43
46
|
|
44
47
|
#[inline]
|
45
|
-
fn should_ignore_component(&self, component_name: &str) -> bool {
|
48
|
+
pub fn should_ignore_component(&self, component_name: &str) -> bool {
|
46
49
|
self.ignored_components_set.contains(component_name)
|
47
50
|
}
|
48
51
|
|
@@ -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
|