async-generators.js 2.4 KB

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