diff --git a/napi/transform/index.d.ts b/napi/transform/index.d.ts index 0347bbf13d0c9..4e78bfd82d6d1 100644 --- a/napi/transform/index.d.ts +++ b/napi/transform/index.d.ts @@ -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. * diff --git a/napi/transform/src/options.rs b/napi/transform/src/options.rs index b8d5e490549a1..2dc26f524dc65 100644 --- a/napi/transform/src/options.rs +++ b/napi/transform/src/options.rs @@ -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, + + /// The current working directory. Used to resolve relative paths in other + /// options. + pub cwd: Option, + + /// Configure how TypeScript is transformed. + pub typescript: Option, + + /// Configure how TSX and JSX are transformed. + pub react: Option, + + /// Enable ES2015 transformations. + pub es2015: Option, + + /// Enable source map generation. + /// + /// When `true`, the `sourceMap` field of transform result objects will be populated. + /// + /// @default false + /// + /// @see {@link SourceMap} + pub sourcemap: Option, +} + +impl From 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 { @@ -234,52 +278,3 @@ impl From 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, - - /// The current working directory. Used to resolve relative paths in other - /// options. - pub cwd: Option, - - /// Force jsx parsing, - /// - /// @default false - pub jsx: Option, - - /// Configure how TypeScript is transformed. - pub typescript: Option, - - /// Configure how TSX and JSX are transformed. - pub react: Option, - - /// Enable ES2015 transformations. - pub es2015: Option, - - /// Enable source map generation. - /// - /// When `true`, the `sourceMap` field of transform result objects will be populated. - /// - /// @default false - /// - /// @see {@link SourceMap} - pub sourcemap: Option, -} - -impl From 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() - } - } -} diff --git a/napi/transform/src/transformer.rs b/napi/transform/src/transformer.rs index a2925cf1af36d..82e9bd99b6354 100644 --- a/napi/transform/src/transformer.rs +++ b/napi/transform/src/transformer.rs @@ -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 };