Skip to content

Commit

Permalink
fix(napi/transform): remove confusing jsx option (#6159)
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Sep 29, 2024
1 parent ea908f7 commit f27d59f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 60 deletions.
8 changes: 1 addition & 7 deletions napi/transform/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,18 +187,12 @@ export interface TransformOptions {
* options.
*/
cwd?: string
/**
* Force jsx parsing,
*
* @default false
*/
jsx?: boolean
/** Configure how TypeScript is transformed. */
typescript?: TypeScriptBindingOptions
/** Configure how TSX and JSX are transformed. */
react?: ReactBindingOptions
/** Enable ES2015 transformations. */
es2015?: Es2015BindingOptions
es2015?: ES2015BindingOptions
/**
* Enable source map generation.
*
Expand Down
93 changes: 44 additions & 49 deletions napi/transform/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,50 @@ use oxc_transformer::{

use crate::IsolatedDeclarationsOptions;

/// Options for transforming a JavaScript or TypeScript file.
///
/// @see {@link transform}
#[napi(object)]
#[derive(Default)]
pub struct TransformOptions {
#[napi(ts_type = "'script' | 'module' | 'unambiguous' | undefined")]
pub source_type: Option<String>,

/// The current working directory. Used to resolve relative paths in other
/// options.
pub cwd: Option<String>,

/// Configure how TypeScript is transformed.
pub typescript: Option<TypeScriptBindingOptions>,

/// Configure how TSX and JSX are transformed.
pub react: Option<ReactBindingOptions>,

/// Enable ES2015 transformations.
pub es2015: Option<ES2015BindingOptions>,

/// Enable source map generation.
///
/// When `true`, the `sourceMap` field of transform result objects will be populated.
///
/// @default false
///
/// @see {@link SourceMap}
pub sourcemap: Option<bool>,
}

impl From<TransformOptions> for oxc_transformer::TransformOptions {
fn from(options: TransformOptions) -> Self {
Self {
cwd: options.cwd.map(PathBuf::from).unwrap_or_default(),
typescript: options.typescript.map(Into::into).unwrap_or_default(),
react: options.react.map(Into::into).unwrap_or_default(),
es2015: options.es2015.map(Into::into).unwrap_or_default(),
..Self::default()
}
}
}

#[napi(object)]
#[derive(Default)]
pub struct TypeScriptBindingOptions {
Expand Down Expand Up @@ -234,52 +278,3 @@ impl From<ES2015BindingOptions> for ES2015Options {
ES2015Options { arrow_function: options.arrow_function.map(Into::into) }
}
}

/// Options for transforming a JavaScript or TypeScript file.
///
/// @see {@link transform}
#[napi(object)]
#[derive(Default)]
pub struct TransformOptions {
#[napi(ts_type = "'script' | 'module' | 'unambiguous' | undefined")]
pub source_type: Option<String>,

/// The current working directory. Used to resolve relative paths in other
/// options.
pub cwd: Option<String>,

/// Force jsx parsing,
///
/// @default false
pub jsx: Option<bool>,

/// Configure how TypeScript is transformed.
pub typescript: Option<TypeScriptBindingOptions>,

/// Configure how TSX and JSX are transformed.
pub react: Option<ReactBindingOptions>,

/// Enable ES2015 transformations.
pub es2015: Option<ES2015BindingOptions>,

/// Enable source map generation.
///
/// When `true`, the `sourceMap` field of transform result objects will be populated.
///
/// @default false
///
/// @see {@link SourceMap}
pub sourcemap: Option<bool>,
}

impl From<TransformOptions> for oxc_transformer::TransformOptions {
fn from(options: TransformOptions) -> Self {
Self {
cwd: options.cwd.map(PathBuf::from).unwrap_or_default(),
typescript: options.typescript.map(Into::into).unwrap_or_default(),
react: options.react.map(Into::into).unwrap_or_default(),
es2015: options.es2015.map(Into::into).unwrap_or_default(),
..Self::default()
}
}
}
4 changes: 0 additions & 4 deletions napi/transform/src/transformer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ pub fn transform(
Some("module") => source_type = source_type.with_module(true),
_ => {}
}
// Force `jsx`
if let Some(jsx) = options.as_ref().and_then(|options| options.jsx.as_ref()) {
source_type = source_type.with_jsx(*jsx);
}
source_type
};

Expand Down

0 comments on commit f27d59f

Please sign in to comment.