@@ -414,12 +414,6 @@ fn op_emit(state: &mut OpState, #[serde] args: EmitArgs) -> bool {
414
414
true
415
415
}
416
416
417
- #[ derive( Debug , Deserialize ) ]
418
- struct LoadArgs {
419
- /// The fully qualified specifier that should be loaded.
420
- specifier : String ,
421
- }
422
-
423
417
pub fn as_ts_script_kind ( media_type : MediaType ) -> i32 {
424
418
match media_type {
425
419
MediaType :: JavaScript => 1 ,
@@ -453,36 +447,37 @@ struct LoadResponse {
453
447
#[ serde]
454
448
fn op_load (
455
449
state : & mut OpState ,
456
- #[ serde ] v : LoadArgs ,
450
+ #[ string ] load_specifier : & str ,
457
451
) -> Result < LoadResponse , AnyError > {
458
452
let state = state. borrow_mut :: < State > ( ) ;
459
453
460
- let specifier = normalize_specifier ( & v . specifier , & state. current_dir )
454
+ let specifier = normalize_specifier ( load_specifier , & state. current_dir )
461
455
. context ( "Error converting a string module specifier for \" op_load\" ." ) ?;
462
456
463
457
let mut hash: Option < String > = None ;
464
458
let mut media_type = MediaType :: Unknown ;
465
459
let graph = & state. graph ;
466
460
467
- let data = if & v . specifier == "internal:///.tsbuildinfo" {
461
+ let data = if load_specifier == "internal:///.tsbuildinfo" {
468
462
state. maybe_tsbuildinfo . as_deref ( ) . map ( Cow :: Borrowed )
469
463
// in certain situations we return a "blank" module to tsc and we need to
470
464
// handle the request for that module here.
471
- } else if & v . specifier == "internal:///missing_dependency.d.ts" {
465
+ } else if load_specifier == "internal:///missing_dependency.d.ts" {
472
466
hash = Some ( "1" . to_string ( ) ) ;
473
467
media_type = MediaType :: Dts ;
474
468
Some ( Cow :: Borrowed ( "declare const __: any;\n export = __;\n " ) )
475
- } else if let Some ( name) = v . specifier . strip_prefix ( "asset:///" ) {
469
+ } else if let Some ( name) = load_specifier . strip_prefix ( "asset:///" ) {
476
470
let maybe_source = get_lazily_loaded_asset ( name) ;
477
471
hash = get_maybe_hash ( maybe_source, state. hash_data ) ;
478
- media_type = MediaType :: from_str ( & v . specifier ) ;
472
+ media_type = MediaType :: from_str ( load_specifier ) ;
479
473
maybe_source. map ( Cow :: Borrowed )
480
474
} else {
481
475
let specifier = if let Some ( remapped_specifier) =
482
- state. remapped_specifiers . get ( & v . specifier )
476
+ state. remapped_specifiers . get ( load_specifier )
483
477
{
484
478
remapped_specifier
485
- } else if let Some ( remapped_specifier) = state. root_map . get ( & v. specifier ) {
479
+ } else if let Some ( remapped_specifier) = state. root_map . get ( load_specifier)
480
+ {
486
481
remapped_specifier
487
482
} else {
488
483
& specifier
@@ -1062,13 +1057,8 @@ mod tests {
1062
1057
Some ( "some content" . to_string ( ) ) ,
1063
1058
)
1064
1059
. await ;
1065
- let actual = op_load:: call (
1066
- & mut state,
1067
- LoadArgs {
1068
- specifier : "https://deno.land/x/mod.ts" . to_string ( ) ,
1069
- } ,
1070
- )
1071
- . unwrap ( ) ;
1060
+ let actual =
1061
+ op_load:: call ( & mut state, "https://deno.land/x/mod.ts" ) . unwrap ( ) ;
1072
1062
assert_eq ! (
1073
1063
serde_json:: to_value( actual) . unwrap( ) ,
1074
1064
json!( {
@@ -1087,13 +1077,8 @@ mod tests {
1087
1077
Some ( "some content" . to_string ( ) ) ,
1088
1078
)
1089
1079
. await ;
1090
- let actual = op_load:: call (
1091
- & mut state,
1092
- LoadArgs {
1093
- specifier : "asset:///lib.dom.d.ts" . to_string ( ) ,
1094
- } ,
1095
- )
1096
- . expect ( "should have invoked op" ) ;
1080
+ let actual = op_load:: call ( & mut state, "asset:///lib.dom.d.ts" )
1081
+ . expect ( "should have invoked op" ) ;
1097
1082
let expected = get_lazily_loaded_asset ( "lib.dom.d.ts" ) . unwrap ( ) ;
1098
1083
assert_eq ! ( actual. data. unwrap( ) , expected) ;
1099
1084
assert ! ( actual. version. is_some( ) ) ;
@@ -1108,13 +1093,8 @@ mod tests {
1108
1093
Some ( "some content" . to_string ( ) ) ,
1109
1094
)
1110
1095
. await ;
1111
- let actual = op_load:: call (
1112
- & mut state,
1113
- LoadArgs {
1114
- specifier : "internal:///.tsbuildinfo" . to_string ( ) ,
1115
- } ,
1116
- )
1117
- . expect ( "should have invoked op" ) ;
1096
+ let actual = op_load:: call ( & mut state, "internal:///.tsbuildinfo" )
1097
+ . expect ( "should have invoked op" ) ;
1118
1098
assert_eq ! (
1119
1099
serde_json:: to_value( actual) . unwrap( ) ,
1120
1100
json!( {
@@ -1128,13 +1108,8 @@ mod tests {
1128
1108
#[ tokio:: test]
1129
1109
async fn test_load_missing_specifier ( ) {
1130
1110
let mut state = setup ( None , None , None ) . await ;
1131
- let actual = op_load:: call (
1132
- & mut state,
1133
- LoadArgs {
1134
- specifier : "https://deno.land/x/mod.ts" . to_string ( ) ,
1135
- } ,
1136
- )
1137
- . expect ( "should have invoked op" ) ;
1111
+ let actual = op_load:: call ( & mut state, "https://deno.land/x/mod.ts" )
1112
+ . expect ( "should have invoked op" ) ;
1138
1113
assert_eq ! (
1139
1114
serde_json:: to_value( actual) . unwrap( ) ,
1140
1115
json!( {
0 commit comments