mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
feat(napi/transform): export react refresh options (#5533)
Co-authored-by: Boshen <boshenc@gmail.com>
This commit is contained in:
parent
8c9179d58a
commit
aba9194ebc
2 changed files with 50 additions and 2 deletions
18
napi/transform/index.d.ts
vendored
18
napi/transform/index.d.ts
vendored
|
|
@ -113,6 +113,24 @@ export interface ReactBindingOptions {
|
|||
* @default false
|
||||
*/
|
||||
useSpread?: boolean
|
||||
/** Enable react fast refresh transform */
|
||||
refresh?: ReactRefreshBindingOptions
|
||||
}
|
||||
|
||||
export interface ReactRefreshBindingOptions {
|
||||
/**
|
||||
* Specify the identifier of the refresh registration variable.
|
||||
*
|
||||
* @default `$RefreshReg$`.
|
||||
*/
|
||||
refreshReg?: string
|
||||
/**
|
||||
* Specify the identifier of the refresh signature variable.
|
||||
*
|
||||
* @default `$RefreshSig$`.
|
||||
*/
|
||||
refreshSig?: string
|
||||
emitFullSignatures?: boolean
|
||||
}
|
||||
|
||||
export interface SourceMap {
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ use std::path::PathBuf;
|
|||
use napi::Either;
|
||||
use napi_derive::napi;
|
||||
use oxc_transformer::{
|
||||
ArrowFunctionsOptions, ES2015Options, ReactJsxRuntime, ReactOptions, RewriteExtensionsMode,
|
||||
TypeScriptOptions,
|
||||
ArrowFunctionsOptions, ES2015Options, ReactJsxRuntime, ReactOptions, ReactRefreshOptions,
|
||||
RewriteExtensionsMode, TypeScriptOptions,
|
||||
};
|
||||
|
||||
#[napi(object)]
|
||||
|
|
@ -140,6 +140,9 @@ pub struct ReactBindingOptions {
|
|||
///
|
||||
/// @default false
|
||||
pub use_spread: Option<bool>,
|
||||
|
||||
/// Enable react fast refresh transform
|
||||
pub refresh: Option<ReactRefreshBindingOptions>,
|
||||
}
|
||||
|
||||
impl From<ReactBindingOptions> for ReactOptions {
|
||||
|
|
@ -158,11 +161,38 @@ impl From<ReactBindingOptions> for ReactOptions {
|
|||
pragma_frag: options.pragma_frag,
|
||||
use_built_ins: options.use_built_ins,
|
||||
use_spread: options.use_spread,
|
||||
refresh: ops.refresh.map(Into::into),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[napi(object)]
|
||||
pub struct ReactRefreshBindingOptions {
|
||||
/// Specify the identifier of the refresh registration variable.
|
||||
///
|
||||
/// @default `$RefreshReg$`.
|
||||
pub refresh_reg: Option<String>,
|
||||
|
||||
/// Specify the identifier of the refresh signature variable.
|
||||
///
|
||||
/// @default `$RefreshSig$`.
|
||||
pub refresh_sig: Option<String>,
|
||||
|
||||
pub emit_full_signatures: Option<bool>,
|
||||
}
|
||||
|
||||
impl From<ReactRefreshBindingOptions> for ReactRefreshOptions {
|
||||
fn from(options: ReactRefreshBindingOptions) -> Self {
|
||||
let ops = ReactRefreshOptions::default();
|
||||
ReactRefreshOptions {
|
||||
refresh_reg: options.refresh_reg.unwrap_or(ops.refresh_reg),
|
||||
refresh_sig: options.refresh_sig.unwrap_or(ops.refresh_sig),
|
||||
emit_full_signatures: options.emit_full_signatures.unwrap_or(ops.emit_full_signatures),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[napi(object)]
|
||||
pub struct ArrowFunctionsBindingOptions {
|
||||
/// This option enables the following:
|
||||
|
|
|
|||
Loading…
Reference in a new issue