diff --git a/crates/oxc_transformer/src/es2022/class_properties/class.rs b/crates/oxc_transformer/src/es2022/class_properties/class.rs index cfc9b0dc7747d7..3463b862814ab3 100644 --- a/crates/oxc_transformer/src/es2022/class_properties/class.rs +++ b/crates/oxc_transformer/src/es2022/class_properties/class.rs @@ -263,6 +263,20 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> { // TODO(improve-on-babel): If outer scope is sloppy mode, all code which is moved to outside // the class should be wrapped in an IIFE with `'use strict'` directive. Babel doesn't do this. + // TODO: If static blocks transform is disabled, it's possible to get incorrect execution order. + // ```js + // class C { + // static x = console.log('x'); + // static { + // console.log('block'); + // } + // static y = console.log('y'); + // } + // ``` + // This logs "x", "block", "y". But in transformed output it'd be "block", "x", "y". + // Maybe force transform of static blocks if any static properties? + // Or alteratively could insert static property initializers into static blocks. + struct Constructor { element_index: usize, // TODO: Remove this if don't use it diff --git a/crates/oxc_transformer/src/es2022/class_properties/constructor.rs b/crates/oxc_transformer/src/es2022/class_properties/constructor.rs index 4c450c5ccdf350..19794f53425730 100644 --- a/crates/oxc_transformer/src/es2022/class_properties/constructor.rs +++ b/crates/oxc_transformer/src/es2022/class_properties/constructor.rs @@ -46,6 +46,11 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> { // If `_super` function is required outside class, insert it after class. // Note: Inserting it after class not before, so that other transforms run on it. + // TODO: That doesn't work - other transforms do not run on it. + // TODO: If static block transform is not enabled, it's possible to construct the class + // within the static block `class C { static { new C() } }` and that'd run before `_super` + // is defined. So it needs to go before the class, not after, in that case. + // TODO: `_super` should be a `let` binding, not `var`. if let Some((super_binding, super_func)) = maybe_super_func { if self.is_declaration { // `var _super = function() { ; return this; };`