Skip to content

Commit

Permalink
add builtin definitions checker
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Aug 24, 2021
1 parent 434ae62 commit 00d009b
Showing 1 changed file with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import corejs3Entries from "../core-js-compat/entries";

import {
BuiltIns,
StaticProperties,
InstanceProperties,
} from "../src/built-in-definitions.js";

const supportedCorejs3Modules = new Set();

const corejs3Modules = corejs3Entries["core-js"];

function addsupportedCorejs3Modules(descriptors) {
for (const { global } of Object.values(descriptors)) {
for (const dep of global) {
supportedCorejs3Modules.add(dep);
}
}
}
addsupportedCorejs3Modules(BuiltIns);

for (const properties of Object.values(StaticProperties)) {
addsupportedCorejs3Modules(properties);
}

addsupportedCorejs3Modules(InstanceProperties);

const allowList = new Set([]);

describe("corejs3 builtin definitions", () => {
it("should support most corejs3 features", () => {
let todoListItem = 0;
for (const name of corejs3Modules) {
if (supportedCorejs3Modules.has(name)) continue;
if (name.startsWith("es.")) {
const esNextName = "esnext." + name.slice(3);
if (supportedCorejs3Modules.has(esNextName)) {
todoListItem++;
console.error(
`Please replace "${esNextName}" by "${name}" in
packages/babel-plugin-polyfill-corejs3/src/built-in-definitions.js.`,
);
} else {
if (!allowList.has(name)) {
todoListItem++;
console.error(
`"${esNextName}" is not supported, please add it to
packages/babel-plugin-polyfill-corejs3/src/built-in-definitions.js
or the allowlist in packages/babel-plugin-polyfill-corejs3/test/check-builtin-definitions.test.js`,
);
}
}
}
}
expect(todoListItem).toBe(0);
});
});

0 comments on commit 00d009b

Please sign in to comment.