/
preset-stage-1.test.js
81 lines (77 loc) 路 2.3 KB
/
preset-stage-1.test.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { createRequire } from "module";
const require = createRequire(import.meta.url);
describe("stage-1 preset", () => {
let Babel;
beforeAll(() => {
Babel = require("../babel.js");
});
it("should parser decimal literal", () => {
const output = Babel.transform("0.3m", {
presets: [["stage-1", { decoratorsLegacy: true }]],
}).code;
expect(output).toBe("0.3m;");
});
it("should support hack pipeline", () => {
const output = Babel.transform("x |> %", {
presets: [
[
"stage-1",
{
pipelineProposal: "hack",
decoratorsLegacy: true,
},
],
],
}).code;
expect(output).toMatchInlineSnapshot(`"x;"`);
});
it("should support hack pipeline with `#` topic token", () => {
const output = Babel.transform("x |> #", {
presets: [
[
"stage-1",
{
pipelineProposal: "hack",
pipelineTopicToken: "#",
recordAndTupleSyntax: "bar",
decoratorsLegacy: true,
},
],
],
}).code;
expect(output).toMatchInlineSnapshot(`"x;"`);
});
it("should support decorators versioned 2021-12", () => {
const output = Babel.transform("@dec class C {}", {
plugins: [["external-helpers", { helperVersion: "7.100.0" }]],
presets: [["stage-1", { decoratorsVersion: "2021-12" }]],
}).code;
expect(output).toMatch("babelHelpers.applyDecs");
});
it("should support private destructuring", () => {
const output = Babel.transform("class C { #x; m({ #x: x}) {} }", {
plugins: [["external-helpers", { helperVersion: "7.100.0" }]],
presets: [
[
"stage-1",
{
decoratorsVersion: "2021-12",
},
],
],
}).code;
expect(output).not.toContain("#x:");
});
it("should support regexp v flag", () => {
const output = Babel.transform("/[[a-p]&&[d-z]]/v", {
presets: [["stage-1", { decoratorsVersion: "2021-12" }]],
}).code;
expect(output).toMatchInlineSnapshot(`"/[d-p]/u;"`);
});
it("should support record and tuple", () => {
const output = Babel.transform("#[#{}]", {
presets: [["stage-1", { decoratorsVersion: "2021-12" }]],
}).code;
expect(output).toMatchInlineSnapshot(`"Tuple(Record({}));"`);
});
});