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