/
type-constructors-test.js
50 lines (47 loc) · 1.15 KB
/
type-constructors-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
jest.autoMockOff();
const babel = require("@babel/core");
const plugin = require("../src/index");
const unpad = require("unpad");
const thePlugin = require("test-transform")(plugin);
describe("type-constructors-plugin", () => {
// options tests
it("should respect the options disabling optomizations", () => {
const types = {
boolean: "Boolean",
number: "Number",
array: "Array",
object: "Object",
string: "String"
};
const names = Object.keys(types);
for (let i = 0; i < names.length; i++) {
const source = unpad(
`
(function () {
var foo = ${types[names[i]]}(1);
var bar = ${types[names[i]]}(x);
var baz = ${types[names[i]]}();
})();
`
);
expect(
babel.transformSync(source, {
plugins: [[plugin, { [names[i]]: false }]],
sourceType: "script"
}).code
).toBe(source);
}
});
// https://github.com/babel/minify/issues/206
thePlugin(
"should handle floating point numbers in `Array()`",
`
new Array(-0.01);
new Array(-1);
`,
`
Array(-0.01);
Array(-1);
`
);
});