Skip to content

Commit 9117aa5

Browse files
committed
Apply review suggestions
1 parent 1ba8472 commit 9117aa5

File tree

15 files changed

+172
-212
lines changed

15 files changed

+172
-212
lines changed

instrumentation-wasm/Cargo.lock

Lines changed: 52 additions & 60 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

instrumentation-wasm/Cargo.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ name = "node_code_instrumentation"
1010
crate-type = ["cdylib", "rlib"]
1111

1212
[dependencies]
13-
oxc_allocator = "0.73.2"
14-
oxc_ast = "0.73.2"
15-
oxc_codegen = "0.73.2"
16-
oxc_parser = "0.73.2"
17-
oxc_semantic = "0.73.2"
18-
oxc_span = "0.73.2"
19-
oxc_traverse = "0.73.2"
13+
oxc_allocator = "0.74.0"
14+
oxc_ast = "0.74.0"
15+
oxc_codegen = "0.74.0"
16+
oxc_parser = "0.74.0"
17+
oxc_semantic = "0.74.0"
18+
oxc_span = "0.74.0"
19+
oxc_traverse = "0.74.0"
2020
serde = "1.0.219"
2121
serde_json = "1.0.140"
2222
wasm-bindgen = "0.2.100"

instrumentation-wasm/src/js_transformer/helpers/get_name_str_for_member_expr.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
use oxc_allocator::{Allocator, CloneIn};
22
use oxc_ast::ast::{Expression, MemberExpression};
33

4+
/**
5+
* This funcion tries to get the name of a member expression in the form of a string.
6+
* Examples:
7+
* - `app.get = () => {}` will return `app.get`
8+
* - `app.prototype.get = () => {}` will return `app.prototype.get`
9+
* - `app[method] = () => {}` will return `app[method]`
10+
*/
411
pub fn get_name_str_for_member_expr<'a>(
512
allocator: &'a Allocator,
613
member_expr: &MemberExpression,

instrumentation-wasm/src/js_transformer/helpers/insert_import_statement.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ const IMPORT_METHODS: [(&str, ImportMethodPredicate); 3] = [
3232
),
3333
];
3434

35+
fn is_common_js(source_type: &SourceType, has_module_syntax: bool) -> bool {
36+
if source_type.is_script() {
37+
return true;
38+
}
39+
if source_type.is_unambiguous() && !has_module_syntax {
40+
return true; // Unambiguous mode without module syntax
41+
}
42+
false // Otherwise, it's ESM
43+
}
44+
3545
pub fn insert_import_statement<'a>(
3646
source_type: &SourceType,
3747
has_module_syntax: bool,
@@ -41,7 +51,7 @@ pub fn insert_import_statement<'a>(
4151
file_instructions: &FileInstructions,
4252
) {
4353
// Common JS require() statement
44-
if source_type.is_script() || source_type.is_unambiguous() && !has_module_syntax {
54+
if is_common_js(source_type, has_module_syntax) {
4555
let mut require_args: OxcVec<'a, Argument<'a>> = builder.vec_with_capacity(1);
4656
require_args.push(Argument::StringLiteral(builder.alloc_string_literal(
4757
SPAN,
Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
11
use oxc_span::SourceType;
22

3-
/*
4-
0 -> JS, auto-detect CJS or ESM
5-
1 -> TypeScript (ESM)
6-
2 -> CJS
7-
3 -> MJS (ESM)
8-
4 -> TSX
9-
Default -> JS, auto-detect CJS or ESM
10-
*/
11-
pub fn select_sourcetype_based_on_enum(src_type: i32) -> SourceType {
3+
pub fn select_sourcetype_based_on_enum(src_type: &str) -> SourceType {
124
// 0 is generic type.
135
match src_type {
14-
0 => SourceType::unambiguous(),
15-
1 => SourceType::ts(),
16-
2 => SourceType::cjs(),
17-
3 => SourceType::mjs(),
18-
4 => SourceType::tsx(),
6+
"unambiguous" => SourceType::unambiguous(),
7+
"ts" => SourceType::ts(),
8+
"cjs" => SourceType::cjs(),
9+
"mjs" => SourceType::mjs(),
10+
"tsx" => SourceType::tsx(),
11+
"jsx" => SourceType::jsx(),
1912
_ => SourceType::unambiguous(),
2013
}
2114
}

0 commit comments

Comments
 (0)