@@ -582,7 +582,7 @@ impl Options {
582
582
let disable_all_lints = experimental. disable_all_lints . into_bool ( ) ;
583
583
584
584
#[ cfg( feature = "plugin" ) ]
585
- let plugin_transforms = {
585
+ let plugin_transforms: Box < dyn Fold > = {
586
586
let transform_filename = match base {
587
587
FileName :: Real ( path) => path. as_os_str ( ) . to_str ( ) . map ( String :: from) ,
588
588
FileName :: Custom ( filename) => Some ( filename. to_owned ( ) ) ,
@@ -643,13 +643,13 @@ impl Options {
643
643
}
644
644
}
645
645
646
- crate :: plugin:: plugins (
646
+ Box :: new ( crate :: plugin:: plugins (
647
647
experimental. plugins ,
648
648
transform_metadata_context,
649
649
comments. cloned ( ) ,
650
650
cm. clone ( ) ,
651
651
unresolved_mark,
652
- )
652
+ ) )
653
653
}
654
654
655
655
// Native runtime plugin target, based on assumption we have
@@ -663,26 +663,28 @@ impl Options {
663
663
skipped. Refer https://github.com/swc-project/swc/issues/3934 for the details.",
664
664
) ;
665
665
666
- noop ( )
666
+ Box :: new ( noop ( ) )
667
667
}
668
668
} ;
669
669
670
670
#[ cfg( not( feature = "plugin" ) ) ]
671
- let plugin_transforms = {
671
+ let plugin_transforms: Box < dyn Fold > = {
672
672
if experimental. plugins . is_some ( ) {
673
673
handler. warn (
674
674
"Plugin is not supported with current @swc/core. Plugin transform will be \
675
675
skipped.",
676
676
) ;
677
677
}
678
- noop ( )
678
+ Box :: new ( noop ( ) )
679
679
} ;
680
680
681
+ let mut plugin_transforms = Some ( plugin_transforms) ;
682
+
681
683
let pass: Box < dyn Fold > = if experimental
682
684
. disable_builtin_transforms_for_internal_testing
683
685
. into_bool ( )
684
686
{
685
- Box :: new ( plugin_transforms)
687
+ plugin_transforms. unwrap ( )
686
688
} else {
687
689
let decorator_pass: Box < dyn Fold > =
688
690
match transform. decorator_version . unwrap_or_default ( ) {
@@ -698,6 +700,11 @@ impl Options {
698
700
} ;
699
701
700
702
Box :: new ( chain ! (
703
+ if experimental. run_plugin_first. into_bool( ) {
704
+ option_pass( plugin_transforms. take( ) )
705
+ } else {
706
+ Box :: new( noop( ) )
707
+ } ,
701
708
Optional :: new(
702
709
lint_to_fold( swc_ecma_lints:: rules:: all( LintParams {
703
710
program: & program,
@@ -748,7 +755,7 @@ impl Options {
748
755
) ,
749
756
syntax. typescript( )
750
757
) ,
751
- plugin_transforms,
758
+ option_pass ( plugin_transforms. take ( ) ) ,
752
759
custom_before_pass( & program) ,
753
760
// handle jsx
754
761
Optional :: new(
@@ -1225,6 +1232,9 @@ pub struct JscExperimental {
1225
1232
#[ serde( default ) ]
1226
1233
pub cache_root : Option < String > ,
1227
1234
1235
+ #[ serde( default ) ]
1236
+ pub run_plugin_first : BoolConfig < false > ,
1237
+
1228
1238
#[ serde( default ) ]
1229
1239
pub disable_builtin_transforms_for_internal_testing : BoolConfig < false > ,
1230
1240
@@ -1751,3 +1761,10 @@ fn build_resolver(
1751
1761
1752
1762
r
1753
1763
}
1764
+
1765
+ fn option_pass ( pass : Option < Box < dyn Fold > > ) -> Box < dyn Fold > {
1766
+ match pass {
1767
+ None => Box :: new ( noop ( ) ) ,
1768
+ Some ( pass) => pass,
1769
+ }
1770
+ }
0 commit comments