From bd2ce025c3d1b30b4192f801262891e966090183 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Wed, 27 Nov 2024 02:37:59 +0000 Subject: [PATCH] test(transformer): fix fixtures updating script (#7499) Script to update fixtures for class properties transform was failing to transform fixtures where output is `output.mjs` (instead of `output.js`). This PR fixes that. --- pnpm-lock.yaml | 45 +++++++++++++++++++ tasks/transform_conformance/package.json | 1 + .../snapshots/babel.snap.md | 25 +---------- .../transform_conformance/update_fixtures.js | 15 +++++-- 4 files changed, 60 insertions(+), 26 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ee30c569a23f0..12cd97e0a8351 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -136,6 +136,9 @@ importers: '@babel/plugin-transform-arrow-functions': specifier: ^7.25.9 version: 7.25.9(@babel/core@7.26.0) + '@babel/plugin-transform-async-to-generator': + specifier: ^7.25.9 + version: 7.25.9(@babel/core@7.26.0) '@babel/plugin-transform-class-properties': specifier: ^7.25.9 version: 7.25.9(@babel/core@7.26.0) @@ -270,6 +273,12 @@ packages: resolution: {integrity: sha512-kSMlyUVdWe25rEsRGviIgOWnoT/nfABVWlqt9N19/dIPWViAOW2s9wznP5tURbs/IDuNk4gPy3YdYRgH3uxhBw==} engines: {node: '>=6.9.0'} + '@babel/helper-remap-async-to-generator@7.25.9': + resolution: {integrity: sha512-IZtukuUeBbhgOcaW2s06OXTzVNJR0ybm4W5xC1opWFFJMZbwRj5LCk+ByYH7WdZPZTt8KnFwA8pvjN2yqcPlgw==} + engines: {node: '>=6.9.0'} + peerDependencies: + '@babel/core': ^7.0.0 + '@babel/helper-replace-supers@7.25.9': resolution: {integrity: sha512-IiDqTOTBQy0sWyeXyGSC5TBJpGFXBkRynjBeXsvbhQFKj2viwJC76Epz35YLU1fpe/Am6Vppb7W7zM4fPQzLsQ==} engines: {node: '>=6.9.0'} @@ -292,6 +301,10 @@ packages: resolution: {integrity: sha512-e/zv1co8pp55dNdEcCynfj9X7nyUKUXoUEwfXqaZt0omVOmDe9oOTdKStH4GmAw6zxMFs50ZayuMfHDKlO7Tfw==} engines: {node: '>=6.9.0'} + '@babel/helper-wrap-function@7.25.9': + resolution: {integrity: sha512-ETzz9UTjQSTmw39GboatdymDq4XIQbR8ySgVrylRhPOFpsd+JrKHIuF0de7GCWmem+T4uC5z7EZguod7Wj4A4g==} + engines: {node: '>=6.9.0'} + '@babel/helpers@7.26.0': resolution: {integrity: sha512-tbhNuIxNcVb21pInl3ZSjksLCvgdZy9KwJ8brv993QtIVKJBBkYXz4q4ZbAv31GdnC+R90np23L5FbEBlthAEw==} engines: {node: '>=6.9.0'} @@ -325,6 +338,12 @@ packages: peerDependencies: '@babel/core': ^7.0.0-0 + '@babel/plugin-transform-async-to-generator@7.25.9': + resolution: {integrity: sha512-NT7Ejn7Z/LjUH0Gv5KsBCxh7BH3fbLTV0ptHvpeMvrt3cPThHfJfst9Wrb7S8EvJ7vRTFI7z+VAvFVEQn/m5zQ==} + engines: {node: '>=6.9.0'} + peerDependencies: + '@babel/core': ^7.0.0-0 + '@babel/plugin-transform-class-properties@7.25.9': resolution: {integrity: sha512-bbMAII8GRSkcd0h0b4X+36GksxuheLFjP65ul9w6C3KgAamI3JqErNgSrosX6ZPj+Mpim5VvEbawXxJCyEUV3Q==} engines: {node: '>=6.9.0'} @@ -3168,6 +3187,15 @@ snapshots: '@babel/helper-plugin-utils@7.25.9': {} + '@babel/helper-remap-async-to-generator@7.25.9(@babel/core@7.26.0)': + dependencies: + '@babel/core': 7.26.0 + '@babel/helper-annotate-as-pure': 7.25.9 + '@babel/helper-wrap-function': 7.25.9 + '@babel/traverse': 7.25.9 + transitivePeerDependencies: + - supports-color + '@babel/helper-replace-supers@7.25.9(@babel/core@7.26.0)': dependencies: '@babel/core': 7.26.0 @@ -3190,6 +3218,14 @@ snapshots: '@babel/helper-validator-option@7.25.9': {} + '@babel/helper-wrap-function@7.25.9': + dependencies: + '@babel/template': 7.25.9 + '@babel/traverse': 7.25.9 + '@babel/types': 7.26.0 + transitivePeerDependencies: + - supports-color + '@babel/helpers@7.26.0': dependencies: '@babel/template': 7.25.9 @@ -3223,6 +3259,15 @@ snapshots: '@babel/core': 7.26.0 '@babel/helper-plugin-utils': 7.25.9 + '@babel/plugin-transform-async-to-generator@7.25.9(@babel/core@7.26.0)': + dependencies: + '@babel/core': 7.26.0 + '@babel/helper-module-imports': 7.25.9 + '@babel/helper-plugin-utils': 7.25.9 + '@babel/helper-remap-async-to-generator': 7.25.9(@babel/core@7.26.0) + transitivePeerDependencies: + - supports-color + '@babel/plugin-transform-class-properties@7.25.9(@babel/core@7.26.0)': dependencies: '@babel/core': 7.26.0 diff --git a/tasks/transform_conformance/package.json b/tasks/transform_conformance/package.json index 55fdfd8ac4777..16224f15eb7cb 100644 --- a/tasks/transform_conformance/package.json +++ b/tasks/transform_conformance/package.json @@ -11,6 +11,7 @@ "@babel/plugin-external-helpers": "^7.25.9", "@babel/plugin-proposal-decorators": "^7.25.9", "@babel/plugin-transform-arrow-functions": "^7.25.9", + "@babel/plugin-transform-async-to-generator": "^7.25.9", "@babel/plugin-transform-class-properties": "^7.25.9", "@babel/plugin-transform-class-static-block": "^7.26.0", "@babel/plugin-transform-exponentiation-operator": "^7.25.9", diff --git a/tasks/transform_conformance/snapshots/babel.snap.md b/tasks/transform_conformance/snapshots/babel.snap.md index a6492cb4f3e2e..d1e1094713e5e 100644 --- a/tasks/transform_conformance/snapshots/babel.snap.md +++ b/tasks/transform_conformance/snapshots/babel.snap.md @@ -1,6 +1,6 @@ commit: 54a8389f -Passed: 406/846 +Passed: 413/846 # All Passed: * babel-plugin-transform-class-static-block @@ -276,7 +276,7 @@ x Output mismatch x Output mismatch -# babel-plugin-transform-class-properties (79/264) +# babel-plugin-transform-class-properties (86/264) * assumption-constantSuper/complex-super-class/input.js x Output mismatch @@ -817,12 +817,6 @@ Scope parent mismatch: after transform: ScopeId(3): Some(ScopeId(1)) rebuilt : ScopeId(3): Some(ScopeId(2)) -* public/non-block-arrow-func/input.mjs -x Output mismatch - -* public/regression-T2983/input.mjs -x Output mismatch - * public/regression-T7364/input.mjs Scope children mismatch: after transform: ScopeId(1): [ScopeId(2), ScopeId(7)] @@ -855,9 +849,6 @@ rebuilt : ScopeId(9): Some(ScopeId(8)) * public/static-class-binding/input.js x Output mismatch -* public/static-export/input.mjs -x Output mismatch - * public/static-infer-name/input.js x Output mismatch @@ -888,12 +879,6 @@ x Output mismatch * public-loose/foobar/input.js x Output mismatch -* public-loose/non-block-arrow-func/input.mjs -x Output mismatch - -* public-loose/regression-T2983/input.mjs -x Output mismatch - * public-loose/regression-T7364/input.mjs Scope children mismatch: after transform: ScopeId(1): [ScopeId(2), ScopeId(7)] @@ -926,9 +911,6 @@ rebuilt : ScopeId(9): Some(ScopeId(8)) * public-loose/static-class-binding/input.js x Output mismatch -* public-loose/static-export/input.mjs -x Output mismatch - * public-loose/static-infer-name/input.js x Output mismatch @@ -970,9 +952,6 @@ Symbol scope ID mismatch for "_bar": after transform: SymbolId(4): ScopeId(2) rebuilt : SymbolId(3): ScopeId(0) -* regression/T2983/input.mjs -x Output mismatch - * regression/T7364/input.mjs Scope children mismatch: after transform: ScopeId(1): [ScopeId(2), ScopeId(7)] diff --git a/tasks/transform_conformance/update_fixtures.js b/tasks/transform_conformance/update_fixtures.js index 2b150ae82b111..8406d59dac103 100644 --- a/tasks/transform_conformance/update_fixtures.js +++ b/tasks/transform_conformance/update_fixtures.js @@ -51,7 +51,7 @@ async function updateDir(dirPath, options, hasChangedOptions) { dirFiles.push(file); } else if (file.name === 'options.json') { optionsFile = file; - } else if (file.name === 'output.js') { + } else if (file.name.startsWith('output.')) { outputFile = file; } else if (file.name.startsWith('input.')) { inputFile = file; @@ -73,7 +73,7 @@ async function updateDir(dirPath, options, hasChangedOptions) { if (outputFile && hasChangedOptions) { const inputPath = pathJoin(dirPath, inputFile.name); const outputPath = pathJoin(dirPath, outputFile.name); - const backupOutputPath = pathJoin(dirPath, 'output.original.js'); + const backupOutputPath = pathJoin(dirPath, `output.original.${outputFile.name.slice(7)}`); await rename(outputPath, backupOutputPath); await transform(inputPath, outputPath, options); } @@ -187,7 +187,16 @@ async function transform(inputPath, outputPath, options) { if (options.presets) options.presets = options.presets.map(preset => prefixName(preset, 'preset')); options.plugins = (options.plugins || []).map(plugin => prefixName(plugin, 'plugin')); - options.plugins.push(['@babel/plugin-external-helpers', { helperVersion: EXTERNAL_HELPERS_VERSION }]); + + let addExternalHelpersPlugin = true; + if (Object.hasOwn(options, 'externalHelpers')) { + if (!options.externalHelpers) addExternalHelpersPlugin = false; + delete options.externalHelpers; + } + + if (addExternalHelpersPlugin) { + options.plugins.push(['@babel/plugin-external-helpers', { helperVersion: EXTERNAL_HELPERS_VERSION }]); + } const { code } = await transformFileAsync(inputPath, options); await writeFile(outputPath, code);