diff --git a/crates/oxc_transformer/src/es2022/class_properties/static_prop.rs b/crates/oxc_transformer/src/es2022/class_properties/static_prop.rs index 25293610b7956c..8a7a6013642b95 100644 --- a/crates/oxc_transformer/src/es2022/class_properties/static_prop.rs +++ b/crates/oxc_transformer/src/es2022/class_properties/static_prop.rs @@ -80,6 +80,30 @@ impl<'a, 'ctx, 'v> StaticInitializerVisitor<'a, 'ctx, 'v> { } impl<'a, 'ctx, 'v> VisitMut<'a> for StaticInitializerVisitor<'a, 'ctx, 'v> { + // TODO: Also need to call class visitors so private props stack is in correct state. + // Otherwise, in this example, `#x` in `getInnerX` is resolved incorrectly + // and `getInnerX()` will return 1 instead of 2. + // We have to visit the inner class now rather than later after exiting outer class so that + // `#y` in `getOuterY` resolves correctly too. + // ```js + // class Outer { + // #x = 1; + // #y = 1; + // static inner = class Inner { + // #x = 2; + // getInnerX() { + // return this.#x; // Should equal 2 + // } + // getOuterY() { + // return this.#y; // Should equal 1 + // } + // }; + // } + // ``` + // + // Need to save all per-class state (`insert_before` etc), and restore it again after. + // Using a stack would be overkill because nested classes in static blocks will be rare. + #[inline] fn visit_expression(&mut self, expr: &mut Expression<'a>) { match expr {