From d14d3600613e7cdd7e5fa19be5e97af199e89c9f Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Thu, 12 Dec 2024 09:27:54 +0000 Subject: [PATCH] test(transformer): remove dead code from fixtures update script (#7808) Follow-up after #7771 and #7779. Remove dead code from transformer fixtures updater script. --- .../transform_conformance/update_fixtures.js | 38 ++++++------------- 1 file changed, 12 insertions(+), 26 deletions(-) diff --git a/tasks/transform_conformance/update_fixtures.js b/tasks/transform_conformance/update_fixtures.js index 9253378c0ae45..1115ecf56343d 100644 --- a/tasks/transform_conformance/update_fixtures.js +++ b/tasks/transform_conformance/update_fixtures.js @@ -27,11 +27,7 @@ const FILTER_OUT_PLUGINS = [ 'transform-destructuring', ]; -const PACKAGES_PATH = pathJoin( - import.meta.dirname, - '../coverage/babel/packages', -); -const OVERRIDES_PATH = pathJoin(import.meta.dirname, 'overrides'); +const PACKAGES_PATH = pathJoin(import.meta.dirname, '../coverage/babel/packages'); // Copied from `@babel/helper-transform-fixture-test-runner` const EXTERNAL_HELPERS_VERSION = '7.100.0'; @@ -51,15 +47,8 @@ for (const packageName of PACKAGES) { async function updateDir(dirPath, options, hasChangedOptions) { const files = await readdir(dirPath, { withFileTypes: true }); - const dirFiles = []; - - const filenames = { options: null, input: null, output: null, exec: null }; - const overrides = { - options: false, - input: false, - output: false, - exec: false, - }; + const dirFiles = [], + filenames = { options: null, input: null, output: null }; // Find files in dir for (const file of files) { @@ -77,7 +66,7 @@ async function updateDir(dirPath, options, hasChangedOptions) { if (filenames.options) { const path = pathJoin(dirPath, filenames.options); const localOptions = JSON.parse(await readFile(path, 'utf8')); - if (!overrides.options && updateOptions(localOptions)) { + if (updateOptions(localOptions)) { hasChangedOptions = true; await backupFile(path); await writeFile(path, JSON.stringify(localOptions, null, 2) + '\n'); @@ -86,18 +75,16 @@ async function updateDir(dirPath, options, hasChangedOptions) { } // Run Babel with updated options/input - if ( - filenames.output && - (hasChangedOptions || overrides.input) && - !overrides.output - ) { + if (filenames.output && hasChangedOptions) { const inputPath = pathJoin(dirPath, filenames.input), outputPath = pathJoin(dirPath, filenames.output); - const originalCode = (await readFile(outputPath)).toString(); - const code = await transform(inputPath, outputPath, options); - if (originalCode.trim() !== code.trim()) { + + const transformedCode = await transform(inputPath, options); + const originalTransformedCode = await readFile(outputPath, 'utf8'); + + if (transformedCode.trim() !== originalTransformedCode.trim()) { await backupFile(outputPath); - await writeFile(outputPath, code); + await writeFile(outputPath, transformedCode); } } @@ -137,11 +124,10 @@ function updateOptions(options) { /** * Transform input with Babel and save to output file. * @param {string} inputPath - Path of input file - * @param {string} outputPath - Path of output file * @param {Object} options - Transform options * @returns {undefined} */ -async function transform(inputPath, outputPath, options) { +async function transform(inputPath, options) { options = { ...options, configFile: false,