-
Notifications
You must be signed in to change notification settings - Fork 754
Expand file tree
/
Copy pathremove_polyfills_test.ts
More file actions
87 lines (77 loc) · 1.69 KB
/
Copy pathremove_polyfills_test.ts
File metadata and controls
87 lines (77 loc) · 1.69 KB
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
import { expect } from "@std/expect/expect";
import * as babel from "@babel/core";
import { removePolyfills } from "./remove_polyfills.ts";
function runTest(options: { input: string; expected: string }) {
const res = babel.transformSync(options.input, {
filename: "foo.js",
babelrc: false,
plugins: [removePolyfills],
});
const output = res?.code ?? "";
expect(output).toEqual(options.expected);
}
Deno.test("remove polyfills - Object.keys", () => {
runTest({
input: `if (!Object.keys) {
Object.keys = function (o) {
var a = []
for (var i in o) if (o.hasOwnProperty(i)) a.push(i)
return a
}
}
Object.keys({ foo: "bar" });`,
expected: `Object.keys({
foo: "bar"
});`,
});
});
Deno.test("remove polyfills - Object.create", () => {
runTest({
input: `if (!Object.create) {
Object.create = function (o) {
function F () {}
F.prototype = o
var newf = new F()
return newf
}
}
Object.create({});`,
expected: `Object.create({});`,
});
});
Deno.test("remove polyfills - keep alternate", () => {
runTest({
input: `if (!Object.create) {
Object.create = function (o) {
function F () {}
F.prototype = o
var newf = new F()
return newf
}
} else {
console.log("foo")
}`,
expected: `{
console.log("foo");
}`,
});
});
Deno.test("remove polyfills - String.fromCodePoint", () => {
runTest({
input: `if (!String.fromCodePoint) {
foo
}
String.fromCodePoint(42);`,
expected: `String.fromCodePoint(42);`,
});
});
Deno.test("remove polyfills - Keep unrelated unary statements", () => {
runTest({
input: `if (+String.fromCodePoint) {
foo;
}`,
expected: `if (+String.fromCodePoint) {
foo;
}`,
});
});