async-generators.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. describe("parsing freestanding generators", () => {
  2. test("simple", () => {
  3. expect(`async function* foo() {}`).toEval();
  4. expect(`async function *foo() {}`).toEval();
  5. expect(`async function
  6. *foo() {}`).toEval();
  7. });
  8. test("yield & await expression", () => {
  9. expect(`async function* foo() { yield; await 1; }`).toEval();
  10. expect(`async function* foo() { yield (yield); await (yield); }`).toEval();
  11. expect(`async function* foo() { yield (yield foo); yield (await foo); }`).toEval();
  12. expect(`async function foo() { yield; }`).toEval();
  13. expect(`async function foo() { yield 3; }`).not.toEval();
  14. expect(`function* foo() { await 3; }`).not.toEval();
  15. });
  16. test("yield-from expression", () => {
  17. expect(`async function* foo() { yield *bar; }`).toEval();
  18. expect(`async function* foo() { yield *(yield); }`).toEval();
  19. expect(`async function* foo() { yield
  20. *bar; }`).not.toEval();
  21. expect(`async function foo() { yield
  22. *bar; }`).toEval();
  23. });
  24. });
  25. describe("parsing object literal generator functions", () => {
  26. test("simple", () => {
  27. expect(`x = { async *foo() { } }`).toEval();
  28. expect(`x = { async * foo() { } }`).toEval();
  29. expect(`x = { async *
  30. foo() { } }`).toEval();
  31. });
  32. test("yield & await", () => {
  33. expect(`x = { async foo() { yield; await 3;} }`).toEval();
  34. expect(`x = { async *foo() { yield; await 3; } }`).toEval();
  35. expect(`x = { async *foo() { yield 42; await 3; } }`).toEval();
  36. expect(`x = { async *foo() { yield (yield); await (yield); } }`).toEval();
  37. expect(`x = { async *
  38. foo() { yield (yield); await 4; } }`).toEval();
  39. expect(`x = { async foo() { yield 42; } }`).not.toEval();
  40. expect(`x = { *foo() { await 42; } }`).not.toEval();
  41. });
  42. });
  43. describe("parsing classes with generator methods", () => {
  44. test("simple", () => {
  45. expect(`class Foo { async *foo() {} }`).toEval();
  46. expect(`class Foo { static async *foo() {} }`).toEval();
  47. expect(`class Foo { async *foo() { yield; } }`).toEval();
  48. expect(`class Foo { async *foo() { yield 42; } }`).toEval();
  49. expect(`class Foo { async *constructor() { yield 42; } }`).not.toEval();
  50. });
  51. });