@@ -220,6 +220,39 @@ 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+ /// }
237+ /// ```
238+ ///
239+ /// The option is used to align with the behavior of TypeScript's `useDefineForClassFields: false` option.
240+ /// When you want to enable this, you also need to set [`crate::CompilerAssumptions::set_public_class_fields`]
241+ /// to `true`. The `set_public_class_fields: true` + `remove_class_fields_without_initializer: true` is
242+ /// equivalent to `useDefineForClassFields: false` in TypeScript.
243+ ///
244+ /// When `set_public_class_fields` is true and class-properties plugin is enabled, the above example transforms into:
245+ ///
246+ /// ```js
247+ /// class Foo {
248+ /// constructor() {
249+ /// this.y = 0;
250+ /// }
251+ /// }
252+ /// ```
253+ ///
254+ /// Defaults to `false`.
255+ pub remove_class_fields_without_initializer : Option < bool > ,
223256 /// Also generate a `.d.ts` declaration file for TypeScript files.
224257 ///
225258 /// The source file must be compliant with all
@@ -252,8 +285,9 @@ impl From<TypeScriptOptions> for oxc::transformer::TypeScriptOptions {
252285 allow_namespaces : options. allow_namespaces . unwrap_or ( ops. allow_namespaces ) ,
253286 allow_declare_fields : options. allow_declare_fields . unwrap_or ( ops. allow_declare_fields ) ,
254287 optimize_const_enums : false ,
255- // TODO: Implement
256- remove_class_fields_without_initializer : false ,
288+ remove_class_fields_without_initializer : options
289+ . remove_class_fields_without_initializer
290+ . unwrap_or ( ops. remove_class_fields_without_initializer ) ,
257291 rewrite_import_extensions : options. rewrite_import_extensions . and_then ( |value| {
258292 match value {
259293 Either :: A ( v) => {
0 commit comments