From 426184598c7f8bce3a3850b8e8b0224516b63b1b Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Fri, 27 Feb 2026 12:28:57 -0500 Subject: [PATCH 1/2] feat: Match more class declarations for export alias check --- src/instrumentation.rs | 38 ++++++++++++++++--- tests/const_class_export_alias_mjs/mod.mjs | 7 ++++ tests/const_class_export_alias_mjs/mod.rs | 15 ++++++++ tests/const_class_export_alias_mjs/test.mjs | 12 ++++++ tests/instrumentor_test.rs | 4 ++ tests/let_class_export_alias_mjs/mod.mjs | 7 ++++ tests/let_class_export_alias_mjs/mod.rs | 15 ++++++++ tests/let_class_export_alias_mjs/test.mjs | 12 ++++++ tests/var_class_export_alias_mjs/mod.mjs | 7 ++++ tests/var_class_export_alias_mjs/mod.rs | 15 ++++++++ tests/var_class_export_alias_mjs/test.mjs | 12 ++++++ .../var_named_class_export_alias_mjs/mod.mjs | 13 +++++++ tests/var_named_class_export_alias_mjs/mod.rs | 15 ++++++++ .../var_named_class_export_alias_mjs/test.mjs | 12 ++++++ 14 files changed, 179 insertions(+), 5 deletions(-) create mode 100644 tests/const_class_export_alias_mjs/mod.mjs create mode 100644 tests/const_class_export_alias_mjs/mod.rs create mode 100644 tests/const_class_export_alias_mjs/test.mjs create mode 100644 tests/let_class_export_alias_mjs/mod.mjs create mode 100644 tests/let_class_export_alias_mjs/mod.rs create mode 100644 tests/let_class_export_alias_mjs/test.mjs create mode 100644 tests/var_class_export_alias_mjs/mod.mjs create mode 100644 tests/var_class_export_alias_mjs/mod.rs create mode 100644 tests/var_class_export_alias_mjs/test.mjs create mode 100644 tests/var_named_class_export_alias_mjs/mod.mjs create mode 100644 tests/var_named_class_export_alias_mjs/mod.rs create mode 100644 tests/var_named_class_export_alias_mjs/test.mjs diff --git a/src/instrumentation.rs b/src/instrumentation.rs index 58d5917..1322e01 100644 --- a/src/instrumentation.rs +++ b/src/instrumentation.rs @@ -287,6 +287,18 @@ impl Instrumentation { if let Pat::Ident(name) = &decl.name { traced = self.trace_expr_or_count(func_expr, &name.id.sym); } + } else if let Some(class_expr) = init.as_mut_class() { + if let Pat::Ident(name) = &decl.name { + if class_expr.ident.is_none() { + class_expr.ident = Some(name.id.clone()); + } else { + self.is_correct_class = self + .config + .function_query + .class_name() + .is_none_or(|class| name.id.sym.as_ref() == class); + } + } } } } @@ -303,11 +315,13 @@ impl Instrumentation { } pub fn visit_mut_class_expr(&mut self, node: &mut ClassExpr) -> bool { - self.is_correct_class = self.config.function_query.class_name().is_none_or(|class| { - node.ident - .as_ref() - .is_some_and(|ident| ident.sym.as_ref() == class) - }); + if !self.is_correct_class { + self.is_correct_class = self.config.function_query.class_name().is_none_or(|class| { + node.ident + .as_ref() + .is_some_and(|ident| ident.sym.as_ref() == class) + }); + } true } @@ -416,6 +430,20 @@ impl Instrumentation { _ => {} } } + } else if let Some(class_expr) = node.right.as_mut_class() { + if let AssignTarget::Simple(target) = &node.left { + if let SimpleAssignTarget::Ident(name) = target { + if class_expr.ident.is_none() { + class_expr.ident = Some(name.id.clone()); + } else { + self.is_correct_class = self + .config + .function_query + .class_name() + .is_none_or(|class| name.id.sym.as_ref() == class); + } + } + } } !traced } diff --git a/tests/const_class_export_alias_mjs/mod.mjs b/tests/const_class_export_alias_mjs/mod.mjs new file mode 100644 index 0000000..0348c70 --- /dev/null +++ b/tests/const_class_export_alias_mjs/mod.mjs @@ -0,0 +1,7 @@ +const J = class { + async fetch(url) { + return 42; + } +}; + +export { J as Undici }; diff --git a/tests/const_class_export_alias_mjs/mod.rs b/tests/const_class_export_alias_mjs/mod.rs new file mode 100644 index 0000000..1be5651 --- /dev/null +++ b/tests/const_class_export_alias_mjs/mod.rs @@ -0,0 +1,15 @@ +use crate::common::*; +use orchestrion_js::*; + +#[test] +fn const_class_export_alias_mjs() { + transpile_and_test( + file!(), + true, + Config::new_single(InstrumentationConfig::new( + "Undici:fetch", + test_module_matcher(), + FunctionQuery::class_method("Undici", "fetch", FunctionKind::Async).as_export_alias(), + )), + ); +} diff --git a/tests/const_class_export_alias_mjs/test.mjs b/tests/const_class_export_alias_mjs/test.mjs new file mode 100644 index 0000000..3b4fdd4 --- /dev/null +++ b/tests/const_class_export_alias_mjs/test.mjs @@ -0,0 +1,12 @@ +import { Undici } from './instrumented.mjs'; +import { assert, getContext } from '../common/preamble.js'; +const context = getContext('orchestrion:undici:Undici:fetch'); +const undici = new Undici(); +const result = await undici.fetch('https://example.com'); +assert.strictEqual(result, 42); +assert.deepStrictEqual(context, { + start: true, + end: true, + asyncStart: 42, + asyncEnd: 42 +}); diff --git a/tests/instrumentor_test.rs b/tests/instrumentor_test.rs index 6c50772..eaaba3b 100644 --- a/tests/instrumentor_test.rs +++ b/tests/instrumentor_test.rs @@ -7,6 +7,7 @@ mod common; mod arguments_mutation; mod class_expression_cjs; mod class_method_cjs; +mod const_class_export_alias_mjs; mod constructor_cjs; mod constructor_mjs; mod decl_cjs; @@ -18,6 +19,7 @@ mod expr_cjs; mod expr_mjs; mod index_cjs; mod injection_failure; +mod let_class_export_alias_mjs; mod multiple_class_method_cjs; mod multiple_load_cjs; mod nested_functions; @@ -25,3 +27,5 @@ mod object_method_cjs; mod polyfill_cjs; mod polyfill_mjs; mod private_method_cjs; +mod var_class_export_alias_mjs; +mod var_named_class_export_alias_mjs; diff --git a/tests/let_class_export_alias_mjs/mod.mjs b/tests/let_class_export_alias_mjs/mod.mjs new file mode 100644 index 0000000..fb20b68 --- /dev/null +++ b/tests/let_class_export_alias_mjs/mod.mjs @@ -0,0 +1,7 @@ +let J = class { + async fetch(url) { + return 42; + } +}; + +export { J as Undici }; diff --git a/tests/let_class_export_alias_mjs/mod.rs b/tests/let_class_export_alias_mjs/mod.rs new file mode 100644 index 0000000..c9f5774 --- /dev/null +++ b/tests/let_class_export_alias_mjs/mod.rs @@ -0,0 +1,15 @@ +use crate::common::*; +use orchestrion_js::*; + +#[test] +fn let_class_export_alias_mjs() { + transpile_and_test( + file!(), + true, + Config::new_single(InstrumentationConfig::new( + "Undici:fetch", + test_module_matcher(), + FunctionQuery::class_method("Undici", "fetch", FunctionKind::Async).as_export_alias(), + )), + ); +} diff --git a/tests/let_class_export_alias_mjs/test.mjs b/tests/let_class_export_alias_mjs/test.mjs new file mode 100644 index 0000000..3b4fdd4 --- /dev/null +++ b/tests/let_class_export_alias_mjs/test.mjs @@ -0,0 +1,12 @@ +import { Undici } from './instrumented.mjs'; +import { assert, getContext } from '../common/preamble.js'; +const context = getContext('orchestrion:undici:Undici:fetch'); +const undici = new Undici(); +const result = await undici.fetch('https://example.com'); +assert.strictEqual(result, 42); +assert.deepStrictEqual(context, { + start: true, + end: true, + asyncStart: 42, + asyncEnd: 42 +}); diff --git a/tests/var_class_export_alias_mjs/mod.mjs b/tests/var_class_export_alias_mjs/mod.mjs new file mode 100644 index 0000000..cb5cb8f --- /dev/null +++ b/tests/var_class_export_alias_mjs/mod.mjs @@ -0,0 +1,7 @@ +var J = class { + async fetch(url) { + return 42; + } +}; + +export { J as Undici }; diff --git a/tests/var_class_export_alias_mjs/mod.rs b/tests/var_class_export_alias_mjs/mod.rs new file mode 100644 index 0000000..18245a3 --- /dev/null +++ b/tests/var_class_export_alias_mjs/mod.rs @@ -0,0 +1,15 @@ +use crate::common::*; +use orchestrion_js::*; + +#[test] +fn var_class_export_alias_mjs() { + transpile_and_test( + file!(), + true, + Config::new_single(InstrumentationConfig::new( + "Undici:fetch", + test_module_matcher(), + FunctionQuery::class_method("Undici", "fetch", FunctionKind::Async).as_export_alias(), + )), + ); +} diff --git a/tests/var_class_export_alias_mjs/test.mjs b/tests/var_class_export_alias_mjs/test.mjs new file mode 100644 index 0000000..3b4fdd4 --- /dev/null +++ b/tests/var_class_export_alias_mjs/test.mjs @@ -0,0 +1,12 @@ +import { Undici } from './instrumented.mjs'; +import { assert, getContext } from '../common/preamble.js'; +const context = getContext('orchestrion:undici:Undici:fetch'); +const undici = new Undici(); +const result = await undici.fetch('https://example.com'); +assert.strictEqual(result, 42); +assert.deepStrictEqual(context, { + start: true, + end: true, + asyncStart: 42, + asyncEnd: 42 +}); diff --git a/tests/var_named_class_export_alias_mjs/mod.mjs b/tests/var_named_class_export_alias_mjs/mod.mjs new file mode 100644 index 0000000..5ba3d3c --- /dev/null +++ b/tests/var_named_class_export_alias_mjs/mod.mjs @@ -0,0 +1,13 @@ +class Base { + async fetch(url) { + return 0; + } +} + +var J = class InternalName extends Base { + async fetch(url) { + return 42; + } +}; + +export { J as Undici }; diff --git a/tests/var_named_class_export_alias_mjs/mod.rs b/tests/var_named_class_export_alias_mjs/mod.rs new file mode 100644 index 0000000..fcb87d3 --- /dev/null +++ b/tests/var_named_class_export_alias_mjs/mod.rs @@ -0,0 +1,15 @@ +use crate::common::*; +use orchestrion_js::*; + +#[test] +fn var_named_class_export_alias_mjs() { + transpile_and_test( + file!(), + true, + Config::new_single(InstrumentationConfig::new( + "Undici:fetch", + test_module_matcher(), + FunctionQuery::class_method("Undici", "fetch", FunctionKind::Async).as_export_alias(), + )), + ); +} diff --git a/tests/var_named_class_export_alias_mjs/test.mjs b/tests/var_named_class_export_alias_mjs/test.mjs new file mode 100644 index 0000000..3b4fdd4 --- /dev/null +++ b/tests/var_named_class_export_alias_mjs/test.mjs @@ -0,0 +1,12 @@ +import { Undici } from './instrumented.mjs'; +import { assert, getContext } from '../common/preamble.js'; +const context = getContext('orchestrion:undici:Undici:fetch'); +const undici = new Undici(); +const result = await undici.fetch('https://example.com'); +assert.strictEqual(result, 42); +assert.deepStrictEqual(context, { + start: true, + end: true, + asyncStart: 42, + asyncEnd: 42 +}); From 3b7f55169b6cab0030a60d529e10cfb5579693f6 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Fri, 27 Feb 2026 12:54:03 -0500 Subject: [PATCH 2/2] clippy --- src/instrumentation.rs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/instrumentation.rs b/src/instrumentation.rs index 1322e01..2748a86 100644 --- a/src/instrumentation.rs +++ b/src/instrumentation.rs @@ -431,17 +431,15 @@ impl Instrumentation { } } } else if let Some(class_expr) = node.right.as_mut_class() { - if let AssignTarget::Simple(target) = &node.left { - if let SimpleAssignTarget::Ident(name) = target { - if class_expr.ident.is_none() { - class_expr.ident = Some(name.id.clone()); - } else { - self.is_correct_class = self - .config - .function_query - .class_name() - .is_none_or(|class| name.id.sym.as_ref() == class); - } + if let AssignTarget::Simple(SimpleAssignTarget::Ident(name)) = &node.left { + if class_expr.ident.is_none() { + class_expr.ident = Some(name.id.clone()); + } else { + self.is_correct_class = self + .config + .function_query + .class_name() + .is_none_or(|class| name.id.sym.as_ref() == class); } } }