Fix: assign _this to this when there is no Superclass - Fixes T7364
Closes gh-3508
This commit is contained in:
parent
8532bb8334
commit
f408f28a02
@ -92,7 +92,10 @@ function remap(path, key) {
|
||||
|
||||
fnPath.setData(key, id);
|
||||
|
||||
if (key === "this" && fnPath.isMethod({kind: "constructor"})) {
|
||||
let classPath = fnPath.findParent((p) => p.isClass());
|
||||
let hasSuperClass = !!(classPath && classPath.node && classPath.node.superClass);
|
||||
|
||||
if (key === "this" && fnPath.isMethod({kind: "constructor"}) && hasSuperClass) {
|
||||
fnPath.scope.push({ id });
|
||||
|
||||
fnPath.traverse(superVisitor, { id });
|
||||
|
||||
17
packages/babel-plugin-transform-class-properties/test/fixtures/regression/T7364/actual.js
vendored
Normal file
17
packages/babel-plugin-transform-class-properties/test/fixtures/regression/T7364/actual.js
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
class MyClass {
|
||||
myAsyncMethod = async () => {
|
||||
console.log(this);
|
||||
}
|
||||
}
|
||||
|
||||
(class MyClass2 {
|
||||
myAsyncMethod = async () => {
|
||||
console.log(this);
|
||||
}
|
||||
})
|
||||
|
||||
export default class MyClass3 {
|
||||
myAsyncMethod = async () => {
|
||||
console.log(this);
|
||||
}
|
||||
}
|
||||
32
packages/babel-plugin-transform-class-properties/test/fixtures/regression/T7364/expected.js
vendored
Normal file
32
packages/babel-plugin-transform-class-properties/test/fixtures/regression/T7364/expected.js
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
class MyClass {
|
||||
constructor() {
|
||||
var _this = this;
|
||||
|
||||
this.myAsyncMethod = babelHelpers.asyncToGenerator(function* () {
|
||||
console.log(_this);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
(class MyClass2 {
|
||||
constructor() {
|
||||
var _this2 = this;
|
||||
|
||||
this.myAsyncMethod = babelHelpers.asyncToGenerator(function* () {
|
||||
console.log(_this2);
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
export default class MyClass3 {
|
||||
constructor() {
|
||||
var _this3 = this;
|
||||
|
||||
this.myAsyncMethod = babelHelpers.asyncToGenerator(function* () {
|
||||
console.log(_this3);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
7
packages/babel-plugin-transform-class-properties/test/fixtures/regression/T7364/options.json
vendored
Normal file
7
packages/babel-plugin-transform-class-properties/test/fixtures/regression/T7364/options.json
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"plugins": [
|
||||
"external-helpers",
|
||||
"transform-async-to-generator",
|
||||
"transform-class-properties"
|
||||
]
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user