Repository: swc-project/swc (rust)

Issue:
`this` gets wrongly compiled to `(void 0)` when inside a property definition of an object literal
### Describe the bug

When defining a property on a plain object, references to `this` will be replaced erroneously with `void 0`. 

Example: 
```javascript
const foo = { 
    get prop1() {
        return 1
    },
    get prop2() {
        return this.prop1 + 1
    }
}
```

This will be compiled to:
```javascript
const foo = {
    get prop1() {
        return 1
    },
    get prop2 () {
        return (void 0).prop1 + 1;
    }
};
```

Note `(void 0)` inside `prop2`. This is incorrect because `this` should be a valid reference here. 

### Input code

```typescript
const foo = { 
    get prop1() {
        return 1
    },
    get prop2() {
        return this.prop1 + 1
    }
}
```


### Config

```json
{
  "test": [".*.ts",".*.js"],
  "exclude": [".*\\.d\\.ts$", ".*\\.map$"],
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": false,
      "decorators": false,
      "dynamicImport": false
    },
    "target" : "es2021"
  },
  "module": {
    "type": "commonjs"
  },
  "sourceMaps": true
}
```


### Playground link

https://play.swc.rs/?version=1.2.128&code=H4sIAAAAAAAAA0utKMgvKlFIzkksLlYILkksyUwOSS0ucQbzq7kUgKAYLKpQAhQOKMovULBVUPdIzcnJVyjPL8pJUVS35kJX5ptakpGfAlSooalgawc1BgSS8%2FOK83NS9XLy0zVKMjKL9WCGalqD1dRy1QIAgrT4spEAAAA%3D&config=H4sIAAAAAAAAA0VOSwqDMBC9SnlrF1Xoxjv0EEFHieTHTCyVkLt3IhZ3j%2Fcv2GTCWJAMC3FDcoRsvhiRj0QysU0ZHbIolXmnqtjwSlkdJMOzf6nqYhTCuBgn1MHbYJejdU3RJyaRWzJhdX9n1S4f570R5ZzTTo34GDZBvYuusJX35W5HOlD4nMHzjm4gxJke%2FYBaf%2FJ6D0jYAAAA

### Expected behavior
```javascript
const foo = {
    get prop1() {
        return 1
    },
    get prop2 () {
        return this.prop1 + 1;
    }
};
```

### Actual behavior
```javascript
const foo = {
    get prop1() {
        return 1
    },
    get prop2 () {
        return (void 0).prop1 + 1;
    }
};
```

### Version

1.2.210

### Additional context

* I notice this bug has been introduced in 1.2.206.  
* The SWC playground link includes links of other usages of `this` which work correctly. It seems to be specifically only: 
  (1) inside a property definition; AND
  (2) if the property is defined on an object literal, as opposed to a class.

Pull request:
fix(es/module): Handle top level this
<!-- Note: CI script will automatically rebase your PR so please do not rebase unless required -->

<!-- Thanks for submitting a pull request! Please provide enough information so that others can review your pull request. -->

**Description:**

<!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? -->

**BREAKING CHANGE:**

<!--
If this PR introduces a breaking change, it must contain a notice for it to be included in the CHANGELOG. Add description or remove entirely if not breaking.

You may need to update `MIGRATION.md` for the breaking changes.
-->

**Related issue (if exists):**
- fix #5157 

Patch:
diff --git a/crates/swc_ecma_transforms_module/src/module_ref_rewriter.rs b/crates/swc_ecma_transforms_module/src/module_ref_rewriter.rs
index 77d4349a47..97d7533a66 100644
--- a/crates/swc_ecma_transforms_module/src/module_ref_rewriter.rs
+++ b/crates/swc_ecma_transforms_module/src/module_ref_rewriter.rs
@@ -112,6 +112,18 @@ impl VisitMut for ModuleRefRewriter {
         self.visit_mut_with_non_global_this(&mut n.value);
     }
 
