From 48a3e196dd92d5be9d0cae832a2375b69de99995 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Sun, 31 Mar 2024 10:44:56 +0200 Subject: [PATCH] Create bugfix plugin for classes in computed keys in Firefox (#16390) --- .../data/overlapping-plugins.json | 6 +- .../data/plugin-bugfixes.json | 12 ++ packages/babel-compat-data/data/plugins.json | 12 ++ .../scripts/data/plugin-features.js | 7 ++ .../scripts/utils-build-data.js | 30 ++++- .../.npmignore | 3 + .../README.md | 19 +++ .../package.json | 57 +++++++++ .../src/index.ts | 113 ++++++++++++++++++ .../basic/nested-in-expression/input.js | 4 + .../basic/nested-in-expression/output.js | 4 + .../test/fixtures/basic/options.json | 3 + .../simple-class-in-computed-key/input.js | 4 + .../simple-class-in-computed-key/output.js | 4 + .../test/fixtures/basic/yield-await/input.mjs | 16 +++ .../fixtures/basic/yield-await/output.mjs | 21 ++++ .../decorators-plugin-after/input.js | 5 + .../decorators-plugin-after/options.json | 6 + .../decorators-plugin-after/output.js | 14 +++ .../decorators-plugin-before/input.js | 5 + .../decorators-plugin-before/options.json | 6 + .../decorators-plugin-before/output.js | 14 +++ .../decorators-transform/exported/input.mjs | 5 + .../exported/options.json | 6 + .../decorators-transform/exported/output.mjs | 15 +++ .../class-already-wrapped/input.js | 4 + .../class-already-wrapped/output.js | 4 + .../no-private-in-outer-class/input.js | 4 + .../no-private-in-outer-class/output.js | 6 + .../test/fixtures/no-transform/options.json | 3 + .../test/index.js | 3 + .../test/package.json | 1 + packages/babel-preset-env/package.json | 1 + .../babel-preset-env/src/available-plugins.ts | 3 + .../input.js | 4 + .../options.json | 5 + .../output.js | 4 + .../stdout.txt | 28 +++++ .../input.js | 4 + .../options.json | 5 + .../output.js | 9 ++ .../stdout.txt | 43 +++++++ .../input.js | 4 + .../options.json | 5 + .../output.js | 4 + .../stdout.txt | 30 +++++ .../input.js | 0 .../options.json | 0 .../output.js | 0 .../input.js | 0 .../options.json | 0 .../output.js | 0 .../input.js | 0 .../options.json | 0 .../output.js | 0 .../input.js | 0 .../options.json | 0 .../output.js | 0 .../browserslists-defaults-not-ie/stdout.txt | 1 + .../browserslists-defaults/stdout.txt | 1 + .../stdout.txt | 1 + .../browserslists-defaults-not-ie/stdout.txt | 1 + .../debug/browserslists-defaults/stdout.txt | 1 + .../stdout.txt | 1 + tsconfig.json | 4 + yarn.lock | 15 +++ 66 files changed, 583 insertions(+), 7 deletions(-) create mode 100644 packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/.npmignore create mode 100644 packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/README.md create mode 100644 packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/package.json create mode 100644 packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/src/index.ts create mode 100644 packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/basic/nested-in-expression/input.js create mode 100644 packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/basic/nested-in-expression/output.js create mode 100644 packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/basic/options.json create mode 100644 packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/basic/simple-class-in-computed-key/input.js create mode 100644 packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/basic/simple-class-in-computed-key/output.js create mode 100644 packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/basic/yield-await/input.mjs create mode 100644 packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/basic/yield-await/output.mjs create mode 100644 packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/decorators-transform/decorators-plugin-after/input.js create mode 100644 packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/decorators-transform/decorators-plugin-after/options.json create mode 100644 packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/decorators-transform/decorators-plugin-after/output.js create mode 100644 packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/decorators-transform/decorators-plugin-before/input.js create mode 100644 packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/decorators-transform/decorators-plugin-before/options.json create mode 100644 packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/decorators-transform/decorators-plugin-before/output.js create mode 100644 packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/decorators-transform/exported/input.mjs create mode 100644 packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/decorators-transform/exported/options.json create mode 100644 packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/decorators-transform/exported/output.mjs create mode 100644 packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/no-transform/class-already-wrapped/input.js create mode 100644 packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/no-transform/class-already-wrapped/output.js create mode 100644 packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/no-transform/no-private-in-outer-class/input.js create mode 100644 packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/no-transform/no-private-in-outer-class/output.js create mode 100644 packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/no-transform/options.json create mode 100644 packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/index.js create mode 100644 packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/package.json create mode 100644 packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-chrome-100/input.js create mode 100644 packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-chrome-100/options.json create mode 100644 packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-chrome-100/output.js create mode 100644 packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-chrome-100/stdout.txt create mode 100644 packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-firefox-50/input.js create mode 100644 packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-firefox-50/options.json create mode 100644 packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-firefox-50/output.js create mode 100644 packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-firefox-50/stdout.txt create mode 100644 packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-firefox-90/input.js create mode 100644 packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-firefox-90/options.json create mode 100644 packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-firefox-90/output.js create mode 100644 packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-firefox-90/stdout.txt rename packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/{chrome-70-static-class-fields => static-class-fields-chrome-70}/input.js (100%) rename packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/{chrome-70-static-class-fields => static-class-fields-chrome-70}/options.json (100%) rename packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/{chrome-70-static-class-fields => static-class-fields-chrome-70}/output.js (100%) rename packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/{chrome-90-static-class-fields => static-class-fields-chrome-90}/input.js (100%) rename packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/{chrome-90-static-class-fields => static-class-fields-chrome-90}/options.json (100%) rename packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/{chrome-90-static-class-fields => static-class-fields-chrome-90}/output.js (100%) rename packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/{chrome-96-static-class-fields => static-class-fields-chrome-96}/input.js (100%) rename packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/{chrome-96-static-class-fields => static-class-fields-chrome-96}/options.json (100%) rename packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/{chrome-96-static-class-fields => static-class-fields-chrome-96}/output.js (100%) rename packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/{chrome-97-static-class-fields => static-class-fields-chrome-97}/input.js (100%) rename packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/{chrome-97-static-class-fields => static-class-fields-chrome-97}/options.json (100%) rename packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/{chrome-97-static-class-fields => static-class-fields-chrome-97}/output.js (100%) diff --git a/packages/babel-compat-data/data/overlapping-plugins.json b/packages/babel-compat-data/data/overlapping-plugins.json index 8b34821145db..0722826136b2 100644 --- a/packages/babel-compat-data/data/overlapping-plugins.json +++ b/packages/babel-compat-data/data/overlapping-plugins.json @@ -23,9 +23,11 @@ "bugfix/transform-v8-spread-parameters-in-optional-chaining" ], "transform-class-properties": [ - "bugfix/transform-v8-static-class-fields-redefine-readonly" + "bugfix/transform-v8-static-class-fields-redefine-readonly", + "bugfix/transform-firefox-class-in-computed-class-key" ], "proposal-class-properties": [ - "bugfix/transform-v8-static-class-fields-redefine-readonly" + "bugfix/transform-v8-static-class-fields-redefine-readonly", + "bugfix/transform-firefox-class-in-computed-class-key" ] } diff --git a/packages/babel-compat-data/data/plugin-bugfixes.json b/packages/babel-compat-data/data/plugin-bugfixes.json index 2f55547d384d..55b560213885 100644 --- a/packages/babel-compat-data/data/plugin-bugfixes.json +++ b/packages/babel-compat-data/data/plugin-bugfixes.json @@ -107,6 +107,18 @@ "opera_mobile": "64", "electron": "13.0" }, + "bugfix/transform-firefox-class-in-computed-class-key": { + "chrome": "74", + "opera": "62", + "edge": "79", + "safari": "14.1", + "node": "12", + "deno": "1", + "ios": "14.5", + "samsung": "11", + "opera_mobile": "53", + "electron": "6.0" + }, "transform-optional-chaining": { "chrome": "80", "opera": "67", diff --git a/packages/babel-compat-data/data/plugins.json b/packages/babel-compat-data/data/plugins.json index dcf37fdf9447..25bb9bd218f3 100644 --- a/packages/babel-compat-data/data/plugins.json +++ b/packages/babel-compat-data/data/plugins.json @@ -23,6 +23,18 @@ "opera_mobile": "52", "electron": "17.0" }, + "bugfix/transform-firefox-class-in-computed-class-key": { + "chrome": "74", + "opera": "62", + "edge": "79", + "safari": "14.1", + "node": "12", + "deno": "1", + "ios": "14.5", + "samsung": "11", + "opera_mobile": "53", + "electron": "6.0" + }, "transform-class-static-block": { "chrome": "94", "opera": "80", diff --git a/packages/babel-compat-data/scripts/data/plugin-features.js b/packages/babel-compat-data/scripts/data/plugin-features.js index d5e5d40fd355..8f245526b1b8 100644 --- a/packages/babel-compat-data/scripts/data/plugin-features.js +++ b/packages/babel-compat-data/scripts/data/plugin-features.js @@ -162,6 +162,13 @@ const es2022 = { features: ["static class fields / static class fields use [[Define]]"], replaces: "transform-class-properties", }, + "bugfix/transform-firefox-class-in-computed-class-key": { + replaces: "transform-class-properties", + overwrite: { + // TODO: Once Firefox releases the fix, write the correct version here. + firefox: undefined, + }, + }, "transform-class-static-block": "Class static initialization blocks", "transform-private-property-in-object": "Ergonomic brand checks for private fields", diff --git a/packages/babel-compat-data/scripts/utils-build-data.js b/packages/babel-compat-data/scripts/utils-build-data.js index 30209eac582b..11a862a7f338 100644 --- a/packages/babel-compat-data/scripts/utils-build-data.js +++ b/packages/babel-compat-data/scripts/utils-build-data.js @@ -103,6 +103,14 @@ exports.generateData = (environments, features) => { const normalized = {}; for (const [key, options] of Object.entries(features)) { + if (options.overwrite) { + if (!options.replaces || options.features) { + throw new Error( + `.overwrite is only supported when using .replace and not defining .features (${key})` + ); + } + options.features = features[options.replaces].features; + } if (!options.features) { normalized[key] = { features: expandFeatures([options]), @@ -118,14 +126,24 @@ exports.generateData = (environments, features) => { const overlapping = {}; // Apply bugfixes - for (const [key, { features, replaces }] of Object.entries(normalized)) { + for (const [key, { features, replaces, overwrite }] of Object.entries( + normalized + )) { if (replaces) { if (normalized[replaces].replaces) { - throw new Error("Transitive replacement is not supported"); + throw new Error(`Transitive replacement is not supported (${key})`); + } + + if (overwrite) { + normalized[key] = { + features: normalized[replaces].features, + overwrite, + }; + } else { + normalized[replaces].features = normalized[replaces].features.filter( + feat => !features.includes(feat) + ); } - normalized[replaces].features = normalized[replaces].features.filter( - feat => !features.includes(feat) - ); if (!overlapping[replaces]) overlapping[replaces] = []; overlapping[replaces].push(key); @@ -142,6 +160,8 @@ exports.generateData = (environments, features) => { }); addElectronSupportFromChromium(plugin); + if (options.overwrite) Object.assign(plugin, options.overwrite); + data[key] = plugin; } diff --git a/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/.npmignore b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/.npmignore new file mode 100644 index 000000000000..f9806945836e --- /dev/null +++ b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/.npmignore @@ -0,0 +1,3 @@ +src +test +*.log diff --git a/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/README.md b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/README.md new file mode 100644 index 000000000000..b259f9616e19 --- /dev/null +++ b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/README.md @@ -0,0 +1,19 @@ +# @babel/plugin-bugfix-firefox-class-in-computed-class-key + +> Wraps classes defined in computed keys of other classes affected by https://bugzilla.mozilla.org/show_bug.cgi?id=1887677 + +See our website [@babel/plugin-bugfix-firefox-class-in-computed-class-key](https://babeljs.io/docs/babel-plugin-bugfix-firefox-class-in-computed-class-key) for more information. + +## Install + +Using npm: + +```sh +npm install --save-dev @babel/plugin-bugfix-firefox-class-in-computed-class-key +``` + +or using yarn: + +```sh +yarn add @babel/plugin-bugfix-firefox-class-in-computed-class-key --dev +``` diff --git a/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/package.json b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/package.json new file mode 100644 index 000000000000..8fcb4556b310 --- /dev/null +++ b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/package.json @@ -0,0 +1,57 @@ +{ + "name": "@babel/plugin-bugfix-firefox-class-in-computed-class-key", + "version": "7.24.1", + "description": "Wraps classes defined in computed keys of other classes affected by https://bugzilla.mozilla.org/show_bug.cgi?id=1887677", + "repository": { + "type": "git", + "url": "https://github.com/babel/babel.git", + "directory": "packages/babel-plugin-bugfix-firefox-class-in-computed-class-key" + }, + "homepage": "https://babel.dev/docs/en/next/babel-plugin-bugfix-firefox-class-in-computed-class-key", + "license": "MIT", + "publishConfig": { + "access": "public" + }, + "main": "./lib/index.js", + "exports": { + ".": "./lib/index.js", + "./package.json": "./package.json" + }, + "keywords": [ + "babel-plugin", + "bugfix" + ], + "dependencies": { + "@babel/helper-environment-visitor": "workspace:^", + "@babel/helper-plugin-utils": "workspace:^" + }, + "peerDependencies": { + "@babel/core": "^7.0.0" + }, + "devDependencies": { + "@babel/core": "workspace:^", + "@babel/helper-plugin-test-runner": "workspace:^", + "@babel/traverse": "workspace:^" + }, + "engines": { + "node": ">=6.9.0" + }, + "author": "The Babel Team (https://babel.dev/team)", + "conditions": { + "USE_ESM": [ + { + "type": "module" + }, + null + ], + "BABEL_8_BREAKING": [ + { + "engines": { + "node": "^16.20.0 || ^18.16.0 || >=20.0.0" + } + }, + {} + ] + }, + "type": "commonjs" +} diff --git a/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/src/index.ts b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/src/index.ts new file mode 100644 index 000000000000..8c03203e49f4 --- /dev/null +++ b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/src/index.ts @@ -0,0 +1,113 @@ +import type { NodePath, Visitor } from "@babel/traverse"; +import type { types as t } from "@babel/core"; +import { declare } from "@babel/helper-plugin-utils"; +import environmentVisitor from "@babel/helper-environment-visitor"; + +export default declare(({ types: t, traverse, assertVersion }) => { + assertVersion(REQUIRED_VERSION(7)); + + const containsClassExpressionVisitor: Visitor<{ found: boolean }> = { + ClassExpression(path, state) { + state.found = true; + path.stop(); + }, + Function(path) { + path.skip(); + }, + }; + + const containsYieldOrAwaitVisitor = traverse.visitors.merge([ + { + YieldExpression(path, state) { + state.yield = true; + if (state.await) path.stop(); + }, + AwaitExpression(path, state) { + state.await = true; + if (state.yield) path.stop(); + }, + } satisfies Visitor<{ yield: boolean; await: boolean }>, + environmentVisitor, + ]); + + function containsClassExpression(path: NodePath) { + if (t.isClassExpression(path.node)) return true; + if (t.isFunction(path.node)) return false; + const state = { found: false }; + path.traverse(containsClassExpressionVisitor, state); + return state.found; + } + + function wrap(path: NodePath) { + const context = { + yield: t.isYieldExpression(path.node), + await: t.isAwaitExpression(path.node), + }; + path.traverse(containsYieldOrAwaitVisitor, context); + + let replacement; + + if (context.yield) { + const fn = t.functionExpression( + null, + [], + t.blockStatement([t.returnStatement(path.node)]), + /* generator */ true, + /* async */ context.await, + ); + + replacement = t.yieldExpression( + t.callExpression(t.memberExpression(fn, t.identifier("call")), [ + t.thisExpression(), + // NOTE: In some context arguments is invalid (it might not be defined + // in the top-level scope, or it's a syntax error in static class blocks). + // However, `yield` is also invalid in those contexts, so we can safely + // inject a reference to arguments. + t.identifier("arguments"), + ]), + true, + ); + } else { + const fn = t.arrowFunctionExpression([], path.node, context.await); + + if (context.await) { + replacement = t.awaitExpression(t.callExpression(fn, [])); + } else { + replacement = t.callExpression( + // We need to use fn.call() instead of just fn() because + // terser transforms (() => class {})() to class {}, effectively + // undoing the wrapping introduced by this plugin. + // https://github.com/terser/terser/issues/1514 + // TODO(Babel 8): Remove .call if Terser stops inlining this case. + t.memberExpression(fn, t.identifier("call")), + [], + ); + } + } + + path.replaceWith(replacement); + } + + return { + name: "bugfix-firefox-class-in-computed-class-key", + + visitor: { + Class(path) { + const hasPrivateElement = path.node.body.body.some(node => + t.isPrivate(node), + ); + if (!hasPrivateElement) return; + + for (const elem of path.get("body.body")) { + if ( + "computed" in elem.node && + elem.node.computed && + containsClassExpression(elem.get("key")) + ) { + wrap(elem.get("key")); + } + } + }, + }, + }; +}); diff --git a/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/basic/nested-in-expression/input.js b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/basic/nested-in-expression/input.js new file mode 100644 index 000000000000..2b2bd486224b --- /dev/null +++ b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/basic/nested-in-expression/input.js @@ -0,0 +1,4 @@ +class A { + #x = 1; + [useIt([1 + class {}])]; +} \ No newline at end of file diff --git a/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/basic/nested-in-expression/output.js b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/basic/nested-in-expression/output.js new file mode 100644 index 000000000000..9be05d7485ce --- /dev/null +++ b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/basic/nested-in-expression/output.js @@ -0,0 +1,4 @@ +class A { + #x = 1; + [(() => useIt([1 + class {}])).call()]; +} diff --git a/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/basic/options.json b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/basic/options.json new file mode 100644 index 000000000000..54416e990f1b --- /dev/null +++ b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/basic/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["bugfix-firefox-class-in-computed-class-key"] +} diff --git a/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/basic/simple-class-in-computed-key/input.js b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/basic/simple-class-in-computed-key/input.js new file mode 100644 index 000000000000..4de1ad8df0c1 --- /dev/null +++ b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/basic/simple-class-in-computed-key/input.js @@ -0,0 +1,4 @@ +class A { + #x = 1; + [class {}]; +} \ No newline at end of file diff --git a/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/basic/simple-class-in-computed-key/output.js b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/basic/simple-class-in-computed-key/output.js new file mode 100644 index 000000000000..ca54288022a3 --- /dev/null +++ b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/basic/simple-class-in-computed-key/output.js @@ -0,0 +1,4 @@ +class A { + #x = 1; + [(() => class {}).call()]; +} diff --git a/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/basic/yield-await/input.mjs b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/basic/yield-await/input.mjs new file mode 100644 index 000000000000..b56e259b9b20 --- /dev/null +++ b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/basic/yield-await/input.mjs @@ -0,0 +1,16 @@ +class A { + #x; + [class {}] + [await class {}] +} + +async function* f() { + class A { + #x; + [class {}] + [await class {}] + [yield class {}] + [yield* class {}] + [await (yield class {})] + } +} diff --git a/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/basic/yield-await/output.mjs b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/basic/yield-await/output.mjs new file mode 100644 index 000000000000..a61f5e2e6020 --- /dev/null +++ b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/basic/yield-await/output.mjs @@ -0,0 +1,21 @@ +class A { + #x; + [(() => class {}).call()]; + [await (async () => await class {})()]; +} +async function* f() { + class A { + #x; + [(() => class {}).call()]; + [await (async () => await class {})()]; + [yield* function* () { + return yield class {}; + }.call(this, arguments)]; + [yield* function* () { + return yield* class {}; + }.call(this, arguments)]; + [yield* async function* () { + return await (yield class {}); + }.call(this, arguments)]; + } +} diff --git a/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/decorators-transform/decorators-plugin-after/input.js b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/decorators-transform/decorators-plugin-after/input.js new file mode 100644 index 000000000000..e7014dea3bc2 --- /dev/null +++ b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/decorators-transform/decorators-plugin-after/input.js @@ -0,0 +1,5 @@ +@deco +class A { + #x = 1; + static #y = 2; +} diff --git a/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/decorators-transform/decorators-plugin-after/options.json b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/decorators-transform/decorators-plugin-after/options.json new file mode 100644 index 000000000000..57327db77c5f --- /dev/null +++ b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/decorators-transform/decorators-plugin-after/options.json @@ -0,0 +1,6 @@ +{ + "plugins": [ + "bugfix-firefox-class-in-computed-class-key", + ["proposal-decorators", { "version": "2023-11" }] + ] +} diff --git a/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/decorators-transform/decorators-plugin-after/output.js b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/decorators-transform/decorators-plugin-after/output.js new file mode 100644 index 000000000000..5b16f5951f58 --- /dev/null +++ b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/decorators-transform/decorators-plugin-after/output.js @@ -0,0 +1,14 @@ +let _initClass; +let _A; +new class extends babelHelpers.identity { + static [(() => class A { + static { + [_A, _initClass] = babelHelpers.applyDecs2311(this, [deco], []).c; + } + #x = 1; + }).call()]; + #y = 2; + constructor() { + super(_A), _initClass(); + } +}(); diff --git a/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/decorators-transform/decorators-plugin-before/input.js b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/decorators-transform/decorators-plugin-before/input.js new file mode 100644 index 000000000000..e7014dea3bc2 --- /dev/null +++ b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/decorators-transform/decorators-plugin-before/input.js @@ -0,0 +1,5 @@ +@deco +class A { + #x = 1; + static #y = 2; +} diff --git a/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/decorators-transform/decorators-plugin-before/options.json b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/decorators-transform/decorators-plugin-before/options.json new file mode 100644 index 000000000000..e17179ba1c59 --- /dev/null +++ b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/decorators-transform/decorators-plugin-before/options.json @@ -0,0 +1,6 @@ +{ + "plugins": [ + ["proposal-decorators", { "version": "2023-11" }], + "bugfix-firefox-class-in-computed-class-key" + ] +} diff --git a/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/decorators-transform/decorators-plugin-before/output.js b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/decorators-transform/decorators-plugin-before/output.js new file mode 100644 index 000000000000..5b16f5951f58 --- /dev/null +++ b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/decorators-transform/decorators-plugin-before/output.js @@ -0,0 +1,14 @@ +let _initClass; +let _A; +new class extends babelHelpers.identity { + static [(() => class A { + static { + [_A, _initClass] = babelHelpers.applyDecs2311(this, [deco], []).c; + } + #x = 1; + }).call()]; + #y = 2; + constructor() { + super(_A), _initClass(); + } +}(); diff --git a/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/decorators-transform/exported/input.mjs b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/decorators-transform/exported/input.mjs new file mode 100644 index 000000000000..a21cc656d3a3 --- /dev/null +++ b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/decorators-transform/exported/input.mjs @@ -0,0 +1,5 @@ +@deco +export class A { + #x = 1; + static #y = 2; +} diff --git a/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/decorators-transform/exported/options.json b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/decorators-transform/exported/options.json new file mode 100644 index 000000000000..e17179ba1c59 --- /dev/null +++ b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/decorators-transform/exported/options.json @@ -0,0 +1,6 @@ +{ + "plugins": [ + ["proposal-decorators", { "version": "2023-11" }], + "bugfix-firefox-class-in-computed-class-key" + ] +} diff --git a/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/decorators-transform/exported/output.mjs b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/decorators-transform/exported/output.mjs new file mode 100644 index 000000000000..f3e4ddb6c0a7 --- /dev/null +++ b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/decorators-transform/exported/output.mjs @@ -0,0 +1,15 @@ +let _initClass; +let _A; +new class extends babelHelpers.identity { + static [(() => class A { + static { + [_A, _initClass] = babelHelpers.applyDecs2311(this, [deco], []).c; + } + #x = 1; + }).call()]; + #y = 2; + constructor() { + super(_A), _initClass(); + } +}(); +export { _A as A }; diff --git a/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/no-transform/class-already-wrapped/input.js b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/no-transform/class-already-wrapped/input.js new file mode 100644 index 000000000000..5b48dec1d99a --- /dev/null +++ b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/no-transform/class-already-wrapped/input.js @@ -0,0 +1,4 @@ +class A { + #x; + [run(() => class {})] +} diff --git a/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/no-transform/class-already-wrapped/output.js b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/no-transform/class-already-wrapped/output.js new file mode 100644 index 000000000000..4e9e87aa886d --- /dev/null +++ b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/no-transform/class-already-wrapped/output.js @@ -0,0 +1,4 @@ +class A { + #x; + [run(() => class {})]; +} diff --git a/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/no-transform/no-private-in-outer-class/input.js b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/no-transform/no-private-in-outer-class/input.js new file mode 100644 index 000000000000..05a5b811ef61 --- /dev/null +++ b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/no-transform/no-private-in-outer-class/input.js @@ -0,0 +1,4 @@ +class A { + x; + [class { #y }] +} diff --git a/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/no-transform/no-private-in-outer-class/output.js b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/no-transform/no-private-in-outer-class/output.js new file mode 100644 index 000000000000..727bfdd78419 --- /dev/null +++ b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/no-transform/no-private-in-outer-class/output.js @@ -0,0 +1,6 @@ +class A { + x; + [class { + #y; + }]; +} diff --git a/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/no-transform/options.json b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/no-transform/options.json new file mode 100644 index 000000000000..54416e990f1b --- /dev/null +++ b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/fixtures/no-transform/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["bugfix-firefox-class-in-computed-class-key"] +} diff --git a/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/index.js b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/index.js new file mode 100644 index 000000000000..21a55ce6b5e7 --- /dev/null +++ b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/index.js @@ -0,0 +1,3 @@ +import runner from "@babel/helper-plugin-test-runner"; + +runner(import.meta.url); diff --git a/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/package.json b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/package.json new file mode 100644 index 000000000000..5ffd9800b97c --- /dev/null +++ b/packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/test/package.json @@ -0,0 +1 @@ +{ "type": "module" } diff --git a/packages/babel-preset-env/package.json b/packages/babel-preset-env/package.json index f0dfcb86452e..bfff0af63442 100644 --- a/packages/babel-preset-env/package.json +++ b/packages/babel-preset-env/package.json @@ -20,6 +20,7 @@ "@babel/helper-compilation-targets": "workspace:^", "@babel/helper-plugin-utils": "workspace:^", "@babel/helper-validator-option": "workspace:^", + "@babel/plugin-bugfix-firefox-class-in-computed-class-key": "workspace:^", "@babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression": "workspace:^", "@babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining": "workspace:^", "@babel/plugin-bugfix-v8-static-class-fields-redefine-readonly": "workspace:^", diff --git a/packages/babel-preset-env/src/available-plugins.ts b/packages/babel-preset-env/src/available-plugins.ts index a6bd440c621e..f1d694aa1d82 100644 --- a/packages/babel-preset-env/src/available-plugins.ts +++ b/packages/babel-preset-env/src/available-plugins.ts @@ -55,6 +55,7 @@ import transformUnicodeSetsRegex from "@babel/plugin-transform-unicode-sets-rege import bugfixAsyncArrowsInClass from "@babel/preset-modules/lib/plugins/transform-async-arrows-in-class/index.js"; import bugfixEdgeDefaultParameters from "@babel/preset-modules/lib/plugins/transform-edge-default-parameters/index.js"; import bugfixEdgeFunctionName from "@babel/preset-modules/lib/plugins/transform-edge-function-name/index.js"; +import bugfixFirefoxClassInComputedKey from "@babel/plugin-bugfix-firefox-class-in-computed-class-key"; import bugfixTaggedTemplateCaching from "@babel/preset-modules/lib/plugins/transform-tagged-template-caching/index.js"; import bugfixSafariBlockShadowing from "@babel/preset-modules/lib/plugins/transform-safari-block-shadowing/index.js"; import bugfixSafariForShadowing from "@babel/preset-modules/lib/plugins/transform-safari-for-shadowing/index.js"; @@ -67,6 +68,8 @@ const availablePlugins = { "bugfix/transform-async-arrows-in-class": () => bugfixAsyncArrowsInClass, "bugfix/transform-edge-default-parameters": () => bugfixEdgeDefaultParameters, "bugfix/transform-edge-function-name": () => bugfixEdgeFunctionName, + "bugfix/transform-firefox-class-in-computed-class-key": () => + bugfixFirefoxClassInComputedKey, "bugfix/transform-safari-block-shadowing": () => bugfixSafariBlockShadowing, "bugfix/transform-safari-for-shadowing": () => bugfixSafariForShadowing, "bugfix/transform-safari-id-destructuring-collision-in-function-expression": diff --git a/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-chrome-100/input.js b/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-chrome-100/input.js new file mode 100644 index 000000000000..2c76451b89e5 --- /dev/null +++ b/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-chrome-100/input.js @@ -0,0 +1,4 @@ +class A { + #x; + [class {}] +} diff --git a/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-chrome-100/options.json b/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-chrome-100/options.json new file mode 100644 index 000000000000..31df526c609f --- /dev/null +++ b/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-chrome-100/options.json @@ -0,0 +1,5 @@ +{ + "validateLogs": true, + "targets": { "chrome": 100 }, + "presets": [["env", { "debug": true }]] +} diff --git a/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-chrome-100/output.js b/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-chrome-100/output.js new file mode 100644 index 000000000000..7a3839da8e14 --- /dev/null +++ b/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-chrome-100/output.js @@ -0,0 +1,4 @@ +class A { + #x; + [class {}]; +} diff --git a/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-chrome-100/stdout.txt b/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-chrome-100/stdout.txt new file mode 100644 index 000000000000..55cf79898cbc --- /dev/null +++ b/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-chrome-100/stdout.txt @@ -0,0 +1,28 @@ +@babel/preset-env: `DEBUG` option + +Using targets: +{ + "chrome": "100" +} + +Using modules transform: auto + +Using plugins: + transform-unicode-sets-regex { chrome < 112 } + syntax-class-static-block + syntax-private-property-in-object + syntax-class-properties + syntax-numeric-separator + syntax-nullish-coalescing-operator + syntax-optional-chaining + syntax-json-strings + syntax-optional-catch-binding + syntax-async-generators + syntax-object-rest-spread + transform-export-namespace-from { } + transform-modules-commonjs + transform-dynamic-import + syntax-top-level-await + syntax-import-meta + +Using polyfills: No polyfills were added, since the `useBuiltIns` option was not set. diff --git a/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-firefox-50/input.js b/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-firefox-50/input.js new file mode 100644 index 000000000000..2c76451b89e5 --- /dev/null +++ b/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-firefox-50/input.js @@ -0,0 +1,4 @@ +class A { + #x; + [class {}] +} diff --git a/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-firefox-50/options.json b/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-firefox-50/options.json new file mode 100644 index 000000000000..50c9bd473272 --- /dev/null +++ b/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-firefox-50/options.json @@ -0,0 +1,5 @@ +{ + "validateLogs": true, + "targets": { "firefox": 50 }, + "presets": [["env", { "debug": true }]] +} diff --git a/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-firefox-50/output.js b/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-firefox-50/output.js new file mode 100644 index 000000000000..bccee5b6a07e --- /dev/null +++ b/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-firefox-50/output.js @@ -0,0 +1,9 @@ +var _ref; +var _x = /*#__PURE__*/new WeakMap(); +_ref = class {}; +class A { + constructor() { + babelHelpers.classPrivateFieldInitSpec(this, _x, void 0); + babelHelpers.defineProperty(this, _ref, void 0); + } +} diff --git a/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-firefox-50/stdout.txt b/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-firefox-50/stdout.txt new file mode 100644 index 000000000000..a55d12009948 --- /dev/null +++ b/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-firefox-50/stdout.txt @@ -0,0 +1,43 @@ +@babel/preset-env: `DEBUG` option + +Using targets: +{ + "firefox": "50" +} + +Using modules transform: auto + +Using plugins: + transform-unicode-sets-regex { firefox < 116 } + transform-class-static-block { firefox < 93 } + transform-private-property-in-object { firefox < 90 } + transform-class-properties { firefox < 90 } + transform-private-methods { firefox < 90 } + transform-numeric-separator { firefox < 70 } + transform-logical-assignment-operators { firefox < 79 } + transform-nullish-coalescing-operator { firefox < 72 } + transform-optional-chaining { firefox < 74 } + transform-json-strings { firefox < 62 } + transform-optional-catch-binding { firefox < 58 } + transform-parameters { firefox < 53 } + transform-async-generator-functions { firefox < 57 } + transform-object-rest-spread { firefox < 55 } + transform-dotall-regex { firefox < 78 } + transform-unicode-property-regex { firefox < 78 } + transform-named-capturing-groups-regex { firefox < 78 } + transform-async-to-generator { firefox < 52 } + transform-exponentiation-operator { firefox < 52 } + transform-literals { firefox < 53 } + transform-function-name { firefox < 53 } + transform-for-of { firefox < 53 } + transform-unicode-escapes { firefox < 53 } + transform-destructuring { firefox < 53 } + transform-block-scoping { firefox < 53 } + transform-regenerator { firefox < 53 } + transform-export-namespace-from { firefox < 80 } + transform-modules-commonjs + transform-dynamic-import + syntax-top-level-await + syntax-import-meta + +Using polyfills: No polyfills were added, since the `useBuiltIns` option was not set. diff --git a/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-firefox-90/input.js b/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-firefox-90/input.js new file mode 100644 index 000000000000..2c76451b89e5 --- /dev/null +++ b/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-firefox-90/input.js @@ -0,0 +1,4 @@ +class A { + #x; + [class {}] +} diff --git a/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-firefox-90/options.json b/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-firefox-90/options.json new file mode 100644 index 000000000000..c034f3d663ef --- /dev/null +++ b/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-firefox-90/options.json @@ -0,0 +1,5 @@ +{ + "validateLogs": true, + "targets": { "firefox": 90 }, + "presets": [["env", { "debug": true }]] +} diff --git a/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-firefox-90/output.js b/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-firefox-90/output.js new file mode 100644 index 000000000000..090a88a3f184 --- /dev/null +++ b/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-firefox-90/output.js @@ -0,0 +1,4 @@ +class A { + #x; + [(() => class {}).call()]; +} diff --git a/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-firefox-90/stdout.txt b/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-firefox-90/stdout.txt new file mode 100644 index 000000000000..a55c41171f61 --- /dev/null +++ b/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/class-in-computed-field-firefox-90/stdout.txt @@ -0,0 +1,30 @@ +@babel/preset-env: `DEBUG` option + +Using targets: +{ + "firefox": "90" +} + +Using modules transform: auto + +Using plugins: + transform-unicode-sets-regex { firefox < 116 } + bugfix/transform-v8-static-class-fields-redefine-readonly { firefox < 95 } + bugfix/transform-firefox-class-in-computed-class-key { firefox } + transform-class-static-block { firefox < 93 } + syntax-private-property-in-object + syntax-class-properties + syntax-numeric-separator + syntax-nullish-coalescing-operator + syntax-optional-chaining + syntax-json-strings + syntax-optional-catch-binding + syntax-async-generators + syntax-object-rest-spread + transform-export-namespace-from { } + transform-modules-commonjs + transform-dynamic-import + syntax-top-level-await + syntax-import-meta + +Using polyfills: No polyfills were added, since the `useBuiltIns` option was not set. diff --git a/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/chrome-70-static-class-fields/input.js b/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/static-class-fields-chrome-70/input.js similarity index 100% rename from packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/chrome-70-static-class-fields/input.js rename to packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/static-class-fields-chrome-70/input.js diff --git a/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/chrome-70-static-class-fields/options.json b/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/static-class-fields-chrome-70/options.json similarity index 100% rename from packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/chrome-70-static-class-fields/options.json rename to packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/static-class-fields-chrome-70/options.json diff --git a/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/chrome-70-static-class-fields/output.js b/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/static-class-fields-chrome-70/output.js similarity index 100% rename from packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/chrome-70-static-class-fields/output.js rename to packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/static-class-fields-chrome-70/output.js diff --git a/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/chrome-90-static-class-fields/input.js b/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/static-class-fields-chrome-90/input.js similarity index 100% rename from packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/chrome-90-static-class-fields/input.js rename to packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/static-class-fields-chrome-90/input.js diff --git a/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/chrome-90-static-class-fields/options.json b/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/static-class-fields-chrome-90/options.json similarity index 100% rename from packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/chrome-90-static-class-fields/options.json rename to packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/static-class-fields-chrome-90/options.json diff --git a/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/chrome-90-static-class-fields/output.js b/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/static-class-fields-chrome-90/output.js similarity index 100% rename from packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/chrome-90-static-class-fields/output.js rename to packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/static-class-fields-chrome-90/output.js diff --git a/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/chrome-96-static-class-fields/input.js b/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/static-class-fields-chrome-96/input.js similarity index 100% rename from packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/chrome-96-static-class-fields/input.js rename to packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/static-class-fields-chrome-96/input.js diff --git a/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/chrome-96-static-class-fields/options.json b/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/static-class-fields-chrome-96/options.json similarity index 100% rename from packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/chrome-96-static-class-fields/options.json rename to packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/static-class-fields-chrome-96/options.json diff --git a/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/chrome-96-static-class-fields/output.js b/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/static-class-fields-chrome-96/output.js similarity index 100% rename from packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/chrome-96-static-class-fields/output.js rename to packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/static-class-fields-chrome-96/output.js diff --git a/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/chrome-97-static-class-fields/input.js b/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/static-class-fields-chrome-97/input.js similarity index 100% rename from packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/chrome-97-static-class-fields/input.js rename to packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/static-class-fields-chrome-97/input.js diff --git a/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/chrome-97-static-class-fields/options.json b/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/static-class-fields-chrome-97/options.json similarity index 100% rename from packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/chrome-97-static-class-fields/options.json rename to packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/static-class-fields-chrome-97/options.json diff --git a/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/chrome-97-static-class-fields/output.js b/packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/static-class-fields-chrome-97/output.js similarity index 100% rename from packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/chrome-97-static-class-fields/output.js rename to packages/babel-preset-env/test/fixtures/bugfixes-always-enabled/static-class-fields-chrome-97/output.js diff --git a/packages/babel-preset-env/test/fixtures/debug-babel-7/browserslists-defaults-not-ie/stdout.txt b/packages/babel-preset-env/test/fixtures/debug-babel-7/browserslists-defaults-not-ie/stdout.txt index 8c67bdbf78f1..036733c92434 100644 --- a/packages/babel-preset-env/test/fixtures/debug-babel-7/browserslists-defaults-not-ie/stdout.txt +++ b/packages/babel-preset-env/test/fixtures/debug-babel-7/browserslists-defaults-not-ie/stdout.txt @@ -17,6 +17,7 @@ Using modules transform: auto Using plugins: transform-unicode-sets-regex { chrome < 112, firefox < 116, ios, opera_mobile < 75, safari < tp, samsung } + bugfix/transform-firefox-class-in-computed-class-key { firefox } transform-class-static-block { ios < 16.4, safari < 16.4 } syntax-private-property-in-object syntax-class-properties diff --git a/packages/babel-preset-env/test/fixtures/debug-babel-7/browserslists-defaults/stdout.txt b/packages/babel-preset-env/test/fixtures/debug-babel-7/browserslists-defaults/stdout.txt index 8c67bdbf78f1..036733c92434 100644 --- a/packages/babel-preset-env/test/fixtures/debug-babel-7/browserslists-defaults/stdout.txt +++ b/packages/babel-preset-env/test/fixtures/debug-babel-7/browserslists-defaults/stdout.txt @@ -17,6 +17,7 @@ Using modules transform: auto Using plugins: transform-unicode-sets-regex { chrome < 112, firefox < 116, ios, opera_mobile < 75, safari < tp, samsung } + bugfix/transform-firefox-class-in-computed-class-key { firefox } transform-class-static-block { ios < 16.4, safari < 16.4 } syntax-private-property-in-object syntax-class-properties diff --git a/packages/babel-preset-env/test/fixtures/debug-babel-7/browserslists-last-2-versions-not-ie/stdout.txt b/packages/babel-preset-env/test/fixtures/debug-babel-7/browserslists-last-2-versions-not-ie/stdout.txt index c1cbfd02557c..26fee436d55f 100644 --- a/packages/babel-preset-env/test/fixtures/debug-babel-7/browserslists-last-2-versions-not-ie/stdout.txt +++ b/packages/babel-preset-env/test/fixtures/debug-babel-7/browserslists-last-2-versions-not-ie/stdout.txt @@ -17,6 +17,7 @@ Using modules transform: auto Using plugins: transform-unicode-sets-regex { ios, opera_mobile < 75, safari < tp, samsung } + bugfix/transform-firefox-class-in-computed-class-key { firefox } syntax-class-static-block syntax-private-property-in-object syntax-class-properties diff --git a/packages/babel-preset-env/test/fixtures/debug/browserslists-defaults-not-ie/stdout.txt b/packages/babel-preset-env/test/fixtures/debug/browserslists-defaults-not-ie/stdout.txt index 381a37771f3c..962cb8f4507e 100644 --- a/packages/babel-preset-env/test/fixtures/debug/browserslists-defaults-not-ie/stdout.txt +++ b/packages/babel-preset-env/test/fixtures/debug/browserslists-defaults-not-ie/stdout.txt @@ -17,6 +17,7 @@ Using modules transform: auto Using plugins: transform-unicode-sets-regex { chrome < 112, firefox < 116, ios, opera_mobile < 75, safari < tp, samsung } + bugfix/transform-firefox-class-in-computed-class-key { firefox } transform-class-static-block { ios < 16.4, safari < 16.4 } transform-export-namespace-from { } bugfix/transform-safari-id-destructuring-collision-in-function-expression { ios < 16.3, safari < 16.3 } diff --git a/packages/babel-preset-env/test/fixtures/debug/browserslists-defaults/stdout.txt b/packages/babel-preset-env/test/fixtures/debug/browserslists-defaults/stdout.txt index 381a37771f3c..962cb8f4507e 100644 --- a/packages/babel-preset-env/test/fixtures/debug/browserslists-defaults/stdout.txt +++ b/packages/babel-preset-env/test/fixtures/debug/browserslists-defaults/stdout.txt @@ -17,6 +17,7 @@ Using modules transform: auto Using plugins: transform-unicode-sets-regex { chrome < 112, firefox < 116, ios, opera_mobile < 75, safari < tp, samsung } + bugfix/transform-firefox-class-in-computed-class-key { firefox } transform-class-static-block { ios < 16.4, safari < 16.4 } transform-export-namespace-from { } bugfix/transform-safari-id-destructuring-collision-in-function-expression { ios < 16.3, safari < 16.3 } diff --git a/packages/babel-preset-env/test/fixtures/debug/browserslists-last-2-versions-not-ie/stdout.txt b/packages/babel-preset-env/test/fixtures/debug/browserslists-last-2-versions-not-ie/stdout.txt index ec71b915ecd3..09ee201849c0 100644 --- a/packages/babel-preset-env/test/fixtures/debug/browserslists-last-2-versions-not-ie/stdout.txt +++ b/packages/babel-preset-env/test/fixtures/debug/browserslists-last-2-versions-not-ie/stdout.txt @@ -17,6 +17,7 @@ Using modules transform: auto Using plugins: transform-unicode-sets-regex { ios, opera_mobile < 75, safari < tp, samsung } + bugfix/transform-firefox-class-in-computed-class-key { firefox } transform-export-namespace-from { } transform-modules-commonjs transform-dynamic-import diff --git a/tsconfig.json b/tsconfig.json index eebea86b5b10..50e42cce92c4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -39,6 +39,7 @@ "./packages/babel-highlight/src/**/*.ts", "./packages/babel-node/src/**/*.ts", "./packages/babel-parser/src/**/*.ts", + "./packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/src/**/*.ts", "./packages/babel-plugin-bugfix-safari-id-destructuring-collision-in-function-expression/src/**/*.ts", "./packages/babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining/src/**/*.ts", "./packages/babel-plugin-bugfix-v8-static-class-fields-redefine-readonly/src/**/*.ts", @@ -291,6 +292,9 @@ "@babel/parser": [ "./packages/babel-parser/src" ], + "@babel/plugin-bugfix-firefox-class-in-computed-class-key": [ + "./packages/babel-plugin-bugfix-firefox-class-in-computed-class-key/src" + ], "@babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression": [ "./packages/babel-plugin-bugfix-safari-id-destructuring-collision-in-function-expression/src" ], diff --git a/yarn.lock b/yarn.lock index 950baabae62a..403580fedc88 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1300,6 +1300,20 @@ __metadata: languageName: unknown linkType: soft +"@babel/plugin-bugfix-firefox-class-in-computed-class-key@workspace:^, @babel/plugin-bugfix-firefox-class-in-computed-class-key@workspace:packages/babel-plugin-bugfix-firefox-class-in-computed-class-key": + version: 0.0.0-use.local + resolution: "@babel/plugin-bugfix-firefox-class-in-computed-class-key@workspace:packages/babel-plugin-bugfix-firefox-class-in-computed-class-key" + dependencies: + "@babel/core": "workspace:^" + "@babel/helper-environment-visitor": "workspace:^" + "@babel/helper-plugin-test-runner": "workspace:^" + "@babel/helper-plugin-utils": "workspace:^" + "@babel/traverse": "workspace:^" + peerDependencies: + "@babel/core": ^7.0.0 + languageName: unknown + linkType: soft + "@babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression@npm:^8.0.0-alpha.7": version: 8.0.0-alpha.7 resolution: "@babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression@npm:8.0.0-alpha.7" @@ -3967,6 +3981,7 @@ __metadata: "@babel/helper-plugin-test-runner": "workspace:^" "@babel/helper-plugin-utils": "workspace:^" "@babel/helper-validator-option": "workspace:^" + "@babel/plugin-bugfix-firefox-class-in-computed-class-key": "workspace:^" "@babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression": "workspace:^" "@babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining": "workspace:^" "@babel/plugin-bugfix-v8-static-class-fields-redefine-readonly": "workspace:^"