forked from babel/babel
-
Notifications
You must be signed in to change notification settings - Fork 3
/
regressions.js
89 lines (79 loc) 路 2.8 KB
/
regressions.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
82
83
84
85
86
87
88
89
import * as babel7_12 from "@babel/core-7.12";
import * as babel from "@babel/core";
import env from "../lib/index.js";
import path from "path";
import { fileURLToPath } from "url";
import { USE_ESM, commonJS } from "$repo-utils";
const { require } = commonJS(import.meta.url);
const itBabel7 = process.env.BABEL_8_BREAKING ? it.skip : it;
const itBabel7Node14plusCjs =
process.env.BABEL_8_BREAKING ||
parseInt(process.versions.node) < 14 ||
USE_ESM
? it.skip
: it;
describe("regressions", () => {
it("empty", () => {
// TODO(Babel 8): Delete this file
});
itBabel7(
"#12880 - read the .browserslistrc file when using @babel/core < 7.13.0",
() => {
const root = path.join(
path.dirname(fileURLToPath(import.meta.url)),
"regressions",
);
// Unfortunately, when loading the browserslist config through
// @babel/preset-env, it's resolved from process.cwd() and not
// from root. Mock it to isolate this test.
const spy = jest.spyOn(process, "cwd").mockReturnValue(root);
try {
// The browserslistrc file contains "firefox 50".
// a ** b is supported starting from firefox 52;
// a => b is supported starting from firefox 45.
const out = babel7_12.transformSync("a ** b; a => b;", {
configFile: false,
presets: [[env, { modules: false }]],
filename: path.join(root, "input.js"),
root,
});
expect(out.code).toMatchInlineSnapshot(`
"Math.pow(a, b);
a => b;"
`);
} finally {
spy.mockRestore();
}
},
);
// create-reat-app missing dependency fallback
// jest fake timers only work in the Jest version we are using for Node.js 14+
itBabel7Node14plusCjs(
"proposal-private-property-in-object should warn and fallback to transform-...",
() => {
jest.useFakeTimers();
const consoleWarn = jest
.spyOn(console, "warn")
.mockImplementation(() => {});
try {
const out = babel.transformSync("class A { #a; x = #a in this }", {
configFile: false,
presets: [require("./regressions/babel-preset-react-app/index.js")],
});
jest.advanceTimersByTime(5000);
expect(consoleWarn).toHaveBeenCalled();
expect(out.code).toMatchInlineSnapshot(`
"function _checkInRHS(e) { if (Object(e) !== e) throw TypeError(\\"right-hand side of 'in' should be an object, got \\" + (null !== e ? typeof e : \\"null\\")); return e; }
var _aBrandCheck = /*#__PURE__*/new WeakSet();
class A {
#a = void _aBrandCheck.add(this);
x = _aBrandCheck.has(_checkInRHS(this));
}"
`);
} finally {
jest.useRealTimers();
consoleWarn.mockRestore();
}
},
);
});