@@ -12,8 +12,8 @@ use oxc::{
1212 diagnostics:: OxcDiagnostic ,
1313 span:: SourceType ,
1414 transformer:: {
15- EnvOptions , InjectGlobalVariablesConfig , InjectImport , JsxRuntime ,
16- ReplaceGlobalDefinesConfig , RewriteExtensionsMode ,
15+ EnvOptions , HelperLoaderMode , HelperLoaderOptions , InjectGlobalVariablesConfig ,
16+ InjectImport , JsxRuntime , ReplaceGlobalDefinesConfig , RewriteExtensionsMode ,
1717 } ,
1818 CompilerInterface ,
1919} ;
@@ -107,6 +107,9 @@ pub struct TransformOptions {
107107 /// @see [esbuild#target](https://esbuild.github.io/api/#target)
108108 pub target : Option < Either < String , Vec < String > > > ,
109109
110+ /// Behaviour for runtime helpers.
111+ pub helpers : Option < Helpers > ,
112+
110113 /// Define Plugin
111114 #[ napi( ts_type = "Record<string, string>" ) ]
112115 pub define : Option < FxHashMap < String , String > > ,
@@ -134,7 +137,9 @@ impl TryFrom<TransformOptions> for oxc::transformer::TransformOptions {
134137 . unwrap_or_default ( ) ,
135138 jsx : options. jsx . map ( Into :: into) . unwrap_or_default ( ) ,
136139 env,
137- ..Self :: default ( )
140+ helper_loader : options
141+ . helpers
142+ . map_or_else ( HelperLoaderOptions :: default, HelperLoaderOptions :: from) ,
138143 } )
139144 }
140145}
@@ -393,6 +398,53 @@ impl From<Es2015Options> for oxc::transformer::ES2015Options {
393398 }
394399}
395400
401+ #[ napi( object) ]
402+ #[ derive( Default ) ]
403+ pub struct Helpers {
404+ pub mode : Option < HelperMode > ,
405+ }
406+
407+ #[ derive( Default , Clone , Copy ) ]
408+ #[ napi( string_enum) ]
409+ pub enum HelperMode {
410+ /// Runtime mode (default): Helper functions are imported from a runtime package.
411+ ///
412+ /// Example:
413+ ///
414+ /// ```js
415+ /// import helperName from "@babel/runtime/helpers/helperName";
416+ /// helperName(...arguments);
417+ /// ```
418+ #[ default]
419+ Runtime ,
420+ /// External mode: Helper functions are accessed from a global `babelHelpers` object.
421+ ///
422+ /// Example:
423+ ///
424+ /// ```js
425+ /// babelHelpers.helperName(...arguments);
426+ /// ```
427+ External ,
428+ }
429+
430+ impl From < Helpers > for HelperLoaderOptions {
431+ fn from ( value : Helpers ) -> Self {
432+ Self {
433+ mode : value. mode . map ( HelperLoaderMode :: from) . unwrap_or_default ( ) ,
434+ ..HelperLoaderOptions :: default ( )
435+ }
436+ }
437+ }
438+
439+ impl From < HelperMode > for HelperLoaderMode {
440+ fn from ( value : HelperMode ) -> Self {
441+ match value {
442+ HelperMode :: Runtime => Self :: Runtime ,
443+ HelperMode :: External => Self :: External ,
444+ }
445+ }
446+ }
447+
396448#[ derive( Default ) ]
397449struct Compiler {
398450 transform_options : oxc:: transformer:: TransformOptions ,
0 commit comments