Skip to content

Commit

Permalink
Extract targets parser and compat data from preset-env (babel#10899)
Browse files Browse the repository at this point in the history
* Extract targets parser and compat data from preset-env

* Review by Jùnliàng

* isItemRequired -> targetsSupported

* Export isRequired
  • Loading branch information
nicolo-ribaudo authored Jan 10, 2020
1 parent 5f807ae commit 04354d1
Show file tree
Hide file tree
Showing 59 changed files with 936 additions and 707 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ dist
package-lock.json
!/.github/actions/*/package-lock.json

/packages/babel-compat-data/build

/packages/babel-runtime/helpers/*.js
!/packages/babel-runtime/helpers/toArray.js
!/packages/babel-runtime/helpers/iterableToArray.js
Expand Down
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package.json
packages/babel-preset-env/data
packages/babel-compat-data/data
packages/babel-compat-data/scripts/data/overlapping-plugins.js
packages/*/test/fixtures/**/input.*
packages/*/test/fixtures/**/exec.*
packages/*/test/fixtures/**/output.*
7 changes: 6 additions & 1 deletion Gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,12 @@ function buildRollup(packages) {
},
}),
rollupCommonJs({
include: [/node_modules/, "packages/babel-preset-env/data/**"],
include: [
/node_modules/,
"packages/babel-preset-env/data/*.js",
// Rollup doesn't read export maps, so it loads the cjs fallback
"packages/babel-compat-data/*.js",
],
namedExports: {
"babel-plugin-dynamic-import-node/utils.js": [
"createDynamicImportTransform",
Expand Down
12 changes: 2 additions & 10 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,16 @@ module.exports = function(api) {
switch (env) {
// Configs used during bundling builds.
case "rollup":
convertESM = false;
ignoreLib = false;
// rollup-commonjs will converts node_modules to ESM
unambiguousSources.push(
"**/node_modules",
// todo: remove this after it is rewritten into ESM
"packages/babel-preset-env/data"
);
envOpts.targets = {
node: nodeVersion,
};
break;
case "standalone":
convertESM = false;
ignoreLib = false;
unambiguousSources.push(
"**/node_modules",
"packages/babel-preset-env/data"
"packages/babel-preset-env/data",
"packages/babel-compat-data"
);
// targets to browserslists: defaults
break;
Expand Down
4 changes: 4 additions & 0 deletions packages/babel-compat-data/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
scripts
src
test
*.log
4 changes: 4 additions & 0 deletions packages/babel-compat-data/corejs2-built-ins.js
Original file line number Diff line number Diff line change
@@ -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/corejs2-built-ins.json");
12 changes: 12 additions & 0 deletions packages/babel-compat-data/data/built-in-modules.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"es6.module": {
"edge": "16",
"firefox": "60",
"chrome": "61",
"safari": "10.1",
"opera": "48",
"ios_saf": "10.3",
"and_chr": "74",
"and_ff": "66"
}
}
3 changes: 3 additions & 0 deletions packages/babel-compat-data/data/overlapping-plugins.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"transform-regenerator": []
}
File renamed without changes.
4 changes: 4 additions & 0 deletions packages/babel-compat-data/native-modules.js
Original file line number Diff line number Diff line change
@@ -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/native-modules.json");
4 changes: 4 additions & 0 deletions packages/babel-compat-data/overlapping-plugins.js
Original file line number Diff line number Diff line change
@@ -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/overlapping-plugins.json");
36 changes: 36 additions & 0 deletions packages/babel-compat-data/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "@babel/compat-data",
"version": "0.0.0",
"author": "The Babel Team (https://babeljs.io/team)",
"license": "MIT",
"description": "",
"repository": "https://github.com/babel/babel/tree/master/packages/babel-compat-data",
"publishConfig": {
"access": "public"
},
"exports": {
"./plugins": "./data/plugins.json",
"./native-modules": "./data/native-modules.json",
"./corejs2-built-ins": "./data/corejs2-built-ins.json",
"./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"
},
"keywords": [
"babel",
"compat-table",
"compat-data"
],
"dependencies": {
"browserslist": "^4.8.2",
"invariant": "^2.2.4",
"semver": "^7.1.1"
},
"devDependencies": {
"caniuse-db": "1.0.30000969",
"electron-to-chromium": "1.3.113",
"lodash": "^4.17.15",
"@babel/helper-compilation-targets": "^0.0.0"
}
}
4 changes: 4 additions & 0 deletions packages/babel-compat-data/plugins.js
Original file line number Diff line number Diff line change
@@ -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/plugins.json");
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const flattenDeep = require("lodash/flattenDeep");
const isEqual = require("lodash/isEqual");
const mapValues = require("lodash/mapValues");
const pickBy = require("lodash/pickBy");
const unreleasedLabels = require("../data/unreleased-labels");
const { unreleasedLabels } = require("babel/helper-compilation-targets");
const electronToChromiumVersions = require("electron-to-chromium").versions;

const electronToChromiumKeys = Object.keys(
Expand Down Expand Up @@ -293,7 +293,7 @@ const generateData = (environments, features) => {
["plugin", "corejs2-built-in"].forEach(target => {
const newData = generateData(
environments,
require(`../data/${target}-features`)
require(`./data/${target}-features`)
);
const dataPath = path.join(__dirname, `../data/${target}s.json`);

Expand Down
15 changes: 15 additions & 0 deletions packages/babel-compat-data/scripts/build-overlapping-plugins.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"use strict";

const fs = require("fs");
const overlappingPlugins = require("./data/overlapping-plugins");

fs.writeFileSync(
__dirname + "/../data/overlapping-plugins.json",
JSON.stringify(overlappingPlugins, replacer, 2)
);

function replacer(key, val) {
if (val instanceof Set) return Array.from(val);
if (val instanceof Map) return Object.fromEntries(val);
return val;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@ const typedArrayMethods = [
"typed arrays / %TypedArray%[Symbol.species]",
];

const es = {
module.exports = {
// compat-table missing babel6 mapping
// "es6.array.concat": {
// features: [
// "well-known symbols / Symbol.isConcatSpreadable",
// "well-known symbols / Symbol.species, Array.prototype.concat",
// ]
// },
"es6.array.copy-within": "Array.prototype methods / Array.prototype.copyWithin",
"es6.array.copy-within":
"Array.prototype methods / Array.prototype.copyWithin",
"es6.array.every": "Array methods / Array.prototype.every",
"es6.array.fill": "Array.prototype methods / Array.prototype.fill",
"es6.array.filter": {
Expand All @@ -46,7 +47,8 @@ const es = {
},
"es6.array.find": "Array.prototype methods / Array.prototype.find",
"es6.array.find-index": "Array.prototype methods / Array.prototype.findIndex",
"es7.array.flat-map": "Array.prototype.{flat, flatMap} / Array.prototype.flatMap",
"es7.array.flat-map":
"Array.prototype.{flat, flatMap} / Array.prototype.flatMap",
"es6.array.for-each": "Array methods / Array.prototype.forEach",
"es6.array.from": "Array static methods / Array.from",
"es7.array.includes": "Array.prototype.includes",
Expand Down Expand Up @@ -90,8 +92,8 @@ const es = {
"es6.function.has-instance": "well-known symbols / Symbol.hasInstance",
"es6.function.name": {
features: [
"function \"name\" property / function statements",
"function \"name\" property / function expressions",
'function "name" property / function statements',
'function "name" property / function expressions',
],
},

Expand Down Expand Up @@ -174,13 +176,19 @@ const es = {
],
},
"es6.object.define-property": "Object static methods / Object.defineProperty",
"es6.object.define-properties": "Object static methods / Object.defineProperties",
"es6.object.define-properties":
"Object static methods / Object.defineProperties",
"es7.object.entries": "Object static methods / Object.entries",
"es6.object.freeze": "Object static methods accept primitives / Object.freeze",
"es6.object.get-own-property-descriptor": "Object static methods accept primitives / Object.getOwnPropertyDescriptor",
"es7.object.get-own-property-descriptors": "Object static methods / Object.getOwnPropertyDescriptors",
"es6.object.get-own-property-names": "Object static methods accept primitives / Object.getOwnPropertyNames",
"es6.object.get-prototype-of": "Object static methods accept primitives / Object.getPrototypeOf",
"es6.object.freeze":
"Object static methods accept primitives / Object.freeze",
"es6.object.get-own-property-descriptor":
"Object static methods accept primitives / Object.getOwnPropertyDescriptor",
"es7.object.get-own-property-descriptors":
"Object static methods / Object.getOwnPropertyDescriptors",
"es6.object.get-own-property-names":
"Object static methods accept primitives / Object.getOwnPropertyNames",
"es6.object.get-prototype-of":
"Object static methods accept primitives / Object.getPrototypeOf",
"es7.object.lookup-getter": {
features: [
"Object.prototype getter/setter methods / __lookupGetter__",
Expand All @@ -199,15 +207,20 @@ const es = {
"Object.prototype getter/setter methods / __lookupSetter__, data properties can shadow accessors",
],
},
"es6.object.prevent-extensions": "Object static methods accept primitives / Object.preventExtensions",
"es6.object.prevent-extensions":
"Object static methods accept primitives / Object.preventExtensions",
"es6.object.to-string": "well-known symbols / Symbol.toStringTag",
"es6.object.is": "Object static methods / Object.is",
"es6.object.is-frozen": "Object static methods accept primitives / Object.isFrozen",
"es6.object.is-sealed": "Object static methods accept primitives / Object.isSealed",
"es6.object.is-extensible": "Object static methods accept primitives / Object.isExtensible",
"es6.object.is-frozen":
"Object static methods accept primitives / Object.isFrozen",
"es6.object.is-sealed":
"Object static methods accept primitives / Object.isSealed",
"es6.object.is-extensible":
"Object static methods accept primitives / Object.isExtensible",
"es6.object.keys": "Object static methods accept primitives / Object.keys",
"es6.object.seal": "Object static methods accept primitives / Object.seal",
"es6.object.set-prototype-of": "Object static methods / Object.setPrototypeOf",
"es6.object.set-prototype-of":
"Object static methods / Object.setPrototypeOf",
"es7.object.values": "Object static methods / Object.values",

"es6.promise": {
Expand All @@ -224,7 +237,8 @@ const es = {
"es6.reflect.define-property": "Reflect / Reflect.defineProperty",
"es6.reflect.delete-property": "Reflect / Reflect.deleteProperty",
"es6.reflect.get": "Reflect / Reflect.get",
"es6.reflect.get-own-property-descriptor": "Reflect / Reflect.getOwnPropertyDescriptor",
"es6.reflect.get-own-property-descriptor":
"Reflect / Reflect.getOwnPropertyDescriptor",
"es6.reflect.get-prototype-of": "Reflect / Reflect.getPrototypeOf",
"es6.reflect.has": "Reflect / Reflect.has",
"es6.reflect.is-extensible": "Reflect / Reflect.isExtensible",
Expand All @@ -240,11 +254,16 @@ const es = {
],
},
"es6.regexp.flags": "RegExp.prototype properties / RegExp.prototype.flags",
"es6.regexp.match": "RegExp.prototype properties / RegExp.prototype[Symbol.match]",
"es6.regexp.replace": "RegExp.prototype properties / RegExp.prototype[Symbol.replace]",
"es6.regexp.split": "RegExp.prototype properties / RegExp.prototype[Symbol.split]",
"es6.regexp.search": "RegExp.prototype properties / RegExp.prototype[Symbol.search]",
"es6.regexp.to-string": "miscellaneous / RegExp.prototype.toString generic and uses \"flags\" property",
"es6.regexp.match":
"RegExp.prototype properties / RegExp.prototype[Symbol.match]",
"es6.regexp.replace":
"RegExp.prototype properties / RegExp.prototype[Symbol.replace]",
"es6.regexp.split":
"RegExp.prototype properties / RegExp.prototype[Symbol.split]",
"es6.regexp.search":
"RegExp.prototype properties / RegExp.prototype[Symbol.search]",
"es6.regexp.to-string":
'miscellaneous / RegExp.prototype.toString generic and uses "flags" property',

// This is explicit due to prevent the stage-1 Set proposals under the
// category "Set methods" from being included.
Expand Down Expand Up @@ -295,23 +314,27 @@ const es = {
"es6.string.big": "String.prototype HTML methods",
"es6.string.blink": "String.prototype HTML methods",
"es6.string.bold": "String.prototype HTML methods",
"es6.string.code-point-at": "String.prototype methods / String.prototype.codePointAt",
"es6.string.ends-with": "String.prototype methods / String.prototype.endsWith",
"es6.string.code-point-at":
"String.prototype methods / String.prototype.codePointAt",
"es6.string.ends-with":
"String.prototype methods / String.prototype.endsWith",
"es6.string.fixed": "String.prototype HTML methods",
"es6.string.fontcolor": "String.prototype HTML methods",
"es6.string.fontsize": "String.prototype HTML methods",
"es6.string.from-code-point": "String static methods / String.fromCodePoint",
"es6.string.includes": "String.prototype methods / String.prototype.includes",
"es6.string.italics": "String.prototype HTML methods",
"es6.string.iterator": "String.prototype methods / String.prototype[Symbol.iterator]",
"es6.string.iterator":
"String.prototype methods / String.prototype[Symbol.iterator]",
"es6.string.link": "String.prototype HTML methods",
// "String.prototype methods / String.prototype.normalize" not implemented
"es7.string.pad-start": "String padding / String.prototype.padStart",
"es7.string.pad-end": "String padding / String.prototype.padEnd",
"es6.string.raw": "String static methods / String.raw",
"es6.string.repeat": "String.prototype methods / String.prototype.repeat",
"es6.string.small": "String.prototype HTML methods",
"es6.string.starts-with": "String.prototype methods / String.prototype.startsWith",
"es6.string.starts-with":
"String.prototype methods / String.prototype.startsWith",
"es6.string.strike": "String.prototype HTML methods",
"es6.string.sub": "String.prototype HTML methods",
"es6.string.sup": "String.prototype HTML methods",
Expand Down Expand Up @@ -353,7 +376,3 @@ const es = {

"es6.weak-set": "WeakSet",
};

const proposals = require("./shipped-proposals").builtIns;

module.exports = Object.assign({}, es, proposals);
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ module.exports = new Map();

// async -> regenerator is better than async -> generator -> regenerator
ifIncluded("transform-regenerator")
// https://github.com/babel/babel/issues/10678
// Temporarly disabled: https://github.com/babel/babel/issues/10678
// .isUnnecessary("transform-async-to-generator");

function ifIncluded(name) {
const set = new Set();
module.exports.set(name, set);
return {
isUnnecessary(name) { set.add(name); return this; }
isUnnecessary(name) { set.add(name); return this; },
};
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const es = {
module.exports = {
"transform-template-literals": {
features: ["template literals"],
},
Expand Down Expand Up @@ -65,10 +65,7 @@ const es = {
],
},
"transform-destructuring": {
features: [
"destructuring, assignment",
"destructuring, declarations",
],
features: ["destructuring, assignment", "destructuring, declarations"],
},
"transform-block-scoping": {
features: ["const", "let"],
Expand Down Expand Up @@ -98,11 +95,9 @@ const es = {
"proposal-json-strings": "JSON superset",
"proposal-optional-catch-binding": "optional catch binding",
"transform-named-capturing-groups-regex": "RegExp named capture groups",
"transform-member-expression-literals": "Object/array literal extensions / Reserved words as property names",
"transform-property-literals": "Object/array literal extensions / Reserved words as property names",
"transform-member-expression-literals":
"Object/array literal extensions / Reserved words as property names",
"transform-property-literals":
"Object/array literal extensions / Reserved words as property names",
"transform-reserved-words": "Miscellaneous / Unreserved words",
};

const proposals = require("./shipped-proposals").features;

module.exports = Object.assign({}, es, proposals);
3 changes: 3 additions & 0 deletions packages/babel-helper-compilation-targets/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
src
test
*.log
Loading

0 comments on commit 04354d1

Please sign in to comment.