function-new-target.js 561 B

12345678910111213141516171819202122232425
  1. test("basic functionality", () => {
  2. function foo() {
  3. return new.target;
  4. }
  5. expect(foo()).toBeUndefined();
  6. expect(new foo()).toEqual(foo);
  7. function bar() {
  8. const baz = () => new.target;
  9. return baz();
  10. }
  11. expect(bar()).toBeUndefined();
  12. expect(new bar()).toEqual(bar);
  13. class baz {
  14. constructor() {
  15. this.newTarget = new.target;
  16. }
  17. }
  18. expect(new baz().newTarget).toEqual(baz);
  19. });
  20. test("syntax error outside of function", () => {
  21. expect("new.target").not.toEval();
  22. });