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

Include preset modules #11083

Merged
merged 13 commits into from
Mar 16, 2020
Merged
1 change: 1 addition & 0 deletions .flowconfig
Expand Up @@ -14,6 +14,7 @@ codemods/*/src
lib/file.js
lib/parser.js
lib/third-party-libs.js.flow
lib/preset-modules.js.flow
packages/babel-types/lib/index.js.flow

[options]
Expand Down
18 changes: 18 additions & 0 deletions lib/preset-modules.js.flow
@@ -0,0 +1,18 @@
declare module "@babel/preset-modules/lib/plugins/transform-async-arrows-in-class" {
declare module.exports: Function;
}
declare module "@babel/preset-modules/lib/plugins/transform-edge-default-parameters" {
declare module.exports: Function;
}
declare module "@babel/preset-modules/lib/plugins/transform-edge-function-name" {
declare module.exports: Function;
}
declare module "@babel/preset-modules/lib/plugins/transform-tagged-template-caching" {
declare module.exports: Function;
}
declare module "@babel/preset-modules/lib/plugins/transform-safari-block-shadowing" {
declare module.exports: Function;
}
declare module "@babel/preset-modules/lib/plugins/transform-safari-for-shadowing" {
declare module.exports: Function;
}
19 changes: 17 additions & 2 deletions packages/babel-compat-data/data/overlapping-plugins.json
@@ -1,3 +1,18 @@
{
"transform-regenerator": []
}
"transform-async-to-generator": [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should transform-regenerator be here too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally yes. We did it in the past,but had to revert it because regenerator doesn't support async functions with polyfilled promises.

I'd like to revisit it in Babel 8 somehow.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. At least when bugfixes is enabled though, regenerator will never be included, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's only included when targeting browsers not supporting generators (we don't use it for async functions).

It's unrelated to bugfixes: it isn't included because of the esmodules option.

"bugfix/transform-async-arrows-in-class"
],
"transform-parameters": [
"bugfix/transform-edge-default-parameters"
],
"transform-function-name": [
"bugfix/transform-edge-function-name"
],
"transform-block-scoping": [
"bugfix/transform-safari-block-shadowing",
"bugfix/transform-safari-for-shadowing"
],
"transform-template-literals": [
"bugfix/transform-tagged-template-caching"
]
}
125 changes: 125 additions & 0 deletions packages/babel-compat-data/data/plugin-bugfixes.json
@@ -0,0 +1,125 @@
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicolo-ribaudo - meta-comment, more on the data format itself: do you think it might be easier to maintain this file if the data only specified which versions were actually affected by the bugfix plugins? For example, the edge function name plugin could just be listed as { "edge": "79" } rather than including the other browser versions which it doesn't have an effect on. A missing browser version could just be taken as "no change".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This data is generated by the same script which generated the old data, so it's easier to generate all the targets 😅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! gotcha.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it could be interesting to create a rendered version based on the data on our website or something? Or just showcasing this in general in a more readable manner?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like compat-table but with plugin names rather than ECMAScript features?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, then you could generate what @developit was saying allow about seeing the diff's or what was actually affected? Maybe we should add a simple readme to explain each json file

"transform-async-to-generator": {
"chrome": "55",
"edge": "15",
"firefox": "52",
"safari": "10.1",
"node": "7.6",
"ios": "10.3",
"samsung": "6",
"opera": "42",
"electron": "1.6"
},
"bugfix/transform-async-arrows-in-class": {
"chrome": "55",
"edge": "15",
"firefox": "52",
"safari": "11",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Safari should be 10.1 / 10.3 here I think? Same as async-to-generator. I may have had references to Safari 11 in the plugin since that's what I had chosen to target, but the fix should work in all ES-Modules-supporting versions of Safari (10.1+ desktop / 10.3+ ios)

Edit: I keep thinking this list is "versions that are fixed by X", but it's actually "oldest version where this plugin is not needed", right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oldest version where this plugin is not needed

👍

"node": "7.6",
"ios": "11",
"samsung": "6",
"opera": "42",
"electron": "1.6"
},
"transform-parameters": {
"chrome": "49",
"edge": "15",
"firefox": "53",
"safari": "10",
"node": "6",
"ios": "10",
"samsung": "5",
"opera": "36",
"electron": "1"
},
"bugfix/transform-edge-default-parameters": {
"chrome": "49",
"edge": "18",
"firefox": "52",
"safari": "10",
"node": "6",
"ios": "10",
"samsung": "5",
"opera": "36",
"electron": "1"
},
"transform-function-name": {
"chrome": "51",
"edge": "14",
"firefox": "53",
"safari": "10",
"node": "6.5",
"ios": "10",
"samsung": "5",
"opera": "38",
"electron": "1.2"
},
"bugfix/transform-edge-function-name": {
"chrome": "51",
"edge": "79",
"firefox": "53",
"safari": "10",
"node": "6.5",
"ios": "10",
"samsung": "5",
"opera": "38",
"electron": "1.2"
},
"transform-block-scoping": {
"chrome": "49",
"edge": "14",
"firefox": "51",
"safari": "10",
"node": "6",
"ios": "10",
"samsung": "5",
"opera": "36",
"electron": "1"
},
"bugfix/transform-safari-block-shadowing": {
"chrome": "49",
"edge": "12",
"firefox": "44",
"safari": "11",
"node": "6",
"ie": "11",
"ios": "11",
"samsung": "5",
"opera": "36",
"electron": "1"
},
"bugfix/transform-safari-for-shadowing": {
"chrome": "49",
"edge": "12",
"firefox": "4",
"safari": "11",
"node": "6",
"ie": "11",
"ios": "11",
"samsung": "5",
"opera": "36",
"electron": "1"
},
"transform-template-literals": {
"chrome": "41",
"edge": "13",
"firefox": "34",
"safari": "9",
"node": "4",
"ios": "9",
"samsung": "3.4",
"opera": "28",
"electron": "0.24"
},
"bugfix/transform-tagged-template-caching": {
"chrome": "41",
"edge": "12",
"firefox": "34",
"safari": "13",
"node": "4",
"ios": "13",
"samsung": "3.4",
"opera": "28",
"electron": "0.24"
}
}
5 changes: 3 additions & 2 deletions packages/babel-compat-data/package.json
Expand Up @@ -13,10 +13,11 @@
"./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"
"./overlapping-plugins": "./data/overlapping-plugins.json",
"./plugin-bugfixes": "./data/plugin-bugfixes.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; node ./scripts/build-corejs3-proposals.js"
"build-data": "./scripts/download-compat-table.sh; node ./scripts/build-data.js; node ./scripts/build-modules-support.js; node ./scripts/build-bugfixes-targets.js"
},
"keywords": [
"babel",
Expand Down
4 changes: 4 additions & 0 deletions packages/babel-compat-data/plugin-bugfixes.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/plugin-bugfixes.json");
77 changes: 77 additions & 0 deletions packages/babel-compat-data/scripts/build-bugfixes-targets.js
@@ -0,0 +1,77 @@
"use strict";

// NOTE: This script must be run _after_ build-data.js

const path = require("path");

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

const data = 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);

for (const env of environments) {
const supportedWithBugfix = getLowestImplementedVersion({ features }, env);
if (supportedWithBugfix) {
generatedTargets[plugin][env] = supportedWithBugfix;
}
}
}

for (const [replaced, features] of Object.entries(allReplacedFeatures)) {
let replacedFeatures = pluginFeatures[replaced];
if (!Array.isArray(replacedFeatures)) {
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;
}
}
}

for (const plugin of Object.values(generatedTargets)) {
addOperaAndElectron(plugin);
}

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

if (!writeFile(data, dataPath, filename)) {
process.exitCode = 1;
break;
}
}