| 1 | import { parse } from "@babel/parser"; |
| 2 | |
| 3 | import _traverse from "../../lib/index.js"; |
| 4 | const traverse = _traverse.default || _traverse; |
| 5 | |
| 6 | function getPath(code) { |
| 7 | const ast = parse(code, { sourceType: "module" }); |
| 8 | let path; |
| 9 | traverse(ast, { |
| 10 | Program: function (_path) { |
| 11 | path = _path; |
| 12 | _path.stop(); |
| 13 | }, |
| 14 | }); |
| 15 | return path; |
| 16 | } |
| 17 | |
| 18 | describe("path.isForAwaitStatement", () => { |
| 19 | it.each(["for await (const x of []);"])( |
| 20 | `NodePath(%p).get("body.0").isForAwaitStatement() should be true`, |
| 21 | input => { |
| 22 | const path = getPath(input).get("body.0"); |
| 23 | expect(path.node).toBeTruthy(); |
| 24 | expect(path.isForAwaitStatement()).toBe(true); |
| 25 | }, |
| 26 | ); |
| 27 | }); |