From 3c77ed1af12a4a782774325adb23ddd36a3d9551 Mon Sep 17 00:00:00 2001 From: Dunqing <29533304+Dunqing@users.noreply.github.com> Date: Tue, 31 Dec 2024 12:30:56 +0000 Subject: [PATCH] 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. --- pnpm-lock.yaml | 54 +++++++++++++++++ tasks/transform_conformance/package.json | 4 ++ .../transform_conformance/update_fixtures.mjs | 60 +++++++++++++++++++ 3 files changed, 118 insertions(+) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d68e7d0168c1d..cc535e85127d1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -104,6 +104,8 @@ importers: specifier: workspace:^ version: link:../oxc-types + npm/wasm-web: {} + tasks/benchmark/codspeed: devDependencies: axios: @@ -123,6 +125,10 @@ importers: version: 2.8.4 tasks/transform_conformance: + dependencies: + '@babel/plugin-transform-typescript': + specifier: ^7.26.3 + version: 7.26.3(@babel/core@7.26.0) devDependencies: '@babel/core': specifier: ^7.26.0 @@ -157,6 +163,9 @@ importers: '@babel/plugin-transform-private-methods': specifier: ^7.25.9 version: 7.25.9(@babel/core@7.26.0) + '@babel/plugin-transform-private-property-in-object': + specifier: ^7.25.9 + version: 7.25.9(@babel/core@7.26.0) '@babel/runtime': specifier: ^7.26.0 version: 7.26.0 @@ -167,6 +176,8 @@ importers: specifier: workspace:^ version: link:../../npm/oxc-types + wasm/parser/pkg: {} + packages: '@ampproject/remapping@2.3.0': @@ -328,6 +339,12 @@ packages: peerDependencies: '@babel/core': ^7.0.0-0 + '@babel/plugin-syntax-typescript@7.25.9': + resolution: {integrity: sha512-hjMgRy5hb8uJJjUcdWunWVcoi9bGpJp8p5Ol1229PoN6aytsLwNMgmdftO23wnCLMfVmTwZDWMPNq/D1SY60JQ==} + engines: {node: '>=6.9.0'} + peerDependencies: + '@babel/core': ^7.0.0-0 + '@babel/plugin-transform-arrow-functions@7.25.9': resolution: {integrity: sha512-6jmooXYIwn9ca5/RylZADJ+EnSxVUS5sjeJ9UPk6RWRzXCmOJCy6dqItPJFpw2cuCangPK4OYr5uhGKcmrm5Qg==} engines: {node: '>=6.9.0'} @@ -376,6 +393,18 @@ packages: peerDependencies: '@babel/core': ^7.0.0-0 + '@babel/plugin-transform-private-property-in-object@7.25.9': + resolution: {integrity: sha512-Evf3kcMqzXA3xfYJmZ9Pg1OvKdtqsDMSWBDzZOPLvHiTt36E75jLDQo5w1gtRU95Q4E5PDttrTf25Fw8d/uWLw==} + engines: {node: '>=6.9.0'} + peerDependencies: + '@babel/core': ^7.0.0-0 + + '@babel/plugin-transform-typescript@7.26.3': + resolution: {integrity: sha512-6+5hpdr6mETwSKjmJUdYw0EIkATiQhnELWlE3kJFBwSg/BGIVwVaVbX+gOXBCdc7Ln1RXZxyWGecIXhUfnl7oA==} + engines: {node: '>=6.9.0'} + peerDependencies: + '@babel/core': ^7.0.0-0 + '@babel/runtime@7.26.0': resolution: {integrity: sha512-FDSOghenHTiToteC/QRlv2q3DhPZ/oOXTBoirfWNx1Cx3TMVcGWQtMMmQcSvb/JjpNeGzx8Pq/b4fKEJuWm1sw==} engines: {node: '>=6.9.0'} @@ -3245,6 +3274,11 @@ snapshots: '@babel/core': 7.26.0 '@babel/helper-plugin-utils': 7.25.9 + '@babel/plugin-syntax-typescript@7.25.9(@babel/core@7.26.0)': + dependencies: + '@babel/core': 7.26.0 + '@babel/helper-plugin-utils': 7.25.9 + '@babel/plugin-transform-arrow-functions@7.25.9(@babel/core@7.26.0)': dependencies: '@babel/core': 7.26.0 @@ -3301,6 +3335,26 @@ snapshots: transitivePeerDependencies: - supports-color + '@babel/plugin-transform-private-property-in-object@7.25.9(@babel/core@7.26.0)': + dependencies: + '@babel/core': 7.26.0 + '@babel/helper-annotate-as-pure': 7.25.9 + '@babel/helper-create-class-features-plugin': 7.25.9(@babel/core@7.26.0) + '@babel/helper-plugin-utils': 7.25.9 + transitivePeerDependencies: + - supports-color + + '@babel/plugin-transform-typescript@7.26.3(@babel/core@7.26.0)': + dependencies: + '@babel/core': 7.26.0 + '@babel/helper-annotate-as-pure': 7.25.9 + '@babel/helper-create-class-features-plugin': 7.25.9(@babel/core@7.26.0) + '@babel/helper-plugin-utils': 7.25.9 + '@babel/helper-skip-transparent-expression-wrappers': 7.25.9 + '@babel/plugin-syntax-typescript': 7.25.9(@babel/core@7.26.0) + transitivePeerDependencies: + - supports-color + '@babel/runtime@7.26.0': dependencies: regenerator-runtime: 0.14.1 diff --git a/tasks/transform_conformance/package.json b/tasks/transform_conformance/package.json index d04c9d7e5d0c5..6a12afde3ef71 100644 --- a/tasks/transform_conformance/package.json +++ b/tasks/transform_conformance/package.json @@ -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" } } diff --git a/tasks/transform_conformance/update_fixtures.mjs b/tasks/transform_conformance/update_fixtures.mjs index fc45968ff241c..bb577c7901cef 100644 --- a/tasks/transform_conformance/update_fixtures.mjs +++ b/tasks/transform_conformance/update_fixtures.mjs @@ -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']; @@ -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'; @@ -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 = [], @@ -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 @@ -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)) {