Debian Codegraph @

packages/babel-plugin-polyfill-corejs3/test/check-builtin-definitions.test.js

raw symbols SCIP
1 import corejs3Entries from "../core-js-compat/entries";
2
3 import {
4 BuiltIns,
5 StaticProperties,
6 InstanceProperties,
7 } from "../src/built-in-definitions";
8
9 const supportedCorejs3Modules = new Set();
10
11 const corejs3Modules = new Set(corejs3Entries["core-js"]);
12
13 function addsupportedCorejs3Modules(descriptors) {
14 for (const { global } of Object.values(descriptors)) {
15 for (const dep of global) {
16 supportedCorejs3Modules.add(dep);
17 }
18 }
19 }
20 addsupportedCorejs3Modules(BuiltIns);
21
22 for (const properties of Object.values(StaticProperties)) {
23 addsupportedCorejs3Modules(properties);
24 }
25
26 addsupportedCorejs3Modules(InstanceProperties);
27
28 const allowList = [];
29 describe("corejs3 builtin definitions", () => {
30 it("should support most corejs3 features", () => {
31 let todoListItem = 0;
32 for (const name of corejs3Modules) {
33 if (supportedCorejs3Modules.has(name)) continue;
34 if (name.startsWith("es.")) {
35 const esNextName = "esnext." + name.slice(3);
36 if (supportedCorejs3Modules.has(esNextName)) {
37 todoListItem++;
38 console.error(
39 `Please replace "${esNextName}" by "${name}" in
40 packages/babel-plugin-polyfill-corejs3/src/built-in-definitions.js.`,
41 );
42 continue;
43 }
44 }
45 if (name.startsWith("esnext.")) {
46 const esName = "es." + name.slice(7);
47 if (supportedCorejs3Modules.has(esName)) continue;
48 }
49 allowList.push(name);
50 }
51 for (const name of supportedCorejs3Modules.values()) {
52 if (!corejs3Modules.has(name)) {
53 todoListItem++;
54 console.error(
55 `"${name}" in
56 packages/babel-plugin-polyfill-corejs3/src/built-in-definitions.js
57 is not in "core-js-compat/entries": This is very likely a typo`,
58 );
59 }
60 }
61 expect(todoListItem).toBe(0);
62 // The allowlist should only be added when we decide we don't support
63 // the feature in `src/builtin-definitions.js`
64 expect(allowList).toMatchInlineSnapshot(`
65 Array [
66 "esnext.array.filter-out",
67 "esnext.map.update-or-insert",
68 "esnext.map.upsert",
69 "esnext.object.iterate-entries",
70 "esnext.object.iterate-keys",
71 "esnext.object.iterate-values",
72 "esnext.symbol.replace-all",
73 "esnext.typed-array.filter-out",
74 "esnext.weak-map.upsert",
75 ]
76 `);
77 });
78 });