Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify compat-data generation with and without bugfixes: true #14305

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
128 changes: 64 additions & 64 deletions packages/babel-compat-data/data/plugin-bugfixes.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
{
"transform-async-to-generator": {
"chrome": "55",
"opera": "42",
"edge": "15",
"firefox": "52",
"safari": "10.1",
"node": "7.6",
"ios": "10.3",
"samsung": "6",
"electron": "1.6"
},
"bugfix/transform-async-arrows-in-class": {
"chrome": "55",
"opera": "42",
Expand All @@ -21,17 +10,6 @@
"samsung": "6",
"electron": "1.6"
},
"transform-parameters": {
"chrome": "49",
"opera": "36",
"edge": "15",
"firefox": "53",
"safari": "10",
"node": "6",
"ios": "10",
"samsung": "5",
"electron": "0.37"
},
"bugfix/transform-edge-default-parameters": {
"chrome": "49",
"opera": "36",
Expand All @@ -43,17 +21,6 @@
"samsung": "5",
"electron": "0.37"
},
"transform-function-name": {
"chrome": "51",
"opera": "38",
"edge": "14",
"firefox": "53",
"safari": "10",
"node": "6.5",
"ios": "10",
"samsung": "5",
"electron": "1.2"
},
"bugfix/transform-edge-function-name": {
"chrome": "51",
"opera": "38",
Expand All @@ -65,17 +32,6 @@
"samsung": "5",
"electron": "1.2"
},
"transform-block-scoping": {
"chrome": "49",
"opera": "36",
"edge": "14",
"firefox": "51",
"safari": "10",
"node": "6",
"ios": "10",
"samsung": "5",
"electron": "0.37"
},
"bugfix/transform-safari-block-shadowing": {
"chrome": "49",
"opera": "36",
Expand Down Expand Up @@ -110,17 +66,6 @@
"samsung": "5",
"electron": "0.37"
},
"transform-template-literals": {
"chrome": "41",
"opera": "28",
"edge": "13",
"firefox": "34",
"safari": "9",
"node": "4",
"ios": "9",
"samsung": "3.4",
"electron": "0.21"
},
"bugfix/transform-tagged-template-caching": {
"chrome": "41",
"opera": "28",
Expand All @@ -133,6 +78,16 @@
"rhino": "1.7.14",
"electron": "0.21"
},
"bugfix/transform-v8-spread-parameters-in-optional-chaining": {
"chrome": "91",
"opera": "77",
"edge": "91",
"firefox": "74",
"safari": "13.1",
"node": "16.9",
"ios": "13.4",
"electron": "13.0"
},
"proposal-optional-chaining": {
"chrome": "80",
"opera": "67",
Expand All @@ -144,14 +99,59 @@
"samsung": "13",
"electron": "8.0"
},
"bugfix/transform-v8-spread-parameters-in-optional-chaining": {
"chrome": "91",
"opera": "77",
"edge": "91",
"firefox": "74",
"safari": "13.1",
"node": "16.9",
"ios": "13.4",
"electron": "13.0"
"transform-parameters": {
"chrome": "49",
"opera": "36",
"edge": "15",
"firefox": "53",
"safari": "10",
"node": "6",
"ios": "10",
"samsung": "5",
"electron": "0.37"
},
"transform-async-to-generator": {
"chrome": "55",
"opera": "42",
"edge": "15",
"firefox": "52",
"safari": "10.1",
"node": "7.6",
"ios": "10.3",
"samsung": "6",
"electron": "1.6"
},
"transform-template-literals": {
"chrome": "41",
"opera": "28",
"edge": "13",
"firefox": "34",
"safari": "9",
"node": "4",
"ios": "9",
"samsung": "3.4",
"electron": "0.21"
},
"transform-function-name": {
"chrome": "51",
"opera": "38",
"edge": "14",
"firefox": "53",
"safari": "10",
"node": "6.5",
"ios": "10",
"samsung": "5",
"electron": "1.2"
},
"transform-block-scoping": {
"chrome": "49",
"opera": "36",
"edge": "14",
"firefox": "51",
"safari": "10",
"node": "6",
"ios": "10",
"samsung": "5",
"electron": "0.37"
}
}
69 changes: 16 additions & 53 deletions packages/babel-compat-data/scripts/build-bugfixes-targets.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,71 +3,34 @@
// NOTE: This script must be run _after_ build-data.js

const path = require("path");
const { addElectronSupportFromChromium } = require("./chromium-to-electron");

const {
getLowestImplementedVersion,
environments,
writeFile,
} = require("./utils-build-data");
const { generateData, environments, writeFile } = require("./utils-build-data");

const data = require("./data/plugin-bugfixes");
const pluginBugfixes = require("./data/plugin-bugfixes");
const pluginFeatures = require("./data/plugin-features");

const generatedTargets = {};
const overlappingPlugins = {};

const allReplacedFeatures = {};

const has = Function.call.bind(Object.hasOwnProperty);

for (const [plugin, { replaces, features }] of Object.entries(data)) {
if (!has(overlappingPlugins, replaces)) {
overlappingPlugins[replaces] = [];
generatedTargets[replaces] = {};
allReplacedFeatures[replaces] = [];
}
generatedTargets[plugin] = {};

allReplacedFeatures[replaces].push(...features);

overlappingPlugins[replaces].push(plugin);
const { data: dataWithBugfixes, overlapping } = generateData(
environments,
Object.assign({}, pluginBugfixes, pluginFeatures)
);

for (const env of environments) {
const supportedWithBugfix = getLowestImplementedVersion({ features }, env);
if (supportedWithBugfix) {
generatedTargets[plugin][env] = supportedWithBugfix;
}
}
addElectronSupportFromChromium(generatedTargets[plugin]);
}
const dataWithoutBugfixes = require("../data/plugins.json");

for (const [replaced, features] of Object.entries(allReplacedFeatures)) {
let replacedFeatures = pluginFeatures[replaced];
for (const [key, support] of Object.entries(dataWithBugfixes)) {
const originalSupport = dataWithoutBugfixes[key];
if (
typeof replacedFeatures === "object" &&
!Array.isArray(replacedFeatures)
originalSupport &&
Object.keys(support).length === Object.keys(originalSupport).length &&
Object.keys(support).every(env => support[env] === originalSupport[env])
) {
replacedFeatures = replacedFeatures.features;
}

for (const env of environments) {
const stillNotSupported = getLowestImplementedVersion(
{ features: replacedFeatures },
env,
name => features.some(feat => name.includes(feat))
);

if (stillNotSupported) {
generatedTargets[replaced][env] = stillNotSupported;
}
// The data with and without bugfixes is the same; we can avoid saving it twice.
delete dataWithBugfixes[key];
}
addElectronSupportFromChromium(generatedTargets[replaced]);
}

for (const [filename, data] of [
["plugin-bugfixes", generatedTargets],
["overlapping-plugins", overlappingPlugins],
["plugin-bugfixes", dataWithBugfixes],
["overlapping-plugins", overlapping],
]) {
const dataPath = path.join(__dirname, `../data/${filename}.json`);

Expand Down
5 changes: 4 additions & 1 deletion packages/babel-compat-data/scripts/build-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ const { process } = require("./build-modules-support");
const { generateData, environments, writeFile } = require("./utils-build-data");

for (const target of ["plugin", "corejs2-built-in"]) {
const newData = generateData(
// We ignore 'overlapping' here, because it's already generated by
// built-bugfixes-targets.js which has a complete view over all the
// plugins that we have data for.
const { data: newData } = generateData(
environments,
require(`./data/${target}-features`)
);
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-compat-data/scripts/data/plugin-features.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ const es2020 = {
};

const es2021 = {
"proposal-numeric-separator": "numeric separator",
"proposal-numeric-separator": "numeric separators",
"proposal-logical-assignment-operators": "Logical Assignment",
};

Expand Down
47 changes: 40 additions & 7 deletions packages/babel-compat-data/scripts/utils-build-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const compatibilityTests = compatSources.flatMap(data =>
})
);

exports.getLowestImplementedVersion = (
const getLowestImplementedVersion = (
{ features },
env,
exclude = () => false
Expand Down Expand Up @@ -88,29 +88,62 @@ exports.getLowestImplementedVersion = (
return result.version.join(".").replace(/\.0$/, "");
};

const expandFeatures = features =>
features.flatMap(feat => {
if (feat.includes("/")) return [feat];
return compatibilityTests
.map(test => test.name)
.filter(name => name === feat || name.startsWith(feat + " / "));
});

exports.generateData = (environments, features) => {
const data = {};

// eslint-disable-next-line prefer-const
for (let [key, options] of Object.entries(features)) {
const normalized = {};
for (const [key, options] of Object.entries(features)) {
if (!options.features) {
options = {
features: [options],
normalized[key] = {
features: expandFeatures([options]),
};
} else {
normalized[key] = {
...options,
features: expandFeatures(options.features),
};
}
}

const overlapping = {};

// Apply bugfixes
for (const [key, { features, replaces }] of Object.entries(normalized)) {
if (replaces) {
if (normalized[replaces].replaces) {
throw new Error("Transitive replacement is not supported");
}
normalized[replaces].features = normalized[replaces].features.filter(
feat => !features.includes(feat)
);

if (!overlapping[replaces]) overlapping[replaces] = [];
overlapping[replaces].push(key);
}
}

// eslint-disable-next-line prefer-const
for (let [key, options] of Object.entries(normalized)) {
const plugin = {};

environments.forEach(env => {
const version = exports.getLowestImplementedVersion(options, env);
const version = getLowestImplementedVersion(options, env);
if (version) plugin[env] = version;
});
addElectronSupportFromChromium(plugin);

data[key] = plugin;
}

return data;
return { data, overlapping };
};

exports.writeFile = function (data, dataPath, name) {
Expand Down