swc-plugin-component-annotate 1.2.1 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swc-plugin-component-annotate",
3
- "version": "1.2.1",
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::{plugin_transform, proxies::TransformPluginProgramMetadata},
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
- let mut visitor =
314
- ReactComponentAnnotateVisitor::new(config, &FileName::Custom("unknown".to_string()));
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