diff --git a/crates/oxc_transformer/src/es2015/arrow_functions.rs b/crates/oxc_transformer/src/es2015/arrow_functions.rs index d0370e508..d931b9095 100644 --- a/crates/oxc_transformer/src/es2015/arrow_functions.rs +++ b/crates/oxc_transformer/src/es2015/arrow_functions.rs @@ -15,6 +15,9 @@ //! Babel gets this wrong: //! * Error on arrow functions in class properties. //! +//! or we can support it: +//! `class C { x = () => this; }` +//! -> `class C { x = (function(_this) { return () => _this; })(this); }` //! * Error on `super` in arrow functions. //! //! @@ -296,6 +299,7 @@ impl<'a> ArrowFunctions<'a> { // * `extends` clause // * Computed method key // * Computed property key + // * Computed accessor property key (but `this` in this position is not legal TS) // // ```js // // All these `this` refer to global `this` @@ -304,6 +308,8 @@ impl<'a> ArrowFunctions<'a> { // static [this] = 123; // [this]() {} // static [this]() {} + // accessor [this] = 123; + // static accessor [this] = 123; // } // ``` // @@ -323,6 +329,8 @@ impl<'a> ArrowFunctions<'a> { // static e() { this } // #f() { this } // g(x = this) {} + // accessor h = this; + // static accessor i = this; // static { this } // } // ``` @@ -337,8 +345,11 @@ impl<'a> ArrowFunctions<'a> { | Ancestor::FunctionBody(_) // Class property body | Ancestor::PropertyDefinitionValue(_) + // Class accessor property body + | Ancestor::AccessorPropertyValue(_) // Class static block | Ancestor::StaticBlockBody(_) => return None, + // Arrow function Ancestor::ArrowFunctionExpressionParams(func) => { return Some(func.scope_id().get().unwrap()) }