fix(es/transforms/compat): Fix new_target (#2736)

This commit is contained in:
Bojan Đurđević 2021-11-13 15:34:28 -05:00 committed by GitHub
parent 79fc464f8d
commit 571c5e3123
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 66 additions and 0 deletions

View File

@ -85,6 +85,8 @@ impl VisitMut for NewTarget {
let old = self.in_constructor;
self.in_constructor = true;
self.in_arrow_expr = false;
self.var = None;
c.visit_mut_children_with(self);

View File

@ -0,0 +1,22 @@
const targets = [];
{
function foo() {
targets.push(new.target);
}
foo();
}
expect(targets[0]).toBeUndefined();
{
class Foo {
constructor() {
targets.push(new.target);
}
}
new Foo();
}
expect(targets[1]).not.toBeUndefined();

View File

@ -0,0 +1,11 @@
{
class Foo {
constructor() {
new.target;
}
test() {
new.target;
}
}
}

View File

@ -0,0 +1,10 @@
{
class Foo {
constructor() {
this.constructor;
}
test() {
void 0;
}
}
}

View File

@ -0,0 +1,11 @@
(() => {
class Foo {
constructor() {
new.target;
}
test() {
new.target;
}
}
})()

View File

@ -0,0 +1,10 @@
(() => {
class Foo {
constructor() {
this.constructor;
}
test() {
void 0;
}
}
})()