Skip to content

Commit

Permalink
chore: generate shippedProposals from corejs3 compat data
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Sep 20, 2021
1 parent 934299e commit 01398b8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"private": true,
"license": "MIT",
"scripts": {
"build": "yarn build-es-shims-data && gulp build && gulp bundle",
"build": "yarn build-es-shims-data && yarn build-corejs3-shipped-proposals && gulp build && gulp bundle",
"build-corejs3-shipped-proposals": "node ./scripts/build-corejs3-shipped-proposal.mjs",
"build-es-shims-data": "./scripts/download-compat-table.sh && node ./scripts/build-es-shims-data",
"clean": "rimraf packages/*/lib packages/*/esm",
"clean-all": "yarn clean && rimraf packages/*/node_modules node_modules",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// @flow
// This file is automatically generated by scripts/build-corejs3-shipped-proposals.js

export default new Set<string>([
"esnext.global-this",
"esnext.string.match-all",
"esnext.array.at",
"esnext.object.has-own",
"esnext.typed-array.at",
]);
26 changes: 26 additions & 0 deletions scripts/build-corejs3-shipped-proposals.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import compatData from "../packages/babel-plugin-polyfill-corejs3/core-js-compat/data.js";
import fs from "node:fs";

const path = new URL(
"../packages/babel-plugin-polyfill-corejs3/src/shipped-proposals.js",
import.meta.url
);

const template = features => `// @flow
// This file is automatically generated by scripts/build-corejs3-shipped-proposals.js
export default new Set<string>([
${features.map(f => ` "${f}",\n`).join("")}]);
`;

const shippedProposals = [];

for (const feature in compatData) {
if (!feature.startsWith("esnext.")) continue;
const esName = "es." + feature.slice(7);
if (esName in compatData) continue;
if (Object.keys(compatData[feature]).length === 0) continue;
shippedProposals.push(feature);
}

fs.writeFileSync(path, template(shippedProposals));

0 comments on commit 01398b8

Please sign in to comment.