Skip to content

Commit 3c2b98f

Browse files
Add class static blocks to preset-env's shippedProposals (#13114)
1 parent 7f5b212 commit 3c2b98f

84 files changed

Lines changed: 151 additions & 16 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/babel-compat-data/data/plugins.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
2+
"proposal-class-static-block": {
3+
"chrome": "91"
4+
},
25
"proposal-class-properties": {
36
"chrome": "74",
47
"opera": "62",
@@ -28,6 +31,7 @@
2831
},
2932
"proposal-logical-assignment-operators": {
3033
"chrome": "85",
34+
"opera": "71",
3135
"edge": "85",
3236
"firefox": "79",
3337
"safari": "14",

packages/babel-compat-data/scripts/data/plugin-features.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ const es2021 = {
135135
};
136136

137137
const shippedProposal = {
138+
"proposal-class-static-block": "Class static initialization blocks",
138139
"proposal-class-properties": {
139140
features: [
140141
"static class fields",

packages/babel-compat-data/scripts/download-compat-table.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
set -e
33

4-
COMPAT_TABLE_COMMIT=ab73608bddb6895f6f3296c03dba057b47ba8aea
4+
COMPAT_TABLE_COMMIT=ca2d70e305bc3295ade6b06a1c33a929db1ccacf
55
GIT_HEAD=build/compat-table/.git/HEAD
66

77
if [ -d "build/compat-table" ]; then

packages/babel-preset-env/data/shipped-proposals.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44

55
const proposalPlugins = new Set([
66
"proposal-class-properties",
7-
"proposal-private-methods"
7+
"proposal-private-methods",
8+
"proposal-class-static-block",
89
]);
910

1011
// use intermediary object to enforce alphabetical key order
1112
const pluginSyntaxObject = {
1213
"proposal-async-generator-functions": "syntax-async-generators",
1314
"proposal-class-properties": "syntax-class-properties",
15+
"proposal-class-static-block": "syntax-class-static-block",
1416
"proposal-json-strings": "syntax-json-strings",
1517
"proposal-nullish-coalescing-operator": "syntax-nullish-coalescing-operator",
1618
"proposal-numeric-separator": "syntax-numeric-separator",

packages/babel-preset-env/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"@babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining": "workspace:^7.13.12",
2424
"@babel/plugin-proposal-async-generator-functions": "workspace:^7.13.15",
2525
"@babel/plugin-proposal-class-properties": "workspace:^7.13.0",
26+
"@babel/plugin-proposal-class-static-block": "workspace:^7.13.11",
2627
"@babel/plugin-proposal-dynamic-import": "workspace:^7.13.8",
2728
"@babel/plugin-proposal-export-namespace-from": "workspace:^7.12.13",
2829
"@babel/plugin-proposal-json-strings": "workspace:^7.13.8",
@@ -36,6 +37,7 @@
3637
"@babel/plugin-proposal-unicode-property-regex": "workspace:^7.12.13",
3738
"@babel/plugin-syntax-async-generators": "^7.8.4",
3839
"@babel/plugin-syntax-class-properties": "workspace:^7.12.13",
40+
"@babel/plugin-syntax-class-static-block": "workspace:^7.12.13",
3941
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
4042
"@babel/plugin-syntax-export-namespace-from": "^7.8.3",
4143
"@babel/plugin-syntax-json-strings": "^7.8.3",

packages/babel-preset-env/src/available-plugins.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import syntaxAsyncGenerators from "@babel/plugin-syntax-async-generators";
55
import syntaxClassProperties from "@babel/plugin-syntax-class-properties";
6+
import syntaxClassStaticBlock from "@babel/plugin-syntax-class-static-block";
67
import syntaxDynamicImport from "@babel/plugin-syntax-dynamic-import";
78
import syntaxExportNamespaceFrom from "@babel/plugin-syntax-export-namespace-from";
89
import syntaxJsonStrings from "@babel/plugin-syntax-json-strings";
@@ -15,6 +16,7 @@ import syntaxOptionalChaining from "@babel/plugin-syntax-optional-chaining";
1516
import syntaxTopLevelAwait from "@babel/plugin-syntax-top-level-await";
1617
import proposalAsyncGeneratorFunctions from "@babel/plugin-proposal-async-generator-functions";
1718
import proposalClassProperties from "@babel/plugin-proposal-class-properties";
19+
import proposalClassStaticBlock from "@babel/plugin-proposal-class-static-block";
1820
import proposalDynamicImport from "@babel/plugin-proposal-dynamic-import";
1921
import proposalExportNamespaceFrom from "@babel/plugin-proposal-export-namespace-from";
2022
import proposalJsonStrings from "@babel/plugin-proposal-json-strings";
@@ -78,6 +80,7 @@ export default {
7880
bugfixV8SpreadParametersInOptionalChaining,
7981
"proposal-async-generator-functions": () => proposalAsyncGeneratorFunctions,
8082
"proposal-class-properties": () => proposalClassProperties,
83+
"proposal-class-static-block": () => proposalClassStaticBlock,
8184
"proposal-dynamic-import": () => proposalDynamicImport,
8285
"proposal-export-namespace-from": () => proposalExportNamespaceFrom,
8386
"proposal-json-strings": () => proposalJsonStrings,
@@ -93,6 +96,7 @@ export default {
9396
"proposal-unicode-property-regex": () => proposalUnicodePropertyRegex,
9497
"syntax-async-generators": () => syntaxAsyncGenerators,
9598
"syntax-class-properties": () => syntaxClassProperties,
99+
"syntax-class-static-block": () => syntaxClassStaticBlock,
96100
"syntax-dynamic-import": () => syntaxDynamicImport,
97101
"syntax-export-namespace-from": () => syntaxExportNamespaceFrom,
98102
"syntax-json-strings": () => syntaxJsonStrings,
@@ -138,3 +142,7 @@ export default {
138142
"transform-unicode-escapes": () => transformUnicodeEscapes,
139143
"transform-unicode-regex": () => transformUnicodeRegex,
140144
};
145+
146+
export const minVersions = {
147+
"proposal-class-static-block": "7.12.0",
148+
};

packages/babel-preset-env/src/filter-items.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
// @flow
22

3+
import { lt } from "semver";
4+
import { minVersions } from "./available-plugins";
5+
6+
// $FlowIgnore
7+
const has = Function.call.bind(Object.hasOwnProperty);
8+
39
export function removeUnnecessaryItems(
410
items: Set<string>,
511
overlapping: { [name: string]: string[] },
@@ -8,3 +14,13 @@ export function removeUnnecessaryItems(
814
overlapping[item]?.forEach(name => items.delete(name));
915
});
1016
}
17+
export function removeUnsupportedItems(
18+
items: Set<string>,
19+
babelVersion: string,
20+
) {
21+
items.forEach(item => {
22+
if (has(minVersions, item) && lt(babelVersion, minVersions[item])) {
23+
items.delete(item);
24+
}
25+
});
26+
}

packages/babel-preset-env/src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { SemVer, lt } from "semver";
44
import { logPlugin } from "./debug";
55
import getOptionSpecificExcludesFor from "./get-option-specific-excludes";
6-
import { removeUnnecessaryItems } from "./filter-items";
6+
import { removeUnnecessaryItems, removeUnsupportedItems } from "./filter-items";
77
import moduleTransformations from "./module-transformations";
88
import normalizeOptions from "./normalize-options";
99
import { proposalPlugins, pluginSyntaxMap } from "../data/shipped-proposals";
@@ -374,6 +374,7 @@ option \`forceAllTransforms: true\` instead.
374374
pluginSyntaxMap,
375375
);
376376
removeUnnecessaryItems(pluginNames, overlappingPlugins);
377+
removeUnsupportedItems(pluginNames, api.version);
377378

378379
const polyfillPlugins = getPolyfillPlugins({
379380
useBuiltIns,

packages/babel-preset-env/test/fixtures/bugfixes/_esmodules-no-bugfixes/stdout.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Using modules transform: auto
1717

1818
Using plugins:
1919
proposal-numeric-separator { android, chrome < 75, edge < 79, firefox < 70, ios < 13, opera < 62, safari < 13, samsung < 11 }
20-
proposal-logical-assignment-operators { android, chrome < 85, edge < 85, firefox < 79, ios < 14, node < 15, opera, safari < 14, samsung }
20+
proposal-logical-assignment-operators { android, chrome < 85, edge < 85, firefox < 79, ios < 14, node < 15, opera < 71, safari < 14, samsung }
2121
proposal-nullish-coalescing-operator { android, chrome < 80, edge < 80, firefox < 72, ios < 13.4, node < 14, opera < 67, safari < 13.1, samsung < 13 }
2222
proposal-optional-chaining { android, chrome, edge, firefox < 74, ios < 13.4, node, opera, safari < 13.1, samsung }
2323
proposal-json-strings { android, chrome < 66, edge < 79, firefox < 62, ios < 12, opera < 53, safari < 12, samsung < 9 }

packages/babel-preset-env/test/fixtures/bugfixes/_esmodules/stdout.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Using modules transform: auto
1717

1818
Using plugins:
1919
proposal-numeric-separator { android, chrome < 75, edge < 79, firefox < 70, ios < 13, opera < 62, safari < 13, samsung < 11 }
20-
proposal-logical-assignment-operators { android, chrome < 85, edge < 85, firefox < 79, ios < 14, node < 15, opera, safari < 14, samsung }
20+
proposal-logical-assignment-operators { android, chrome < 85, edge < 85, firefox < 79, ios < 14, node < 15, opera < 71, safari < 14, samsung }
2121
proposal-nullish-coalescing-operator { android, chrome < 80, edge < 80, firefox < 72, ios < 13.4, node < 14, opera < 67, safari < 13.1, samsung < 13 }
2222
proposal-optional-chaining { android, chrome < 80, edge < 80, firefox < 74, ios < 13.4, node < 14, opera < 67, safari < 13.1, samsung < 13 }
2323
proposal-json-strings { android, chrome < 66, edge < 79, firefox < 62, ios < 12, opera < 53, safari < 12, samsung < 9 }

0 commit comments

Comments
 (0)