diff --git a/crates/oxc/src/napi/transform.rs b/crates/oxc/src/napi/transform.rs index bf4b2e9a5f421..e247eb9e42c55 100644 --- a/crates/oxc/src/napi/transform.rs +++ b/crates/oxc/src/napi/transform.rs @@ -74,6 +74,9 @@ pub struct TransformOptions { /// @see {@link SourceMap} pub sourcemap: Option, + /// Set assumptions in order to produce smaller output. + pub assumptions: Option, + /// Configure how TypeScript is transformed. pub typescript: Option, @@ -114,6 +117,7 @@ impl TryFrom for oxc_transformer::TransformOptions { }; Ok(Self { cwd: options.cwd.map(PathBuf::from).unwrap_or_default(), + assumptions: options.assumptions.map(Into::into).unwrap_or_default(), typescript: options .typescript .map(oxc_transformer::TypeScriptOptions::from) @@ -125,6 +129,36 @@ impl TryFrom for oxc_transformer::TransformOptions { } } +#[napi(object)] +#[derive(Default, Debug)] +pub struct CompilerAssumptions { + pub ignore_function_length: Option, + pub no_document_all: Option, + pub object_rest_no_symbols: Option, + pub pure_getters: Option, + pub set_public_class_fields: Option, +} + +impl From for oxc_transformer::CompilerAssumptions { + fn from(value: CompilerAssumptions) -> Self { + let ops = oxc_transformer::CompilerAssumptions::default(); + Self { + ignore_function_length: value + .ignore_function_length + .unwrap_or(ops.ignore_function_length), + no_document_all: value.no_document_all.unwrap_or(ops.no_document_all), + object_rest_no_symbols: value + .object_rest_no_symbols + .unwrap_or(ops.object_rest_no_symbols), + pure_getters: value.pure_getters.unwrap_or(ops.pure_getters), + set_public_class_fields: value + .set_public_class_fields + .unwrap_or(ops.set_public_class_fields), + ..ops + } + } +} + #[napi(object)] #[derive(Default)] pub struct TypeScriptOptions { diff --git a/napi/transform/index.d.ts b/napi/transform/index.d.ts index abac5894f1fa9..155b71a0a1d13 100644 --- a/napi/transform/index.d.ts +++ b/napi/transform/index.d.ts @@ -12,6 +12,14 @@ export interface ArrowFunctionsOptions { spec?: boolean } +export interface CompilerAssumptions { + ignoreFunctionLength?: boolean + noDocumentAll?: boolean + objectRestNoSymbols?: boolean + pureGetters?: boolean + setPublicClassFields?: boolean +} + export interface Es2015Options { /** Transform arrow functions into function expressions. */ arrowFunction?: ArrowFunctionsOptions @@ -199,6 +207,8 @@ export interface TransformOptions { * @see {@link SourceMap} */ sourcemap?: boolean + /** Set assumptions in order to produce smaller output. */ + assumptions?: CompilerAssumptions /** Configure how TypeScript is transformed. */ typescript?: TypeScriptOptions /** Configure how TSX and JSX are transformed. */