Skip to content

Commit

Permalink
test(transformer): fix fixtures updating script (#7499)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
overlookmotel committed Nov 27, 2024
1 parent fed8327 commit bd2ce02
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 26 deletions.
45 changes: 45 additions & 0 deletions pnpm-lock.yaml

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

1 change: 1 addition & 0 deletions tasks/transform_conformance/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
25 changes: 2 additions & 23 deletions tasks/transform_conformance/snapshots/babel.snap.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
commit: 54a8389f

Passed: 406/846
Passed: 413/846

# All Passed:
* babel-plugin-transform-class-static-block
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)]
Expand Down
15 changes: 12 additions & 3 deletions tasks/transform_conformance/update_fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit bd2ce02

Please sign in to comment.