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

Add optional-chaining and nullish-coalescing to preset-env #10811

Merged
merged 9 commits into from Jan 10, 2020
2 changes: 1 addition & 1 deletion .eslintignore
Expand Up @@ -17,7 +17,7 @@ codemods/*/lib
codemods/*/dist
codemods/*/test/fixtures
codemods/*/test/tmp
packages/babel-preset-env/data
packages/babel-preset-env/data/[^(plugin-features|shipped-proposals).js]
packages/babel-preset-env/test/debug-fixtures
packages/babel-preset-env-standalone/babel-preset-env.js
packages/babel-preset-env-standalone/babel-preset-env.min.js
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-compat-data/data/built-in-modules.json
Expand Up @@ -6,7 +6,7 @@
"safari": "10.1",
"opera": "48",
"ios_saf": "10.3",
"and_chr": "74",
"and_ff": "66"
"and_chr": "71",
"and_ff": "64"
}
}
4 changes: 2 additions & 2 deletions packages/babel-compat-data/data/native-modules.json
Expand Up @@ -6,7 +6,7 @@
"safari": "10.1",
"opera": "48",
"ios_saf": "10.3",
"and_chr": "71",
"and_ff": "64"
"and_chr": "74",
"and_ff": "66"
}
}
9 changes: 9 additions & 0 deletions packages/babel-compat-data/data/plugins.json
Expand Up @@ -299,6 +299,10 @@
"opera": "53",
"electron": "3.1"
},
"proposal-optional-chaining": {
"chrome": "80",
"opera": "67"
},
"transform-named-capturing-groups-regex": {
"chrome": "64",
"safari": "11.1",
Expand Down Expand Up @@ -349,5 +353,10 @@
"phantom": "2",
"samsung": "2.1",
"electron": "0.2"
},
"proposal-nullish-coalescing-operator": {
"chrome": "80",
"firefox": "72",
"opera": "67"
}
}
132 changes: 67 additions & 65 deletions packages/babel-compat-data/scripts/data/plugin-features.js
@@ -1,42 +1,36 @@
/* eslint sort-keys: "error" */