+    fn visit_mut_private_prop(&mut self, n: &mut PrivateProp) {
+        self.visit_mut_with_non_global_this(n);
+    }
+
+    fn visit_mut_getter_prop(&mut self, n: &mut GetterProp) {
+        self.visit_mut_with_non_global_this(n);
+    }
+
+    fn visit_mut_setter_prop(&mut self, n: &mut SetterProp) {
+        self.visit_mut_with_non_global_this(n);
+    }
+
     fn visit_mut_static_block(&mut self, n: &mut StaticBlock) {
         self.visit_mut_with_non_global_this(n);
     }


Test patch:
diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/live-rewrite/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/live-rewrite/input.js
new file mode 100644
index 0000000000..e704b59026
--- /dev/null
+++ b/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/live-rewrite/input.js
@@ -0,0 +1,36 @@
+import {
+    test1,
+    test2,
+    test3,
+    test4,
+    test5,
+    test6,
+    test7,
+    test8,
+    test9,
+} from "anywhere";
+
+class Example {
+    #test1 = test1;
+    test2 = test2;
+    #test3() {
+        return test3;
+    }
+    test4() {
+        return test4;
+    }
+    get #test5() {
+        return test5;
+    }
+    get test6() {
+        return test6;
+    }
+
+    #test7 = this.#test1;
+    #test8() {
+        return this.#test3();
+    }
+    get #test9() {
+        return this.#test5();
+    }
+}
diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/live-rewrite/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/live-rewrite/output.amd.js
new file mode 100644
index 0000000000..b85e051aa5
--- /dev/null
+++ b/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/live-rewrite/output.amd.js
@@ -0,0 +1,33 @@
+define([
+    "require",
+    "exports",
+    "anywhere"
+], function(require, exports, _anywhere) {
+    "use strict";
+    Object.defineProperty(exports, "__esModule", {
+        value: true
+    });
+    class Example {
+        #test1 = _anywhere.test1;
+        test2 = _anywhere.test2;
+         #test3() {
+            return _anywhere.test3;
+        }
+        test4() {
+            return _anywhere.test4;
+        }
+        get #test5() {
+            return _anywhere.test5;
+        }
+        get test6() {
+            return _anywhere.test6;
+        }
+        #test7 = this.#test1;
+         #test8() {
+            return this.#test3();
+        }
+        get #test9() {
+            return this.#test5();
+        }
+    }
+});
diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/live-rewrite/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/live-rewrite/output.cjs
new file mode 100644
index 0000000000..5f2ccc7369
--- /dev/null
+++ b/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/live-rewrite/output.cjs
@@ -0,0 +1,28 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", {
+    value: true
+});
+const _anywhere = require("anywhere");
+class Example {
+    #test1 = _anywhere.test1;
+    test2 = _anywhere.test2;
+     #test3() {
+        return _anywhere.test3;
+    }
+    test4() {
+        return _anywhere.test4;
+    }
+    get #test5() {
+        return _anywhere.test5;
+    }
+    get test6() {
+        return _anywhere.test6;
+    }
+    #test7 = this.#test1;
+     #test8() {
+        return this.#test3();
+    }
+    get #test9() {
+        return this.#test5();
+    }
+}
diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/live-rewrite/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/live-rewrite/output.umd.js
new file mode 100644
index 0000000000..cea265a89c
--- /dev/null
+++ b/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/live-rewrite/output.umd.js
@@ -0,0 +1,36 @@
+(function(global, factory) {
+    if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("anywhere"));
+    else if (typeof define === "function" && define.amd) define([
+        "exports",
+        "anywhere"
+    ], factory);
+    else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.anywhere);
+})(this, function(exports, _anywhere) {
+    "use strict";
+    Object.defineProperty(exports, "__esModule", {
+        value: true
+    });
+    class Example {
+        #test1 = _anywhere.test1;
+        test2 = _anywhere.test2;
+         #test3() {
+            return _anywhere.test3;
+        }
+        test4() {
+            return _anywhere.test4;
+        }
+        get #test5() {
+            return _anywhere.test5;
+        }
+        get test6() {
+            return _anywhere.test6;
+        }
+        #test7 = this.#test1;
+         #test8() {
+            return this.#test3();
+        }
+        get #test9() {
+            return this.#test5();
+        }
+    }
+});
diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/private-method/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/private-method/input.js
new file mode 100644
index 0000000000..49c9a56744
--- /dev/null
+++ b/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/private-method/input.js
@@ -0,0 +1,5 @@
+class Example {
+    #method() {
+        console.log(this);
+    }
+}
diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/private-method/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/private-method/output.amd.js
new file mode 100644
index 0000000000..98d36b7173
--- /dev/null
+++ b/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/private-method/output.amd.js
@@ -0,0 +1,10 @@
+define([
+    "require"
+], function(require) {
+    "use strict";
+    class Example {
+         #method() {
+            console.log(this);
+        }
+    }
+});
diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/private-method/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/private-method/output.cjs
new file mode 100644
index 0000000000..9f60895b92
--- /dev/null
+++ b/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/private-method/output.cjs
@@ -0,0 +1,6 @@
+"use strict";
+class Example {
+     #method() {
+        console.log(this);
+    }
+}
diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/private-method/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/private-method/output.umd.js
new file mode 100644
index 0000000000..bc4a488ee4
--- /dev/null
+++ b/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/private-method/output.umd.js
@@ -0,0 +1,12 @@
+(function(global, factory) {
+    if (typeof module === "object" && typeof module.exports === "object") factory();
+    else if (typeof define === "function" && define.amd) define([], factory);
+    else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory();
+})(this, function() {
+    "use strict";
+    class Example {
+         #method() {
+            console.log(this);
+        }
+    }
+});
diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/private/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/private/input.js
new file mode 100644
index 0000000000..0448a6042f
--- /dev/null
+++ b/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/private/input.js
@@ -0,0 +1,3 @@
+class Example {
+    #property = this;
+}
diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/private/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/private/output.amd.js
new file mode 100644
index 0000000000..fb4a058598
--- /dev/null
+++ b/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/private/output.amd.js
@@ -0,0 +1,8 @@
+define([
+    "require"
+], function(require) {
+    "use strict";
+    class Example {
+        #property = this;
+    }
+});
diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/private/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/private/output.cjs
new file mode 100644
index 0000000000..673c5ae3da
--- /dev/null
+++ b/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/private/output.cjs
@@ -0,0 +1,4 @@
+"use strict";
+class Example {
+    #property = this;
+}
diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/private/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/private/output.umd.js
new file mode 100644
index 0000000000..fb05d3bce0
--- /dev/null
+++ b/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/private/output.umd.js
@@ -0,0 +1,10 @@
+(function(global, factory) {
+    if (typeof module === "object" && typeof module.exports === "object") factory();
+    else if (typeof define === "function" && define.amd) define([], factory);
+    else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory();
+})(this, function() {
+    "use strict";
+    class Example {
+        #property = this;
+    }
+});
diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/public/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/public/input.js
new file mode 100644
index 0000000000..697b69c40a
--- /dev/null
+++ b/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/public/input.js
@@ -0,0 +1,3 @@
+class Example {
+    property = this;
+}
diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/public/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/public/output.amd.js
new file mode 100644
index 0000000000..7175dacaad
--- /dev/null
+++ b/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/public/output.amd.js
@@ -0,0 +1,8 @@
+define([
+    "require"
+], function(require) {
+    "use strict";
+    class Example {
+        property = this;
+    }
+});
diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/public/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/public/output.cjs
new file mode 100644
index 0000000000..9445df498c
--- /dev/null
+++ b/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/public/output.cjs
@@ -0,0 +1,4 @@
+"use strict";
+class Example {
+    property = this;
+}
diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/public/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/public/output.umd.js
new file mode 100644
index 0000000000..56464a655d
--- /dev/null
+++ b/crates/swc_ecma_transforms_module/tests/fixture/common/class-properties/public/output.umd.js
@@ -0,0 +1,10 @@
+(function(global, factory) {
+    if (typeof module === "object" && typeof module.exports === "object") factory();
+    else if (typeof define === "function" && define.amd) define([], factory);
+    else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory();
+})(this, function() {
+    "use strict";
+    class Example {
+        property = this;
+    }
+});
diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5157/1/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5157/1/input.js
new file mode 100644
index 0000000000..f17728496f
--- /dev/null
+++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5157/1/input.js
@@ -0,0 +1,14 @@
+export const foo = {
+    get prop1() {
+        return 1;
+    },
+    get prop2() {
+        return this.prop1 + 1;
+    },
+    set prop3(v) {
+        this.x = v;
+    },
+    method() {
+        return this.prop1;
+    },
+};
diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5157/1/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5157/1/output.amd.js
new file mode 100644
index 0000000000..16aea4c730
--- /dev/null
+++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5157/1/output.amd.js
@@ -0,0 +1,27 @@
+define([
+    "require",
+    "exports"
+], function(require, exports) {
+    "use strict";
+    Object.defineProperty(exports, "__esModule", {
+        value: true
+    });
+    Object.defineProperty(exports, "foo", {
+        enumerable: true,
+        get: ()=>foo
+    });
+    const foo = {
+        get prop1 () {
+            return 1;
+        },
+        get prop2 () {
+            return this.prop1 + 1;
+        },
+        set prop3 (v){
+            this.x = v;
+        },
+        method () {
+            return this.prop1;
+        }
+    };
+});
diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5157/1/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5157/1/output.cjs
new file mode 100644
index 0000000000..fcea17708f
--- /dev/null
+++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5157/1/output.cjs
@@ -0,0 +1,22 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", {
+    value: true
+});
+Object.defineProperty(exports, "foo", {
+    enumerable: true,
+    get: ()=>foo
+});
+const foo = {
+    get prop1 () {
+        return 1;
+    },
+    get prop2 () {
+        return this.prop1 + 1;
+    },
+    set prop3 (v){
+        this.x = v;
+    },
+    method () {
+        return this.prop1;
+    }
+};
diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5157/1/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5157/1/output.umd.js
new file mode 100644
index 0000000000..2eea6d0409
--- /dev/null
+++ b/crates/swc_ecma_transforms_module/tests/fixture/common/issue-5157/1/output.umd.js
@@ -0,0 +1,30 @@
+(function(global, factory) {
+    if (typeof module === "object" && typeof module.exports === "object") factory(exports);
+    else if (typeof define === "function" && define.amd) define([
+        "exports"
+    ], factory);
+    else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {});
+})(this, function(exports) {
+    "use strict";
+    Object.defineProperty(exports, "__esModule", {
+        value: true
+    });
+    Object.defineProperty(exports, "foo", {
+        enumerable: true,
+        get: ()=>foo
+    });
+    const foo = {
+        get prop1 () {
+            return 1;
+        },
+        get prop2 () {
+            return this.prop1 + 1;
+        },
+        set prop3 (v){
+            this.x = v;
+        },
+        method () {
+            return this.prop1;
+        }
+    };
+});
diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/misc/class-static-block/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/class-static-block/input.js
new file mode 100644
index 0000000000..f3b2ed8deb
--- /dev/null
+++ b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/class-static-block/input.js
@@ -0,0 +1,5 @@
+class foo {
+    static {
+        this; // should not be replaced by undefined
+    }
+}
diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/misc/class-static-block/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/class-static-block/output.amd.js
new file mode 100644
index 0000000000..fb3b865cf6
--- /dev/null
+++ b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/class-static-block/output.amd.js
@@ -0,0 +1,10 @@
+define([
+    "require"
+], function(require) {
+    "use strict";
+    class foo {
+        static{
+            this; // should not be replaced by undefined
+        }
+    }
+});
diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/misc/class-static-block/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/class-static-block/output.cjs
new file mode 100644
index 0000000000..5b9e0abe0f
--- /dev/null
+++ b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/class-static-block/output.cjs
@@ -0,0 +1,6 @@
+"use strict";
+class foo {
+    static{
+        this; // should not be replaced by undefined
+    }
+}
diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/misc/class-static-block/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/class-static-block/output.umd.js
new file mode 100644
index 0000000000..e200ed4432
--- /dev/null
+++ b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/class-static-block/output.umd.js
@@ -0,0 +1,12 @@
+(function(global, factory) {
+    if (typeof module === "object" && typeof module.exports === "object") factory();
+    else if (typeof define === "function" && define.amd) define([], factory);
+    else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory();
+})(this, function() {
+    "use strict";
+    class foo {
+        static{
+            this; // should not be replaced by undefined
+        }
+    }
+});
diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-method-1/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-method-1/input.js
new file mode 100644
index 0000000000..803624cdb4
--- /dev/null
+++ b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-method-1/input.js
@@ -0,0 +1,1 @@
+export class C { [this.name]() {} }
diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-method-1/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-method-1/output.amd.js
new file mode 100644
index 0000000000..0ce792bfb4
--- /dev/null
+++ b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-method-1/output.amd.js
@@ -0,0 +1,16 @@
+define([
+    "require",
+    "exports"
+], function(require, exports) {
+    "use strict";
+    Object.defineProperty(exports, "__esModule", {
+        value: true
+    });
+    Object.defineProperty(exports, "C", {
+        enumerable: true,
+        get: ()=>C
+    });
+    class C {
+        [(void 0).name]() {}
+    }
+});
diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-method-1/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-method-1/output.cjs
new file mode 100644
index 0000000000..8dd09260cc
--- /dev/null
+++ b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-method-1/output.cjs
@@ -0,0 +1,11 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", {
+    value: true
+});
+Object.defineProperty(exports, "C", {
+    enumerable: true,
+    get: ()=>C
+});
+class C {
+    [(void 0).name]() {}
+}
diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-method-1/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-method-1/output.umd.js
new file mode 100644
index 0000000000..2a278f44fc
--- /dev/null
+++ b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-method-1/output.umd.js
@@ -0,0 +1,19 @@
+(function(global, factory) {
+    if (typeof module === "object" && typeof module.exports === "object") factory(exports);
+    else if (typeof define === "function" && define.amd) define([
+        "exports"
+    ], factory);
+    else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {});
+})(this, function(exports) {
+    "use strict";
+    Object.defineProperty(exports, "__esModule", {
+        value: true
+    });
+    Object.defineProperty(exports, "C", {
+        enumerable: true,
+        get: ()=>C
+    });
+    class C {
+        [(void 0).name]() {}
+    }
+});
diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-method-2/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-method-2/input.js
new file mode 100644
index 0000000000..55156089e6
--- /dev/null
+++ b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-method-2/input.js
@@ -0,0 +1,3 @@
+class A {
+  [() => this.name]() {}
+}
\ No newline at end of file
diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-method-2/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-method-2/output.amd.js
new file mode 100644
index 0000000000..e5346f2cb3
--- /dev/null
+++ b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-method-2/output.amd.js
@@ -0,0 +1,8 @@
+define([
+    "require"
+], function(require) {
+    "use strict";
+    class A {
+        [()=>(void 0).name]() {}
+    }
+});
diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-method-2/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-method-2/output.cjs
new file mode 100644
index 0000000000..4d6c50bb00
--- /dev/null
+++ b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-method-2/output.cjs
@@ -0,0 +1,4 @@
+"use strict";
+class A {
+    [()=>(void 0).name]() {}
+}
diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-method-2/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-method-2/output.umd.js
new file mode 100644
index 0000000000..d65bc716c6
--- /dev/null
+++ b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-method-2/output.umd.js
@@ -0,0 +1,10 @@
+(function(global, factory) {
+    if (typeof module === "object" && typeof module.exports === "object") factory();
+    else if (typeof define === "function" && define.amd) define([], factory);
+    else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory();
+})(this, function() {
+    "use strict";
+    class A {
+        [()=>(void 0).name]() {}
+    }
+});
diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-method-3/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-method-3/input.js
new file mode 100644
index 0000000000..878eeffad7
--- /dev/null
+++ b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-method-3/input.js
@@ -0,0 +1,3 @@
+class A {
+  [function () { this.name; }]() {}
+}
\ No newline at end of file
diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-method-3/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-method-3/output.amd.js
new file mode 100644
index 0000000000..5ae66b4680
--- /dev/null
+++ b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-method-3/output.amd.js
@@ -0,0 +1,10 @@
+define([
+    "require"
+], function(require) {
+    "use strict";
+    class A {
+        [function() {
+            this.name;
+        }]() {}
+    }
+});
diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-method-3/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-method-3/output.cjs
new file mode 100644
index 0000000000..9debdbf714
--- /dev/null
+++ b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-method-3/output.cjs
@@ -0,0 +1,6 @@
+"use strict";
+class A {
+    [function() {
+        this.name;
+    }]() {}
+}
diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-method-3/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-method-3/output.umd.js
new file mode 100644
index 0000000000..fb32d05f76
--- /dev/null
+++ b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-method-3/output.umd.js
@@ -0,0 +1,12 @@
+(function(global, factory) {
+    if (typeof module === "object" && typeof module.exports === "object") factory();
+    else if (typeof define === "function" && define.amd) define([], factory);
+    else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory();
+})(this, function() {
+    "use strict";
+    class A {
+        [function() {
+            this.name;
+        }]() {}
+    }
+});
diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-property-name/input.js b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-property-name/input.js
new file mode 100644
index 0000000000..f65287402e
--- /dev/null
+++ b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-property-name/input.js
@@ -0,0 +1,1 @@
+export class C { [this.name] = 42 }
\ No newline at end of file
diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-property-name/output.amd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-property-name/output.amd.js
new file mode 100644
index 0000000000..52ab675166
--- /dev/null
+++ b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-property-name/output.amd.js
@@ -0,0 +1,16 @@
+define([
+    "require",
+    "exports"
+], function(require, exports) {
+    "use strict";
+    Object.defineProperty(exports, "__esModule", {
+        value: true
+    });
+    Object.defineProperty(exports, "C", {
+        enumerable: true,
+        get: ()=>C
+    });
+    class C {
+        [(void 0).name] = 42;
+    }
+});
diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-property-name/output.cjs b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-property-name/output.cjs
new file mode 100644
index 0000000000..d67c1953df
--- /dev/null
+++ b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-property-name/output.cjs
@@ -0,0 +1,11 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", {
+    value: true
+});
+Object.defineProperty(exports, "C", {
+    enumerable: true,
+    get: ()=>C
+});
+class C {
+    [(void 0).name] = 42;
+}
diff --git a/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-property-name/output.umd.js b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-property-name/output.umd.js
new file mode 100644
index 0000000000..e1efde0807
--- /dev/null
+++ b/crates/swc_ecma_transforms_module/tests/fixture/common/misc/undefined-this-computed-class-property-name/output.umd.js
@@ -0,0 +1,19 @@
+(function(global, factory) {
+    if (typeof module === "object" && typeof module.exports === "object") factory(exports);
+    else if (typeof define === "function" && define.amd) define([
+        "exports"
+    ], factory);
+    else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {});
+})(this, function(exports) {
+    "use strict";
+    Object.defineProperty(exports, "__esModule", {
+        value: true
+    });
+    Object.defineProperty(exports, "C", {
+        enumerable: true,
+        get: ()=>C
+    });
+    class C {
+        [(void 0).name] = 42;
+    }
+});