/
compat.mjs
133 lines (123 loc) · 3.32 KB
/
compat.mjs
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import { deepEqual, ok } from 'assert/strict';
import compat from 'core-js-compat/compat.js';
deepEqual(compat({
modules: [
'core-js/es/math',
'es.array.at',
/^es\.reflect/,
],
exclude: [
'es.reflect.prevent-extensions',
],
targets: 'firefox 27',
}), {
list: [
'es.array.at',
'es.math.clz32',
'es.math.expm1',
'es.math.to-string-tag',
'es.reflect.apply',
'es.reflect.construct',
'es.reflect.define-property',
'es.reflect.delete-property',
'es.reflect.get',
'es.reflect.get-own-property-descriptor',
'es.reflect.get-prototype-of',
'es.reflect.has',
'es.reflect.is-extensible',
'es.reflect.own-keys',
'es.reflect.set',
'es.reflect.set-prototype-of',
'es.reflect.to-string-tag',
],
targets: {
'es.array.at': { firefox: '27' },
'es.math.clz32': { firefox: '27' },
'es.math.expm1': { firefox: '27' },
'es.math.to-string-tag': { firefox: '27' },
'es.reflect.apply': { firefox: '27' },
'es.reflect.construct': { firefox: '27' },
'es.reflect.define-property': { firefox: '27' },
'es.reflect.delete-property': { firefox: '27' },
'es.reflect.get': { firefox: '27' },
'es.reflect.get-own-property-descriptor': { firefox: '27' },
'es.reflect.get-prototype-of': { firefox: '27' },
'es.reflect.has': { firefox: '27' },
'es.reflect.is-extensible': { firefox: '27' },
'es.reflect.own-keys': { firefox: '27' },
'es.reflect.set': { firefox: '27' },
'es.reflect.set-prototype-of': { firefox: '27' },
'es.reflect.to-string-tag': { firefox: '27' },
},
}, 'basic');
deepEqual(compat({
modules: [
/^es\.math\.a/,
/^es\.math\.c/,
],
exclude: 'es.math.asinh',
}), {
list: [
'es.math.acosh',
'es.math.atanh',
'es.math.cbrt',
'es.math.clz32',
'es.math.cosh',
],
targets: {
'es.math.acosh': {},
'es.math.atanh': {},
'es.math.cbrt': {},
'es.math.clz32': {},
'es.math.cosh': {},
},
}, 'no target');
deepEqual(compat({
modules: /^es\.math\.a/,
}), {
list: [
'es.math.acosh',
'es.math.asinh',
'es.math.atanh',
],
targets: {
'es.math.acosh': {},
'es.math.asinh': {},
'es.math.atanh': {},
},
}, 'no exclude');
deepEqual(
compat({ targets: { chrome: 93 } }),
compat({ modules: 'core-js', targets: { chrome: 93 } }),
'no modules',
);
deepEqual(compat({
modules: 'core-js/es/math',
targets: {
chrome: 40,
firefox: 27,
},
}), {
list: [
'es.math.acosh',
'es.math.clz32',
'es.math.expm1',
'es.math.hypot',
'es.math.to-string-tag',
],
targets: {
'es.math.acosh': { chrome: '40' },
'es.math.clz32': { firefox: '27' },
'es.math.expm1': { firefox: '27' },
'es.math.hypot': { chrome: '40' },
'es.math.to-string-tag': { chrome: '40', firefox: '27' },
},
}, 'some targets');
const { list: inverted1 } = compat({ targets: { esmodules: true }, inverse: true });
ok(inverted1.includes('es.symbol.iterator'), 'inverse #1');
ok(!inverted1.includes('esnext.iterator.from'), 'inverse #2');
ok(!inverted1.includes('esnext.array.at'), 'inverse #3');
const { list: inverted2 } = compat({ modules: 'core-js/es/math', targets: { esmodules: true }, inverse: true });
ok(inverted2.includes('es.math.acosh'), 'inverse #4');
ok(!inverted2.includes('es.map'), 'inverse #5');
echo(chalk.green('compat tool tested'));