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

feat(transform-conformance): support enabling all class-related plugins when any of them are enabled in update_fixtures #8200

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions tasks/transform_conformance/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
"@babel/plugin-transform-logical-assignment-operators": "^7.25.9",
"@babel/plugin-transform-optional-chaining": "^7.25.9",
"@babel/plugin-transform-private-methods": "^7.25.9",
"@babel/plugin-transform-private-property-in-object": "^7.25.9",
"@babel/runtime": "^7.26.0"
},
"dependencies": {
"@babel/plugin-transform-typescript": "^7.26.3"
}
}
60 changes: 60 additions & 0 deletions tasks/transform_conformance/update_fixtures.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { extname, join as pathJoin } from 'path';
const PACKAGES = [
'babel-plugin-transform-class-properties',
'babel-plugin-transform-private-methods',
'babel-plugin-transform-private-property-in-object',
'babel-plugin-transform-logical-assignment-operators',
];
const FILTER_OUT_PRESETS = ['env'];
Expand All @@ -28,8 +29,20 @@ const FILTER_OUT_PLUGINS = [
'transform-destructuring',
];

const CLASS_PLUGINS = [
'transform-class-properties',
'transform-private-methods',
'transform-private-property-in-object',
];

const PACKAGES_PATH = pathJoin(import.meta.dirname, '../coverage/babel/packages');

// These fixtures transform incorrectly by Babel. Haven't figured out why yet.
const IGNORED_FIXTURES = [
'compile-to-class/constructor-collision-ignores-types',
'compile-to-class/constructor-collision-ignores-types-loose',
];

// Copied from `@babel/helper-transform-fixture-test-runner`
const EXTERNAL_HELPERS_VERSION = '7.100.0';

Expand All @@ -46,6 +59,10 @@ for (const packageName of PACKAGES) {
* @returns {undefined}
*/
async function updateDir(dirPath, options, hasChangedOptions) {
if (IGNORED_FIXTURES.some(p => dirPath.endsWith(p))) {
return;
}

const files = await readdir(dirPath, { withFileTypes: true });

const dirFiles = [],
Expand Down Expand Up @@ -118,10 +135,48 @@ function updateOptions(options) {

filter('presets', FILTER_OUT_PRESETS);
filter('plugins', FILTER_OUT_PLUGINS);
if (ensureAllClassPluginsEnabled(options)) {
hasChangedOptions = true;
}

return hasChangedOptions;
}

// Ensure all class plugins are enabled if any of class related plugins are enabled
function ensureAllClassPluginsEnabled(options) {
let plugins = options.plugins;
if (!plugins) return false;

let already_enabled = [];
let pluginOptions;
plugins.forEach(plugin => {
let pluginName = getName(plugin);
if (CLASS_PLUGINS.includes(pluginName)) {
if (Array.isArray(plugin) && plugin[1]) {
// Store options for the plugin, so that we can ensure all plugins are
// enabled with the same options
pluginOptions = plugin[1];
}
already_enabled.push(pluginName);
}
});

if (already_enabled.length) {
CLASS_PLUGINS.forEach(pluginName => {
if (!already_enabled.includes(pluginName)) {
if (pluginOptions) {
plugins.push([pluginName, pluginOptions]);
} else {
plugins.push(pluginName);
}
}
});
return true;
} else {
return false;
}
}

/**
* Transform input with Babel and save to output file.
* @param {string} inputPath - Path of input file
Expand All @@ -135,8 +190,13 @@ async function transform(inputPath, options) {
babelrc: false,
cwd: import.meta.dirname,
};
delete options.BABEL_8_BREAKING;
delete options.validateLogs;
delete options.SKIP_ON_PUBLISH;
delete options.SKIP_babel7plugins_babel8core;
delete options.minNodeVersion;
delete options.validateLogs;
delete options.SKIP_ON_PUBLISH;

function prefixName(plugin, type) {
if (Array.isArray(plugin)) {
Expand Down
Loading