module.exports = {
"transform-template-literals": {
features: ["template literals"],
},
"transform-literals": {
features: ["Unicode code point escapes"],
},
"transform-function-name": {
features: ['function "name" property'],
},
"proposal-async-generator-functions": "Asynchronous Iterators",
"proposal-json-strings": "JSON superset",
"proposal-nullish-coalescing-operator": "nullish coalescing operator (??)",
"proposal-object-rest-spread": "object rest/spread properties",
"proposal-optional-catch-binding": "optional catch binding",
"proposal-optional-chaining": "optional chaining operator (?.)",
"proposal-unicode-property-regex": "RegExp Unicode Property Escapes",

"transform-arrow-functions": {
features: ["arrow functions"],
},

"transform-async-to-generator": {
features: ["async functions"],
},

"transform-block-scoped-functions": {
features: ["block-level function declaration"],
},
"transform-block-scoping": {
features: ["const", "let"],
},
"transform-classes": {
features: ["class", "super"],
},
"transform-object-super": {
features: ["super"],
},
"transform-shorthand-properties": {
features: ["object literal extensions / shorthand properties"],
},
"transform-duplicate-keys": {
features: ["miscellaneous / duplicate property names in strict mode"],
},
"transform-computed-properties": {
features: ["object literal extensions / computed properties"],
},
"transform-for-of": {
features: ["for..of loops"],
},
"transform-sticky-regex": {
features: [
'RegExp "y" and "u" flags / "y" flag, lastIndex',
'RegExp "y" and "u" flags / "y" flag',
],
"transform-destructuring": {
features: ["destructuring, assignment", "destructuring, declarations"],
},

// We want to apply this prior to unicode regex so that "." and "u"
Expand All @@ -45,17 +39,29 @@ module.exports = {
// Ref: https://github.com/babel/babel/pull/7065#issuecomment-395959112
"transform-dotall-regex": "s (dotAll) flag for regular expressions",

"transform-unicode-regex": {
features: [
'RegExp "y" and "u" flags / "u" flag, case folding',
'RegExp "y" and "u" flags / "u" flag, Unicode code point escapes',
'RegExp "y" and "u" flags / "u" flag, non-BMP Unicode characters',
'RegExp "y" and "u" flags / "u" flag',
],
"transform-duplicate-keys": {
features: ["miscellaneous / duplicate property names in strict mode"],
},

"transform-spread": {
features: "spread syntax for iterable objects",
"transform-exponentiation-operator": {
features: ["exponentiation (**) operator"],
},
"transform-for-of": {
features: ["for..of loops"],
},
"transform-function-name": {
features: ['function "name" property'],
},
"transform-literals": {
features: ["Unicode code point escapes"],
},
"transform-member-expression-literals":
"Object/array literal extensions / Reserved words as property names",
"transform-named-capturing-groups-regex": "RegExp named capture groups",
"transform-new-target": {
features: ["new.target"],
},
"transform-object-super": {
features: ["super"],
},
"transform-parameters": {
features: [
Expand All @@ -64,40 +70,36 @@ module.exports = {
"destructuring, parameters / defaults, arrow function",
],
},
"transform-destructuring": {
features: ["destructuring, assignment", "destructuring, declarations"],
"transform-property-literals":
"Object/array literal extensions / Reserved words as property names",
"transform-regenerator": {
features: ["generators"],
},
"transform-block-scoping": {
features: ["const", "let"],
"transform-reserved-words": "Miscellaneous / Unreserved words",
"transform-shorthand-properties": {
features: ["object literal extensions / shorthand properties"],
},
"transform-typeof-symbol": {
features: ["Symbol / typeof support"],
"transform-spread": {
features: "spread syntax for iterable objects",
},
"transform-new-target": {
features: ["new.target"],
"transform-sticky-regex": {
features: [
'RegExp "y" and "u" flags / "y" flag, lastIndex',
'RegExp "y" and "u" flags / "y" flag',
],
},
"transform-regenerator": {
features: ["generators"],
"transform-template-literals": {
features: ["template literals"],
},

"transform-exponentiation-operator": {
features: ["exponentiation (**) operator"],
"transform-typeof-symbol": {
features: ["Symbol / typeof support"],
},

"transform-async-to-generator": {
features: ["async functions"],
"transform-unicode-regex": {
features: [
'RegExp "y" and "u" flags / "u" flag, case folding',
'RegExp "y" and "u" flags / "u" flag, Unicode code point escapes',
'RegExp "y" and "u" flags / "u" flag, non-BMP Unicode characters',
'RegExp "y" and "u" flags / "u" flag',
],
},

"proposal-async-generator-functions": "Asynchronous Iterators",
"proposal-object-rest-spread": "object rest/spread properties",
"proposal-unicode-property-regex": "RegExp Unicode Property Escapes",

"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-reserved-words": "Miscellaneous / Unreserved words",
};
4 changes: 4 additions & 0 deletions packages/babel-preset-env-standalone/package.json
Expand Up @@ -13,7 +13,11 @@
"devDependencies": {
"@babel/plugin-proposal-dynamic-import": "^7.7.4",
"@babel/plugin-proposal-json-strings": "^7.7.4",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.7.4",
"@babel/plugin-proposal-optional-chaining": "^7.7.4",
"@babel/plugin-syntax-json-strings": "^7.7.4",
"@babel/plugin-syntax-nullish-coalescing-operator": "^7.7.4",
"@babel/plugin-syntax-optional-chaining": "^7.7.4",
"@babel/plugin-syntax-top-level-await": "^7.7.4",
"@babel/plugin-transform-named-capturing-groups-regex": "^7.7.4",
"@babel/plugin-transform-new-target": "^7.7.4",
Expand Down
10 changes: 10 additions & 0 deletions packages/babel-preset-env-standalone/src/available-plugins.js
@@ -1,15 +1,25 @@
/* eslint sort-keys: "error" */

import { availablePlugins, registerPlugin } from "@babel/standalone";
import proposalJsonStrings from "@babel/plugin-proposal-json-strings";
import proposalDynamicImport from "@babel/plugin-proposal-dynamic-import";
import proposalNullishCoalescingOperator from "@babel/plugin-proposal-nullish-coalescing-operator";
import proposalOptionalChaining from "@babel/plugin-proposal-optional-chaining";
import syntaxJsonStrings from "@babel/plugin-syntax-json-strings";
import syntaxNullishCoalescingOperator from "@babel/plugin-syntax-nullish-coalescing-operator";
import syntaxOptionalChaining from "@babel/plugin-syntax-nullish-coalescing-operator";
import syntaxTopLevelAwait from "@babel/plugin-syntax-top-level-await";
import transformNamedCapturingGroupsRegex from "@babel/plugin-transform-named-capturing-groups-regex";
import transformNewTarget from "@babel/plugin-transform-new-target";

const notIncludedPlugins = {
"proposal-dynamic-import": proposalDynamicImport,
"proposal-json-strings": proposalJsonStrings,
"proposal-nullish-coalescing-operator": proposalNullishCoalescingOperator,
"proposal-optional-chaining": proposalOptionalChaining,
"syntax-json-strings": syntaxJsonStrings,
"syntax-nullish-coalescing-operator": syntaxNullishCoalescingOperator,
"syntax-optional-chaining": syntaxOptionalChaining,
"syntax-top-level-await": syntaxTopLevelAwait,
"transform-named-capturing-groups-regex": transformNamedCapturingGroupsRegex,
"transform-new-target": transformNewTarget,
Expand Down
26 changes: 18 additions & 8 deletions packages/babel-preset-env/data/shipped-proposals.js
@@ -1,14 +1,24 @@
/* eslint sort-keys: "error" */
// These mappings represent the syntax proposals that have been
// shipped by browsers, and are enabled by the `shippedProposals` option.

const proposalPlugins = {};

const pluginSyntaxMap = new Map([
["proposal-async-generator-functions", "syntax-async-generators"],
["proposal-object-rest-spread", "syntax-object-rest-spread"],
["proposal-optional-catch-binding", "syntax-optional-catch-binding"],
["proposal-unicode-property-regex", null],
["proposal-json-strings", "syntax-json-strings"],
]);
// use intermediary object to enforce alphabetical key order
const pluginSyntaxObject = {
"proposal-async-generator-functions": "syntax-async-generators",
"proposal-json-strings": "syntax-json-strings",
"proposal-nullish-coalescing-operator": "syntax-nullish-coalescing-operator",
"proposal-object-rest-spread": "syntax-object-rest-spread",
"proposal-optional-catch-binding": "syntax-optional-catch-binding",
"proposal-optional-chaining": "syntax-optional-chaining",
"proposal-unicode-property-regex": null,
};

module.exports = { proposalPlugins, pluginSyntaxMap };
const pluginSyntaxEntries = Object.keys(pluginSyntaxObject).map(function (key) {
return [key, pluginSyntaxObject[key]];
});

const pluginSyntaxMap = new Map(pluginSyntaxEntries);

module.exports = { pluginSyntaxMap, proposalPlugins };
4 changes: 4 additions & 0 deletions packages/babel-preset-env/package.json
Expand Up @@ -20,13 +20,17 @@
"@babel/plugin-proposal-dynamic-import": "^7.7.4",
"@babel/plugin-proposal-json-strings": "^7.7.4",
"@babel/plugin-proposal-object-rest-spread": "^7.7.7",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.7.4",
"@babel/plugin-proposal-optional-catch-binding": "^7.7.4",
"@babel/plugin-proposal-optional-chaining": "^7.7.5",
"@babel/plugin-proposal-unicode-property-regex": "^7.7.7",
"@babel/plugin-syntax-async-generators": "^7.7.4",
"@babel/plugin-syntax-dynamic-import": "^7.7.4",
"@babel/plugin-syntax-json-strings": "^7.7.4",
"@babel/plugin-syntax-nullish-coalescing-operator": "^7.7.4",
"@babel/plugin-syntax-object-rest-spread": "^7.7.4",
"@babel/plugin-syntax-optional-catch-binding": "^7.7.4",
"@babel/plugin-syntax-optional-chaining": "^7.7.4",
"@babel/plugin-syntax-top-level-await": "^7.7.4",
"@babel/plugin-transform-arrow-functions": "^7.7.4",
"@babel/plugin-transform-async-to-generator": "^7.7.4",
Expand Down
30 changes: 20 additions & 10 deletions packages/babel-preset-env/src/available-plugins.js
@@ -1,15 +1,21 @@
// @flow
/* eslint sort-keys: "error" */

import syntaxAsyncGenerators from "@babel/plugin-syntax-async-generators";
import syntaxDynamicImport from "@babel/plugin-syntax-dynamic-import";
import syntaxJsonStrings from "@babel/plugin-syntax-json-strings";
import syntaxNullishCoalescingOperator from "@babel/plugin-syntax-nullish-coalescing-operator";
import syntaxObjectRestSpread from "@babel/plugin-syntax-object-rest-spread";
import syntaxOptionalCatchBinding from "@babel/plugin-syntax-optional-catch-binding";
import syntaxOptionalChaining from "@babel/plugin-syntax-optional-chaining";
import syntaxTopLevelAwait from "@babel/plugin-syntax-top-level-await";
import proposalAsyncGeneratorFunctions from "@babel/plugin-proposal-async-generator-functions";
import proposalDynamicImport from "@babel/plugin-proposal-dynamic-import";
import proposalJsonStrings from "@babel/plugin-proposal-json-strings";
import proposalNullishCoalescingOperator from "@babel/plugin-proposal-nullish-coalescing-operator";
import proposalObjectRestSpread from "@babel/plugin-proposal-object-rest-spread";
import proposalOptionalCatchBinding from "@babel/plugin-proposal-optional-catch-binding";
import proposalOptionalChaining from "@babel/plugin-proposal-optional-chaining";
import proposalUnicodePropertyRegex from "@babel/plugin-proposal-unicode-property-regex";
import transformAsyncToGenerator from "@babel/plugin-transform-async-to-generator";
import transformArrowFunctions from "@babel/plugin-transform-arrow-functions";
Expand Down Expand Up @@ -44,24 +50,32 @@ import transformTypeofSymbol from "@babel/plugin-transform-typeof-symbol";
import transformUnicodeRegex from "@babel/plugin-transform-unicode-regex";

export default {
"proposal-async-generator-functions": proposalAsyncGeneratorFunctions,
"proposal-dynamic-import": proposalDynamicImport,
"proposal-json-strings": proposalJsonStrings,
"proposal-nullish-coalescing-operator": proposalNullishCoalescingOperator,
"proposal-object-rest-spread": proposalObjectRestSpread,
"proposal-optional-catch-binding": proposalOptionalCatchBinding,
"proposal-optional-chaining": proposalOptionalChaining,
"proposal-unicode-property-regex": proposalUnicodePropertyRegex,
"syntax-async-generators": syntaxAsyncGenerators,
"syntax-dynamic-import": syntaxDynamicImport,
"syntax-json-strings": syntaxJsonStrings,
"syntax-nullish-coalescing-operator": syntaxNullishCoalescingOperator,
"syntax-object-rest-spread": syntaxObjectRestSpread,
"syntax-optional-catch-binding": syntaxOptionalCatchBinding,
"syntax-optional-chaining": syntaxOptionalChaining,
"syntax-top-level-await": syntaxTopLevelAwait,
"transform-async-to-generator": transformAsyncToGenerator,
"proposal-async-generator-functions": proposalAsyncGeneratorFunctions,
"proposal-dynamic-import": proposalDynamicImport,
"proposal-json-strings": proposalJsonStrings,
"transform-arrow-functions": transformArrowFunctions,
"transform-async-to-generator": transformAsyncToGenerator,
"transform-block-scoped-functions": transformBlockScopedFunctions,
"transform-block-scoping": transformBlockScoping,
"transform-classes": transformClasses,
"transform-computed-properties": transformComputedProperties,
"transform-destructuring": transformDestructuring,
"transform-dotall-regex": transformDotallRegex,
"transform-duplicate-keys": transformDuplicateKeys,
"transform-exponentiation-operator": transformExponentialOperator,
"transform-for-of": transformForOf,
"transform-function-name": transformFunctionName,
"transform-literals": transformLiterals,
Expand All @@ -71,20 +85,16 @@ export default {
"transform-modules-systemjs": transformModulesSystemjs,
"transform-modules-umd": transformModulesUmd,
"transform-named-capturing-groups-regex": transformNamedCapturingGroupsRegex,
"transform-new-target": transformNewTarget,
"transform-object-super": transformObjectSuper,
"transform-parameters": transformParameters,
"transform-property-literals": transformPropertyLiterals,
"transform-regenerator": transformRegenerator,
"transform-reserved-words": transformReservedWords,
"transform-shorthand-properties": transformShorthandProperties,
"transform-spread": transformSpread,
"transform-sticky-regex": transformStickyRegex,
"transform-template-literals": transformTemplateLiterals,
"transform-typeof-symbol": transformTypeofSymbol,
"transform-unicode-regex": transformUnicodeRegex,
"transform-exponentiation-operator": transformExponentialOperator,
"transform-new-target": transformNewTarget,
"proposal-object-rest-spread": proposalObjectRestSpread,
"proposal-optional-catch-binding": proposalOptionalCatchBinding,
"transform-regenerator": transformRegenerator,
"proposal-unicode-property-regex": proposalUnicodePropertyRegex,
};