@@ -220,6 +220,40 @@ pub struct TypeScriptOptions {
220220 pub only_remove_type_imports : Option < bool > ,
221221 pub allow_namespaces : Option < bool > ,
222222 pub allow_declare_fields : Option < bool > ,
223+ /// When enabled, class fields without initializers are removed.
224+ ///
225+ /// For example:
226+ /// ```ts
227+ /// class Foo {
228+ /// x: number;
229+ /// y: number = 0;
230+ /// }
231+ /// ```
232+ /// // transform into
233+ /// ```js
234+ /// class Foo {
235+ /// x: number;
236+ /// y: number = 0;
237+ /// }
238+ /// ```
239+ ///
240+ /// The option is used to align with the behavior of TypeScript's `useDefineForClassFields: false` option.
241+ /// When you want to enable this, you also need to set [`crate::CompilerAssumptions::set_public_class_fields`]
242+ /// to `true`. The `set_public_class_fields: true` + `remove_class_fields_without_initializer: true` is
243+ /// equivalent to `useDefineForClassFields: false` in TypeScript.
244+ ///
245+ /// When `set_public_class_fields: true`, the above example transforms into:
246+ ///
247+ /// ```js
248+ /// class Foo {
249+ /// constructor() {
250+ /// this.y = 0;
251+ /// }
252+ /// }
253+ /// ```
254+ ///
255+ /// Defaults to `false`.
256+ pub remove_class_fields_without_initializer : Option < bool > ,
223257 /// Also generate a `.d.ts` declaration file for TypeScript files.
224258 ///
225259 /// The source file must be compliant with all
@@ -252,8 +286,9 @@ impl From<TypeScriptOptions> for oxc::transformer::TypeScriptOptions {
252286 allow_namespaces : options. allow_namespaces . unwrap_or ( ops. allow_namespaces ) ,
253287 allow_declare_fields : options. allow_declare_fields . unwrap_or ( ops. allow_declare_fields ) ,
254288 optimize_const_enums : false ,
255- // TODO: Implement
256- remove_class_fields_without_initializer : false ,
289+ remove_class_fields_without_initializer : options
290+ . remove_class_fields_without_initializer
291+ . unwrap_or ( ops. remove_class_fields_without_initializer ) ,
257292 rewrite_import_extensions : options. rewrite_import_extensions . and_then ( |value| {
258293 match value {
259294 Either :: A ( v) => {
0 commit comments