/
util.skip-bundled.js
56 lines (52 loc) 路 1.42 KB
/
util.skip-bundled.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
import { parseSync, traverse } from "@babel/core";
import { shouldTransform } from "../lib/util.js";
function getPath(input, parserOpts = {}) {
let targetPath;
traverse(
parseSync(input, {
parserOpts,
filename: "example.js",
configFile: false,
}),
{
FunctionExpression(path) {
targetPath = path;
path.stop();
},
},
);
return targetPath;
}
describe("shouldTransform", () => {
const positiveCases = [
"(function a([a]) {})",
"({ b: function a([a]) {} })",
"(function a({a}) {})",
"(function a(...a) {})",
"(function a({ ...a }) {})",
"(function a([a = 1]) {})",
"(function a(b, { a: [,...a] }) {})",
];
const negativeCases = [
"(function () {})",
"(function a() {})",
"(function a(a) {})",
"(function a() { var a })",
"(function b([a]) { var a })",
"(function b([a]) { function a() {} })",
"(function a(x = a) {})",
"(function a() { var { a } = {}; })",
"(function b([a]) { var { a } = {}; })",
"(function a({ [a]: b }) {})",
];
describe("the following cases should be transformed", () => {
test.each(positiveCases)("%p", input => {
expect(shouldTransform(getPath(input))).toBe("a");
});
});
describe("the following cases should not be transformed", () => {
test.each(negativeCases)("%p", input => {
expect(shouldTransform(getPath(input))).toBe(false);
});
});
});