| 1 | import env from "../lib/index.js"; |
| 2 | import * as babel from "@babel/core"; |
| 3 | |
| 4 | describe("supportsTopLevelAwait enables the parser plugin for old parser versions", () => { |
| 5 | function extractParserOptions(api, { ref }) { |
| 6 | return { |
| 7 | manipulateOptions(opts, parserOpts) { |
| 8 | ref.parserOpts = parserOpts; |
| 9 | }, |
| 10 | visitor: {}, |
| 11 | }; |
| 12 | } |
| 13 | |
| 14 | it("supported", () => { |
| 15 | const ref = {}; |
| 16 | babel.transformSync("", { |
| 17 | configFile: false, |
| 18 | presets: [env], |
| 19 | plugins: [[extractParserOptions, { ref }]], |
| 20 | caller: { |
| 21 | name: "test", |
| 22 | supportsTopLevelAwait: true, |
| 23 | }, |
| 24 | }); |
| 25 | |
| 26 | expect(ref.parserOpts.plugins).toContain("topLevelAwait"); |
| 27 | }); |
| 28 | |
| 29 | it("unsupported", () => { |
| 30 | const ref = {}; |
| 31 | babel.transformSync("", { |
| 32 | configFile: false, |
| 33 | presets: [env], |
| 34 | plugins: [[extractParserOptions, { ref }]], |
| 35 | caller: { |
| 36 | name: "test", |
| 37 | }, |
| 38 | }); |
| 39 | |
| 40 | expect(ref.parserOpts.plugins).not.toContain("topLevelAwait"); |
| 41 | }); |
| 42 | }); |