Skip to content

Commit 3c77ed1

Browse files
committed
feat(transform-conformance): support enabling all class-related plugins when any of them are enabled in update_fixtures (#8200)
The `class-properties` plugin supports all class-related plugins, so we need to ensure that once any of them are enabled, we also enable all class-related plugins.
1 parent ad77ad5 commit 3c77ed1

File tree

3 files changed

+118
-0
lines changed

3 files changed

+118
-0
lines changed

pnpm-lock.yaml

Lines changed: 54 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tasks/transform_conformance/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
"@babel/plugin-transform-logical-assignment-operators": "^7.25.9",
1818
"@babel/plugin-transform-optional-chaining": "^7.25.9",
1919
"@babel/plugin-transform-private-methods": "^7.25.9",
20+
"@babel/plugin-transform-private-property-in-object": "^7.25.9",
2021
"@babel/runtime": "^7.26.0"
22+
},
23+
"dependencies": {
24+
"@babel/plugin-transform-typescript": "^7.26.3"
2125
}
2226
}

tasks/transform_conformance/update_fixtures.mjs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { extname, join as pathJoin } from 'path';
1919
const PACKAGES = [
2020
'babel-plugin-transform-class-properties',
2121
'babel-plugin-transform-private-methods',
22+
'babel-plugin-transform-private-property-in-object',
2223
'babel-plugin-transform-logical-assignment-operators',
2324
];
2425
const FILTER_OUT_PRESETS = ['env'];
@@ -28,8 +29,20 @@ const FILTER_OUT_PLUGINS = [
2829
'transform-destructuring',
2930
];
3031

32+
const CLASS_PLUGINS = [
33+
'transform-class-properties',
34+
'transform-private-methods',
35+
'transform-private-property-in-object',
36+
];
37+
3138
const PACKAGES_PATH = pathJoin(import.meta.dirname, '../coverage/babel/packages');
3239

40+
// These fixtures transform incorrectly by Babel. Haven't figured out why yet.
41+
const IGNORED_FIXTURES = [
42+
'compile-to-class/constructor-collision-ignores-types',
43+
'compile-to-class/constructor-collision-ignores-types-loose',
44+
];
45+
3346
// Copied from `@babel/helper-transform-fixture-test-runner`
3447
const EXTERNAL_HELPERS_VERSION = '7.100.0';
3548

@@ -46,6 +59,10 @@ for (const packageName of PACKAGES) {
4659
* @returns {undefined}
4760
*/
4861
async function updateDir(dirPath, options, hasChangedOptions) {
62+
if (IGNORED_FIXTURES.some(p => dirPath.endsWith(p))) {
63+
return;
64+
}
65+
4966
const files = await readdir(dirPath, { withFileTypes: true });
5067

5168
const dirFiles = [],
@@ -118,10 +135,48 @@ function updateOptions(options) {
118135

119136
filter('presets', FILTER_OUT_PRESETS);
120137
filter('plugins', FILTER_OUT_PLUGINS);
138+
if (ensureAllClassPluginsEnabled(options)) {
139+
hasChangedOptions = true;
140+
}
121141

122142
return hasChangedOptions;
123143
}
124144

145+
// Ensure all class plugins are enabled if any of class related plugins are enabled
146+
function ensureAllClassPluginsEnabled(options) {
147+
let plugins = options.plugins;
148+
if (!plugins) return false;
149+
150+
let already_enabled = [];
151+
let pluginOptions;
152+
plugins.forEach(plugin => {
153+
let pluginName = getName(plugin);
154+
if (CLASS_PLUGINS.includes(pluginName)) {
155+
if (Array.isArray(plugin) && plugin[1]) {
156+
// Store options for the plugin, so that we can ensure all plugins are
157+
// enabled with the same options
158+
pluginOptions = plugin[1];
159+
}
160+
already_enabled.push(pluginName);
161+
}
162+
});
163+
164+
if (already_enabled.length) {
165+
CLASS_PLUGINS.forEach(pluginName => {
166+
if (!already_enabled.includes(pluginName)) {
167+
if (pluginOptions) {
168+
plugins.push([pluginName, pluginOptions]);
169+
} else {
170+
plugins.push(pluginName);
171+
}
172+
}
173+
});
174+
return true;
175+
} else {
176+
return false;
177+
}
178+
}
179+
125180
/**
126181
* Transform input with Babel and save to output file.
127182
* @param {string} inputPath - Path of input file
@@ -135,8 +190,13 @@ async function transform(inputPath, options) {
135190
babelrc: false,
136191
cwd: import.meta.dirname,
137192
};
193+
delete options.BABEL_8_BREAKING;
194+
delete options.validateLogs;
195+
delete options.SKIP_ON_PUBLISH;
138196
delete options.SKIP_babel7plugins_babel8core;
139197
delete options.minNodeVersion;
198+
delete options.validateLogs;
199+
delete options.SKIP_ON_PUBLISH;
140200

141201
function prefixName(plugin, type) {
142202
if (Array.isArray(plugin)) {

0 commit comments

Comments
 (0)