@@ -21,7 +21,7 @@ use swc_plugin_macro::plugin_transform;
2121use swc_plugin_proxy:: { PluginCommentsProxy , TransformPluginProgramMetadata } ;
2222use tracing:: debug;
2323
24- use crate :: util:: get_import_arg;
24+ use crate :: util:: { expect_fn_body , get_import_arg} ;
2525
2626mod util;
2727
@@ -384,7 +384,7 @@ where
384384 key : PropName :: Ident ( quote_ident ! ( "chunkName" ) ) ,
385385 function : Box :: new ( Function {
386386 params : clone_params ( func) ,
387- body : Some ( BlockStmt {
387+ body : Some ( FunctionBody {
388388 stmts : vec ! [ Stmt :: Return ( ReturnStmt {
389389 span: DUMMY_SP ,
390390 arg: Some ( Box :: new( self . replace_chunk_name( import) ) ) ,
@@ -407,9 +407,8 @@ where
407407 decorators: Default :: default ( ) ,
408408 pat: Pat :: Ident ( quote_ident!( "props" ) . into( ) ) ,
409409 } ] ,
410- body : Some (
411- quote ! (
412- "
410+ body : Some ( expect_fn_body ( quote ! (
411+ "
413412 {
414413 const key=this.resolve(props)
415414 if (this.resolved[key] !== true) {
@@ -423,9 +422,7 @@ where
423422 return false
424423 }
425424 " as Stmt
426- )
427- . expect_block ( ) ,
428- ) ,
425+ ) ) ) ,
429426 is_generator : false ,
430427 is_async : false ,
431428 ..Default :: default ( )
@@ -449,9 +446,8 @@ where
449446 decorators: Default :: default ( ) ,
450447 pat: Pat :: Ident ( quote_ident!( "props" ) . into( ) ) ,
451448 } ] ,
452- body : Some (
453- quote ! (
454- "
449+ body : Some ( expect_fn_body ( quote ! (
450+ "
455451 {
456452 const key = this.resolve(props)
457453 this.resolved[key] = false
@@ -461,9 +457,7 @@ where
461457 });
462458 }
463459 " as Stmt
464- )
465- . expect_block ( ) ,
466- ) ,
460+ ) ) ) ,
467461 is_generator : false ,
468462 is_async : false ,
469463 ..Default :: default ( )
@@ -480,9 +474,8 @@ where
480474 decorators: Default :: default ( ) ,
481475 pat: Pat :: Ident ( quote_ident!( "props" ) . into( ) ) ,
482476 } ] ,
483- body : Some (
484- quote ! (
485- "
477+ body : Some ( expect_fn_body ( quote ! (
478+ "
486479 {
487480 const id = this.resolve(props)
488481
@@ -493,9 +486,7 @@ where
493486 return eval('module.require')(id)
494487 }
495488 " as Stmt
496- )
497- . expect_block ( ) ,
498- ) ,
489+ ) ) ) ,
499490 is_generator : false ,
500491 is_async : false ,
501492 ..Default :: default ( )
@@ -514,9 +505,8 @@ where
514505 key : PropName :: Ident ( quote_ident ! ( "resolve" ) ) ,
515506 function : Box :: new ( Function {
516507 params : clone_params ( func) ,
517- body : Some (
518- quote ! (
519- "
508+ body : Some ( expect_fn_body ( quote ! (
509+ "
520510 {
521511 if (require.resolveWeak) {
522512 return require.resolveWeak($id)
@@ -525,10 +515,8 @@ where
525515 return eval('require.resolve')($id)
526516 }
527517 " as Stmt ,
528- id: Expr = get_call_value( import)
529- )
530- . expect_block ( ) ,
531- ) ,
518+ id: Expr = get_call_value( import)
519+ ) ) ) ,
532520 is_generator : false ,
533521 is_async : false ,
534522 ..Default :: default ( )
0 commit comments