Skip to content

Commit

Permalink
Update preset-env builtin-definitions (#10929)
Browse files Browse the repository at this point in the history
* chore: build corejs3-proposals.json from core-js-compat

* fix: include finished proposals by default

* update test fixtures

* update test fixtures

* chore: rename scripts

* fix: add standarized entries for finished proposals

* refactor: remove unused finished proposals json

* revert test fixtures update

* test against corejs 3.6

* fix: move corejs builtin definitions to babel/compat-data
  • Loading branch information
JLHwung committed Feb 17, 2020
1 parent 31b0506 commit 1613418
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 9 deletions.
4 changes: 4 additions & 0 deletions packages/babel-compat-data/corejs3-shipped-proposals.js
@@ -0,0 +1,4 @@
// Node < 13.3 doesn't support export maps in package.json.
// Use this proxy file as a fallback.

module.exports = require("./data/corejs3-shipped-proposals.json");
@@ -0,0 +1,5 @@
[
"esnext.global-this",
"esnext.promise.all-settled",
"esnext.string.match-all"
]
3 changes: 2 additions & 1 deletion packages/babel-compat-data/package.json
Expand Up @@ -12,10 +12,11 @@
"./plugins": "./data/plugins.json",
"./native-modules": "./data/native-modules.json",
"./corejs2-built-ins": "./data/corejs2-built-ins.json",
"./corejs3-shipped-proposals": "./data/corejs3-shipped-proposals",
"./overlapping-plugins": "./data/overlapping-plugins.json"
},
"scripts": {
"build-data": "./scripts/download-compat-table.sh; node ./scripts/build-data.js; node ./scripts/build-modules-support.js; node ./scripts/build-overlapping-plugins.js"
"build-data": "./scripts/download-compat-table.sh; node ./scripts/build-data.js; node ./scripts/build-modules-support.js; node ./scripts/build-overlapping-plugins.js; node ./scripts/build-corejs3-proposals.js"
},
"keywords": [
"babel",
Expand Down
34 changes: 34 additions & 0 deletions packages/babel-compat-data/scripts/build-corejs3-proposals.js
@@ -0,0 +1,34 @@
const data = require("core-js-compat/data.json");
const fs = require("fs");
const path = require("path");

const features = Object.keys(data);

const shippedProposals = features.filter(feature => {
return feature.startsWith("esnext.") && Object.keys(data[feature]).length > 0;
});

fs.writeFileSync(
path.join(__dirname, "../data/corejs3-shipped-proposals.json"),
JSON.stringify(shippedProposals, undefined, 2) + "\n"
);

const finishedProposals = shippedProposals.filter(feature => {
return features.includes(feature.replace("esnext.", "es."));
});

const builtInDefinitionsPath = path.join(
__dirname,
"../../babel-preset-env/src/polyfills/corejs3/built-in-definitions.js"
);

const builtInDefinitions = fs.readFileSync(builtInDefinitionsPath, "utf-8");

for (const feature of finishedProposals) {
const standarizedName = feature.replace("esnext.", "es.");
if (!builtInDefinitions.includes(standarizedName)) {
console.log(
`${feature} is now standarized as ${standarizedName}, please add "${standarizedName}" to "${builtInDefinitionsPath}"`
);
}
}
Expand Up @@ -158,7 +158,7 @@ export const BuiltIns: ObjectMap<string[]> = {
compositeKey: ["esnext.composite-key"],
compositeSymbol: ["esnext.composite-symbol", ...SymbolDependencies],
fetch: PromiseDependencies,
globalThis: ["esnext.global-this"],
globalThis: ["es.global-this", "esnext.global-this"],
parseFloat: ["es.parse-float"],
parseInt: ["es.parse-int"],
queueMicrotask: ["web.queue-microtask"],
Expand Down Expand Up @@ -205,7 +205,7 @@ export const InstanceProperties: ObjectMap<string[]> = {
lastItem: ["esnext.array.last-item"],
link: ["es.string.link"],
match: ["es.string.match", "es.regexp.exec"],
matchAll: ["esnext.string.match-all"],
matchAll: ["es.string.match-all", "esnext.string.match-all"],
map: ["es.array.map"],
name: ["es.function.name"],
padEnd: ["es.string.pad-end"],
Expand Down Expand Up @@ -355,6 +355,7 @@ export const StaticProperties: ObjectMap<ObjectMap<string | string[]>> = {
Promise: {
all: PromiseDependenciesWithIterators,
allSettled: [
"es.promise.all-settled",
"esnext.promise.all-settled",
...PromiseDependenciesWithIterators,
],
Expand Down

This file was deleted.

@@ -1,7 +1,7 @@
// @flow

import corejs3Polyfills from "core-js-compat/data";
import corejs3ShippedProposalsList from "./shipped-proposals";
import corejs3ShippedProposalsList from "@babel/compat-data/corejs3-shipped-proposals";
import getModulesListForTargetVersion from "core-js-compat/get-modules-list-for-target-version";
import { filterItems } from "@babel/helper-compilation-targets";
import {
Expand Down Expand Up @@ -39,7 +39,7 @@ const corejs3PolyfillsWithoutProposals = Object.keys(corejs3Polyfills)
return memo;
}, {});

const corejs3PolyfillsWithShippedProposals = corejs3ShippedProposalsList.reduce(
const corejs3PolyfillsWithShippedProposals = (corejs3ShippedProposalsList: string[]).reduce(
(memo, key) => {
memo[key] = corejs3Polyfills[key];
return memo;
Expand Down
Expand Up @@ -24,3 +24,6 @@ const foo = new Promise((resolve) => {
queueMicrotask(() => globalThis);

Observable.from(10);

Promise.allSettled([]);
S.matchAll();
Expand Up @@ -4,7 +4,7 @@
"../../../../lib",
{
"useBuiltIns": "usage",
"corejs": 3,
"corejs": "3.6",
"modules": false
}
]
Expand Down
Expand Up @@ -4,12 +4,15 @@ import "core-js/modules/es.symbol.iterator";
import "core-js/modules/es.symbol.match";
import "core-js/modules/es.array.from";
import "core-js/modules/es.array.iterator";
import "core-js/modules/es.global-this";
import "core-js/modules/es.map";
import "core-js/modules/es.object.to-string";
import "core-js/modules/es.promise";
import "core-js/modules/es.promise.all-settled";
import "core-js/modules/es.regexp.exec";
import "core-js/modules/es.string.iterator";
import "core-js/modules/es.string.match";
import "core-js/modules/es.string.match-all";
import "core-js/modules/web.dom-collections.iterator";
import "core-js/modules/web.queue-microtask";
Array.from; // static method
Expand Down Expand Up @@ -49,3 +52,5 @@ queueMicrotask(function () {
return globalThis;
});
Observable.from(10);
Promise.allSettled([]);
S.matchAll();

0 comments on commit 1613418

Please sign in to comment.