Files
react/compiler/forget/scripts/test262-preprocessor.js
T
Joe Savona 079cfe68bf Fix test262 preprocessor
The test262 preprocessor was correctly running forget against all the functions 
in each test file, but it was incorrectly transforming the file contents 
overall. Previously we swapped the contents of the file for the transformed 
output of the last function, now we use the babel plugin to rewrite functions in 
place and keep the rest of the file intact. 

Of course, the tests that failed before still fail. But when we fix them the 
tests will work now.
2022-12-20 16:27:11 -08:00

28 lines
845 B
JavaScript

const BabelPluginReactForget = require("../dist/BabelPlugin").default;
const transformSync = require("@babel/core").transformSync;
// Preprocessor that runs Forget on the test262 test prior to execution. Compilation errors short
// circuit test execution and report an error immediately.
module.exports = (test) => {
try {
const generated = transformSync(test.contents, {
filename: test.file,
plugins: [BabelPluginReactForget],
});
if (generated.code != null && generated.code !== "") {
test.contents = generated.code;
} else {
throw new Error("Codegen returned an empty string");
}
} catch (error) {
error.message = error.message.replace(/ \(\d+:\d+\)/, "");
test.result = {
stderr: `${error.name}: ${error.message}\n`,
stdout: "",
error,
};
}
return test;
};