| 1 |
const targets = []; |
| 2 |
function Foo() { |
| 3 |
targets.push(new.target); |
| 4 |
} |
| 5 |
|
| 6 |
function Bar() { |
| 7 |
Foo.call(this); |
| 8 |
} |
| 9 |
Bar.prototype = Object.create(Foo.prototype, { |
| 10 |
constructor: { |
| 11 |
value: Bar, |
| 12 |
writable: true, |
| 13 |
configurable: true, |
| 14 |
} |
| 15 |
}); |
| 16 |
|
| 17 |
function Baz() {} |
| 18 |
|
| 19 |
Reflect.construct(Foo, []); |
| 20 |
Reflect.construct(Foo, [], Bar); |
| 21 |
Reflect.construct(Bar, []); |
| 22 |
Reflect.construct(Bar, [], Baz); |
| 23 |
Reflect.construct(Foo, [], Baz); |
| 24 |
|
| 25 |
expect(targets[0]).toBe(Foo); |
| 26 |
|
| 27 |
expect(targets[1]).toBe(Bar); |
| 28 |
|
| 29 |
expect(() => { |
| 30 |
// Wish we could support this... |
| 31 |
// Then again, this is what a transformed class does. |
| 32 |
expect(targets[2]).toBeUndefined(); |
| 33 |
}).toThrow(); |
| 34 |
|
| 35 |
expect(targets[3]).toBeUndefined(); |
| 36 |
|
| 37 |
expect(() => { |
| 38 |
// Wish we could support this... |
| 39 |
expect(targets[4]).toBe(Baz); |
| 40 |
}).toThrow(); |